Answers for "laravel where eloquent"

PHP
2

laravel eloquent get first

// return first row by id
$user = App\User::where('id',$id)->first();
// or return directly a field
$userId = App\User::where(...)->pluck('id');
Posted by: Guest on May-17-2020
6

laravel create or update

// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Models\Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99, 'discounted' => 1]
);
Posted by: Guest on September-27-2020
2

model observer laravel

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $table = 'posts';

    protected $fillable = ['title', 'slug', 'content'];

    protected static function boot()
    {
        parent::boot();
        static::saving(function ($model) {
            $model->slug = str_slug($model->title);
        });
    }
}
Posted by: Guest on July-30-2020
0

where in laravel

$users = Users::whereIn('id', array(1, 2, 3))->get()
Posted by: Guest on July-27-2021
2

laravel where

$users = DB::table('users')
                ->whereDate('created_at', '2016-12-31')
                ->get();
Posted by: Guest on September-14-2020
0

where () laravel Eloquent

//los signos de igualdad pueden ser: ">=", "<=", "=", ">", "<"
$user = User::where("estado","=",1)->find(10);
Posted by: Guest on February-09-2021

Browse Popular Code Answers by Language