📜  Laravel 检索单条记录 - 任何代码示例

📅  最后修改于: 2022-03-11 14:54:58.005000             🧑  作者: Mango

代码示例1
use App\Models\Flight;

// Retrieve a model by its primary key...
$flight = Flight::find(1);

// Retrieve the first model matching the query constraints...
$flight = Flight::where('active', 1)->first();

// Alternative to retrieving the first model matching the query constraints...
$flight = Flight::firstWhere('active', 1);