Dev Diaries WD logo Dev Diaries WD
LARAVEL INTERVIEW · EP 04
LARAVEL INTERVIEW · Episode 04

Laravel: get() vs first()

Pick the one that matches what you expect back — many rows or one

Employee queries — get() vs first()
<?php
 public function getVsFirst()
    {
        // TODO (LEP 04): write the two queries
        $emailToFind = "madhyam@yopmail.com";
        $employee =  Employee::where('email' ,  $emailToFind)->first();

        $deptToSearch = "Engineering";
        $employees=Employee::where('department' , $deptToSearch)->get();

        return view('laravel.lep4_get_vs_first', [
            'VIDEO' => null , 'employee' => $employee, 'employees' => $employees
            ]);
    }
?>
Output

Find me the ageo off user whose email is madhyam@yopmail.com

Madhyam Sharma age 35

Give me list of users from Engineering dept

1 - Asha Rao

2 - Dillan Kuhic

3 - DAnny Lalwani

Watch the full episode

Watch on YouTube