Are your other issues fixed yet? Please mark them as solved if so. You keep adding new problems and it's hard to know if the old ones we've been spending our time helping you with are fixed or not before continuing on with new problems.
May 21, 2019
9
Level 6
How to show default value in select option (parent_id)?
I tried for save a parent_id of Category in laravel 5.8 successfully. but I want to edit category now.
CategoryController.php
public function edit(Category $category)
{
return view('Admin.categories.edit', compact('category'));
}
public function update(CategoryRequest $request, Category $category)
{
$category->update($request->all());
return redirect(route('categories.index'));
}
edit.blade.php
<form action="{{ route('categories.update', $category->id) }}" method="post">
{{ method_field('PATCH') }}
{{ csrf_field() }}
@include('Admin.layouts.errors')
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" value="{{ old('name') ? : $category->name }}" id="name" name="name">
</div>
<div class="form-group">
<label for="parent_id">Sub Category</label>
<select class="form-control" id="parent_id" name="parent_id" data-live-search="true">
@foreach(\App\Category::all() as $category)
<option value="{{ $category->id }}" {{ trim($category->id) , $category->pluck('id')->toArray() ? 'selected' : '' }}>{{ $category->name }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
Level 75
I think OP means what is currently stored in the DB. (I think)
See https://laracasts.com/discuss/channels/laravel/how-do-i-assign-the-existing-value-to-a-select
By retrieving what's stored just like inputs.
@irankhosravi I have already mentioned that most questionS like this has been answered many times, go to google and type:
site:laracasts.com YOUR SEARCH EXPRESSION
Takes just a few seconds to find many past wonderful replies.
1 like
Please or to participate in this conversation.