Laravel eloquent firstOrNew method doesn't update or insert

六月ゝ 毕业季﹏ 提交于 2020-01-02 10:19:33

问题


I have a problem with firstOrNew() method of the Laravel eloquent class. the problem is that when I give the method some attributes and values and call save() on the model, it doesn't get saved (inserted or updated).

PHP :

<?

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

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

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

But when I try this with a new model it gets saved :

<?

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

$flightModel->save();

Thanks for helping.

来源:https://stackoverflow.com/questions/38208033/laravel-eloquent-firstornew-method-doesnt-update-or-insert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!