irankhosravi
3 months ago
393
3
Laravel

Property [id] does not exist on this collection instance.

Posted 3 months ago by irankhosravi

I want to select an option when click edit.

BlogController.php

public function create()
{
    $categories = Category::all();
    return view('Admin.blogs.create', compact('categories'));
}

create.blade.php

<select name="category" id="category" class="form-control">
    @foreach($categories as $category)
        <option {{ $category->id == $blog->categories->id ? 'selected' : '' }} value="{{ $category->id }}">
            {{ $category->name_fa }}
        </option>
    @endforeach
</select>

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