laravel db::table pluck code example

Example 1: pluck laravel

$name = DB::table('users')->where('name', 'John')->pluck('name');

Example 2: laravel pluck

$users = Users::pluck('name','email');
dd($users);

Example 3: laravel find query

$model = App\Models\Flight::where('legs', '>', 100)->firstOr(function () {
        // ...
});

Example 4: laravel find query

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model
{
    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'flight_id';
}

Tags:

Sql Example