M
M
mrSeller2018-03-08 17:11:33
Laravel
mrSeller, 2018-03-08 17:11:33

Why doesn't firstOrCreate work in laravel?

I have my own table of cities and regions.
When registering, the user can select a city from the list or add a new one.
In the controller, I check if there is a variable with the new city and, if so, I call:

$city = City::firstOrCreate([
  'name' => $request->new_city,
  'region_id' => $request->region_id
]);

If there is a city with the same name and region id, then everything is fine, but if not (only region_id matches), then the answer comes with an error:
5aa1444412dae846272490.png
What could be the problem? There are no specifics (at least, understandable to me) in the answer. Just the handler complains about the name field

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2018-03-08
@mrSeller

https://laravel.com/docs/5.6/eloquent#mass-assignment

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question