I getting a news pack from a controller and display them on page by using foreach `
@foreach($news as $newsCard)
@include('includes.news.card')
@endforeach
{{$news->links()}}
` news has method for return owner, and i use his name for displayed owner news. On one page is working But on another page is not working (return null). For display element of news is created template and use it in foreach. News is are the same on this two page (checked this by dd()) What is my problem?
Template
<div>
<h5>{{$newsCard->title}}</h5>
<h7>{{$newsCard->user->name}}</h7>
</div>
I tried created new blade file and use cache:clear, but it is not helped
P.S. I used this an approach for another collection and is working correct
P.S.S
I use method like this $newsCard->user->name
in template
CodePudding user response:
you have to pass the variable to the included blade file:
@foreach($news as $newsCard)
@include('includes.news.card', ['newsCard' => $newsCard])
@endforeach
{{$news->links()}}
CodePudding user response:
Try this way
<div >
@foreach ($users as $user)
{{ $user->name }}
@endforeach
</div>
{{ $users->links() }}
Laravel pagination https://laravel.com/docs/9.x/pagination can help you.