I'm trying to show the selected category in the edit form But it is not showing,
My view :
<select name="category_id" id="category_id" class="form-control{{ $errors->has('category_id') ? ' is-invalid' : '' }}">
{{--<option value="">Choose Category</option>--}}
@foreach($cat as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
@endforeach
</select>
the edit method in my PostController
:
public function edit($id)
{
$post = Post::findOrFail($id);
$cat = Category::all();
return view('admin.posts.edit',['post'=>$post,'cat'=>$cat]);
}
I tried to put an if statement like this :
@foreach($cat as $category)
<option value="{{ $category->id }}" {{$category->id == App\Category::class ? 'selected="selected"' : '' }}>{{ $category->name }}</option>
@endforeach
It is showing a category However it's not the selected category for the post.
HELP