I need to make a raw database query using Laravel:
$results = DB::select(\"SELECT * FROM members
INNER JOIN (several other tables)
WHERE (horribly
You can simply init a new model:
$member = new App\Member;
Then you can assign the columns:
$member->column = '';
Or if all columns are mass assignable:
$member->fill((array)$results);
Or have I misunderstood something?
You can try to hydrate your results to Model objects:
$results = DB::select("SELECT * FROM members
INNER JOIN (several other tables)
WHERE (horribly complicated thing)
LIMIT 1");
$models = Member::hydrate( $results->toArray() );
Or you can even let Laravel auto-hydrate them for you from the raw query:
$models = Member::hydrateRaw( "SELECT * FROM members...");
EDIT
From Laravel 5.4 hydrateRaw is no more available. We can use fromQuery instead:
$models = Member::fromQuery( "SELECT * FROM members...");
You should definetly use Eloquent to perform that.
You might declare the relations between the models, and use the where conditions.
like:
Member::where(......)->get();
This will return an eloquent instance, and you can do whatever you need.