我明白了:
ErrorException(E_ERROR) 属性[id]在此集合实例中不存在。
我一直在环顾四周,我尝试了几种不同的修复方法,但仍然没有找到答案。到目前为止,这就是我的意思。。。我找不到导致问题的原因,所以我几乎不需要帮助...
PostsController.php
public function edit($id)
{
$post = Post::find($id);
$categories = Category::all();
$cats = array();
foreach ($categories as $category){
$cats[$category->id] = $category->title;
}
return view('posts.edit')->withPost($post)->withCategories($cats);
}
edit.blade.php
{!! Form::model($post, ['route' => ['PostsController@update', $post->id], 'method' => 'PUT']) !!}
<div class="col-md-4">
<div class'form-group'>
{{ Form::label('title', 'Title')}}
{{ Form::text('title', $post->title, ['class' => 'form-control', 'placeholder' => 'Title'])}}
</div>
</div>
<div class="col-md-4">
<div class'form-group'>
{{ Form::label('slug', 'Slug')}}
{{ Form::text('slug', $post->slug, ['class' => 'form-control ', 'placeholder' => 'Slug', 'required' =>'', 'minlength' => '5', 'maxlength' => '255'])}}
</div>
</div>
<div class="col-md-4">
<div class'form-group'>
{{ Form::label('category_id', 'Category :')}}
{{ Form::select('category_id', $categories, $post->categoty_id, ['class' => 'form-control']) }}
</div>
</div>
</div>
<div class="row post_row">
<div class="col-md-8">
<div class'form-group'>
{{ Form::label('body', 'Body')}}
{!! Form::textarea('body', '$post->body', ['id' => 'article-ckeditor', 'class' => 'form-control space', 'placeholder' => 'Body Text'])!!}
</div>
</div>
</div>
<div class'form-group' style="padding-top: 20px">
{{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
{!! Form::close() !!}
</div>