lundi 8 juillet 2019

Need help using all() and find() in the same function for Laravel

In my layouts, I am displaying all the categories (from my database) using a foreach statement. In the page, it is a page is it shown from the show() function. It seems a little contradicting because I have to use all() for the layout, and find() in the page. Is there any way to work around this?

public function show($id)
    {
        $categories = category::find($id);
        $products = product::all()->sortBy('ID');
        $categories = category::all()->sortBy('ID');
        return view('categories', compact('products','categories'));
    }

In the template

@foreach($categories as $category)
  <li class="text-uppercase" style="white-space: nowrap;"><a href=""></a></li>
@endforeach

In the page itself



When I put both the all() and find() into the same function

This is the error message:-

Property [category] does not exist on this collection instance. (View: C:.............\resources\views\categories.blade.php)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire