I have a table related to another PRODUCTS AND BRANDS, what happens is that when I create brands and products everything goes well. The problem is when I delete a brand and create another, and when creating a new 'product with some role, it sends me the following error:
In my controller I have:
public function create()
{
$marks = Mark::lists('name','id')->prepend('Seleccioname la Marca');
return view('product.create')->with('marks',$marks);
}
And in the view:
{!! Form::select('marks_id',$marks,null,['id'=>'marks_id','class'=>'form-control']) !!}
I have these records in marks with their id:
But when I see the source code, I get a list from 1 to n that are not correct in value.
The problem is that you are using the method
prepend()
to add the valueSeleccione la marca
, but you are not specifying the second parameter, which is the key of said value. When you don't specify it, this method uses PHP's array_unshift() function , which resets the array's numeric indices.Illuminate\Support\Collection
Illuminate\Support\Arr
After seeing the reference of the methods in question, the solution would be:
Another quick solution to not add anything to the array would be to simply use the
placeholder
select's html tag attribute and put the stringSeleccione la marca
there.