Laravel雄辩的firstOrNew方法不会更新或插入

时间:2016-07-05 16:09:17

标签: php database laravel model eloquent

我对Laravel eloquent类的firstOrNew()方法有疑问。问题是当我给方法一些属性和值并在模型上调用save()时,它不会被保存(插入或更新)。

PHP:

<?

$flightModel = Flight::firstOrNew([
    'arrival' => $flightData['arrival'],
    'plane' => $flightData['plane']
]);

$flightModel->departure = $flightData['departure'];

$flightModel->save();//this doesn't save any data

但是当我尝试使用新模型时,它会被保存:

<?

$flightModel = new Flight();
$flightModel->arrival = $flightData['arrival'];
$flightModel->plane = $flightData['plane'];
$flightModel->departure = $flightData['departure'];

$flightModel->save();

感谢您的帮助。

0 个答案:

没有答案