Я пытаюсь создать разделы сообщений и комментариев, мне удалось показать все сообщения на одной странице, теперь я пытаюсь показать комментарии под каждым сообщением.В моей модели я соединил обе таблицы и в своей функции я могу просматривать сообщения и комментарии, когда использую dd();
, это мой результат:
Я не уверен, правильно ли я вызываю часть комментария в своих представлениях, потому что получаю ошибку:
Свойство [activity_post_comments] не существует в этом экземпляре коллекции.(Просмотр: C: \ xampp \ xampp \ htdocs \ rsapp \ resources \ views \ pages \ timeline.blade.php)
Моя функция:
public function timeline()
{
$activityposts = ActivityPost::with('activity_post_comment')
->orderBy('created_at','desc')
->paginate(100);
$posts = Post::orderBy('created_at','desc')->paginate(100);
// dd($activityposts);
return view('pages.timeline')
->with('posts', $posts)
->with('activityposts', $activityposts);
}
Просмотр:
@if(count($activityposts) > 0)
@foreach($activityposts as $activitypost)
<div class="panel panel-default">
<!--
<div class="panel-heading"><a href="#" class="pull-right">View all</a>
<h4>Bootply Editor & Code Library</h4></div>
-->
<div class="panel-body">
<p>
<img src="../storage/user_image/{{ $activitypost->user->user_image }}" width="28px" height="28px">
<b>{{ $activitypost->user->firstname }} {{ $activitypost->user->lastname }}</b>
<span class="pull-right">{{ $activitypost->created_at->format('d-m-Y') }}</span>
</p>
<!--
<div class="clearfix"></div>
<hr>
-->
{{ $activitypost->status_update }}
<hr>
<div class="well">
{{ $activitypost->activity_post_comments->activity_post_comments }};
</div>
<hr>
<form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="{{ action('PagesController@storecomments', $activitypost->id) }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('activity_post_comments') ? ' has-error' : '' }}">
<!-- <label for="activity_post_comments" class="col-md-4 control-label">First Name</label> -->
<div class="col-md-12">
<input id="activity_post_comments" type="text" class="form-control" name="activity_post_comments" required autofocus>
@if ($errors->has('activity_post_comments'))
<span class="help-block">
<strong>{{ $errors->first('activity_post_comments') }}</strong>
</span>
@endif
</div>
</div>
<button type="submit" class="btn btn-primary">Post</button>
</form>
</div>
</div>
@endforeach
{{$activityposts->links()}}
@else
<p>No new activity from users</p>
@endif
Вот где я не уверен:
{{ $activitypost->activity_post_comment->activity_post_comments }};