I'm using Laravel Collective Form builder in my view and i'm populating this select box from a table in my DB like this
I am having an issue with my values not matching up and my dropdown is also giving me the values as an array...
Here's what I have in my PostsController:-
public function edit(Post $post)
{
$categories = Category::all()->pluck('title', 'id')->toArray();
return view('posts.edit')->withPost($post)->withCategories($categories);
}
and here's my view edit.blade.php:-
{{ Form::label('category_id', 'Category :')}}
{!! Form::select('category_id', $categories, null, ['class' => 'form-control']) !!}
So I need little help?
Here's the value issue I was talking about: enter image description here
Here's the array issue I was talking about: enter image description here
no need to use toArray() pluck method automatically create an array.
try this
$categories = Category::pluck('title', 'id');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With