Я хочу создать сообщение, но не могу, потому что он показывает мне Неопределенная переменная Ошибка для функции compact
,
кто-нибудь может мне помочь?
Ниже приведены образцы из файлов:
AdminPostsController.php
public function index(){
$posts = Post::paginate(5);
return view('admin.posts.index', compact('posts','categories'));
}
админ / сообщений / index.blade.php
@extends('layouts.admin')
@section('content')
<h1>Posts page</h1>
<table class="table">
<thead>
<th>ID</th>
<th>Owner</th>
<th>Category</th>
<th>Photo ID</th>
<th>Title</th>
<th>Body</th>
<th>Created</th>
<th>Updated</th>
</thead>
<tbody>
@if($posts)
@foreach($posts as $post)
<tr>
<td>{{$post->id}}</td>
<td>{{$post->user->name}}</td>
<td>{{$post->category_id ? $post->category->name : 'No category'}}</td>
<td><img height="50" src="{{$post->photo ? $post->photo->file : 'http://placehold.it/400x400'}}"></td>
<td><a href="{{route('admin.posts.edit', $post->id)}}">{{$post->title}}</a></td>
<td>{{str_limit($post->body,10)}}</td>
<td>{{$post->created_at->diffForHumans()}}</td>
<td>{{$post->updated_at->diffForHumans()}}</td>
<td><a href="{{route('home.post', $post->id)}}">View post</a> </td>
<td><a href="{{route('admin.comments.show', $post->id)}}">View comments</a></td>
</tr>
@endforeach
@endif
</tbody>
</table>
<div class="row">
<div class="col-sm-6 col-sm-offset-5">
{{$posts->render()}}
{{--pagination--}}
</div>
</div>
@stop