1 year ago

Not selected categories in edit view

Posted 1 year ago by siusiak1000

Hi, I wanted to do it in the edit view so that the categories assigned to the article are highlighted and selected automatically.

In edit view:

<select multiple class="form-control" id="kategoria" name="Kategoria[]">
@foreach($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>

In Model:

public function getKategoriaAttribute()
    return $this->categories->pluck('id')->all();

In [email protected]

    public function edit($id)
        $categories = Category::all('name', 'id');
        $artykul = Article::findOrFail($id);
        return view('panel_admina.edytuj_aktualnosc', compact('artykul', 'categories'));

With such settings it is still not highlighted and selected.

Please sign in or create an account to participate in this conversation.