If have this in my Laravel controller,
$employees = DB::table('employeed')->get();
does it mean that each record in $employees will have /inherit a fluent interface like the method table in DB::table? Is that the reason why I can do something like
{{ $employee->name}}
within a for loop of $employees where each record is assigned to $employee in a view?
Its because you have an array of stdClass
objects that you are iterating through, which is returned from that DB query. Each element in the array will be set as $employee
as that loop iterates, assuming you are using a foreach
loop like so:
@foreach ($employees as $employee)
{{ $employee->name }}
@endforeach
Update
References for Query Builder and Eloquent
Query Builder
the get method returns an array of results where each result is an instance of the PHP StdClass object.
Eloquent
For Eloquent methods like all and get which retrieve multiple results, an instance of Illuminate\Database\Eloquent\Collection will be returned. ... Of course, you may simply loop over this collection like an array