Answers for "model wheree"

PHP
3

laravel findorfail

$model = App\Flight::where('name', 'Mike')->firstOrFail();
Posted by: Guest on June-20-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

Browse Popular Code Answers by Language