1.3Laravel模型(Model)之记录(Record)

查询记录

Flight::all()
Flight::find(1);
Flight::where('active', 1)
               ->orderBy('name')
               ->take(10)
               ->get();
Flight::where('number', 'FR 900')->first();

增加记录

$flight = Flight::create([
    'name' => 'London to Paris',
]);
$flight = new Flight;

$flight->name = $request->name;

$flight->save();

更改记录

$flight = Flight::find(1);

$flight->name = 'Paris to London';

$flight->save();

删除记录

Flight::destroy(1);

Flight::destroy(1, 2, 3);

Flight::destroy([1, 2, 3]);

Flight::destroy(collect([1, 2, 3]));
$flight = Flight::find(1);

$flight->delete();

强参数

protected $fillable = ['title', 'body'];

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/php/laravel/5561.html

发表评论

登录后才能评论