laravel query in code example

Example 1: laravel sql query

use Illuminate\Support\Facades\DB;

$users = DB::select('select * from users');

foreach ($users as $user) {
    echo $user->name;
}

Example 2: laravel wher in

$users = DB::table('users')
                    ->whereIn('id', [1, 2, 3])
                    ->get();

Example 3: laravel find query

use App\Models\Destination;
use App\Models\Flight;

return Destination::addSelect(['last_flight' => Flight::select('name')
    ->whereColumn('destination_id', 'destinations.id')
    ->orderBy('arrived_at', 'desc')
    ->limit(1)
])->get();