Fluent interface in PHP Laravel querybuilder


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 ofstdClass 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 aforeach loop like so:

@foreach ($employees as $employee)
    {{ $employee->name }}


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.


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

Laravel Docs - Query Builder - Retrieving Results

Laravel Docs - Eloquent - Retrieving Multiple Models

People are also looking for solutions to the problem: php - NotFoundHttpException on every route with nginx


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.