Error mounting Foreach Laravel 5.1

Asked

Viewed 55 times

1

I’m trying to set up a filter where I search some options BD I made a foreach to bring this data from BD but is bringing an error:

Trying to get property of non-object

Follow my code:

Controller

public function index()
{
    $categoria = $this->catimage->get();

    return view('administrator.images.index', compact('categoria'));
}

View

<div class="row">
<ul class="simplefilter">
Filtros:
<li class="active" data-filter="all">All</li>
@foreach ($categoria as $categoria)
<li data-filter="{{$categoria ->id}}">{{$categoria ->title}}</li>
@endforeach
</ul>
</div>
  • This error is in the controller or in the view?

  • This error is in View

1 answer

1


With Compact doesn’t work. Do it like this:

Controller:

return view('administrator.images.index', ['categoria' => $categoria]);
  • It worked out thanks!

  • You’re welcome @BJJ. I’m glad you did

Browser other questions tagged

You are not signed in. Login or sign up in order to post.