mercredi 26 août 2015

Create select menu with nested categories in Laravel 5

Having gotten help from the this question I asked earlier Create a nested lists of categories in Laravel 5 was able to loop through and display my nested categories in a tree-like structure. Now I want to be able to edit each categories, so I created an edit link which I then pass category id to the link, which is in turn used in my controller to display that particular category from the categories table. But I keep getting this error

ErrorException in 775837465f5ab64876c1dc1677878595 line 46: Trying to get property of non-object (View: /resources/views/backend/categories/edit.blade.php)

Here is my current controller:

public function edit($id)
{
    $categories   = Category::find($id);
    //print_r($categories);
    return view('backend.categories.edit')->with('categories', $categories); 
}

And this is how I implemented it in my view file:

<select name="parent_id" class="form-control">
                        <option value="" selected disabled style="display:none">choose parent category</option>
                        @foreach ($categories as $category)
                            <option value="{{ $category->id }}" placeholder="choose parent category">{{ $child->name }}</option>
                        @endforeach
                    </select>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Jwy7mv
via IFTTT

Aucun commentaire:

Enregistrer un commentaire