我对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();
感谢您的帮助。