Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

martincodes's avatar

Laravel Eloquent: first() doesnt work

Hello,

I'm currently trying to get all the models (that meet several conditions) and spend the first one of them. However, when I access them with (first), I only get this:

$reports = Report::where([
            ["id", $request->report_id],
            ["absender_persoid", $request->perso_id]
        ])->get();

Result from $reports->dd(): https://picr.eu/images/2021/07/31/YbF1l.png

But $reports->first()->dd(): https://picr.eu/images/2021/07/31/YbGOI.png

What am I doing wrong?

0 likes
5 replies
bugsysha's avatar

Try:

$reports = Report::where([
            'id' => $request->report_id,
            'absender_persoid' => $request->perso_id,
        ])->get();
alitokmakci's avatar

You should use global dd() function to dump Model instances.

The get() method of query builder returns always Collection instance if there is only one related row in the database. But the first() method returns the Model's itself.

If you want to dump Model, use :

dd($reports->first());

Please or to participate in this conversation.