可以在firstorcreate函数中使用“或”条件吗?
Model::firstOrCreate(
['name' => $request->get('name'), 'oldname' => $request->get('name')]
);
2条件与“ AND”相关,我想使用“ Or” 但不适用于['newname'=> $ request-> get('name')或'oldname'=> $ request-> get('name')]
答案 0 :(得分:0)
方法firstOrCreate
带有一个可选的第二个参数,您可以执行以下操作:
Model::firstOrCreate(
['name' => $request->get('name')], ['oldname' => $request->get('name')]
);
来源:https://laravel.com/docs/5.7/eloquent#inserting-and-updating-models
从文档中
// Retrieve flight by name, or create it with the name and delayed attributes...
$flight = App\Flight::firstOrCreate(
['name' => 'Flight 10'], ['delayed' => 1]
);