我试图在我的dashboard.blade.php上创建一个编辑按钮,我的创建功能可以正常工作。但是编辑给了我“函数App \ Http \ Controllers \ PostsController :: edit()的参数太少,传递了0且恰好期望了1个”错误...
我查了一下问题,并读到我需要修复Route :: get这样的东西;路线:: get('/ show / {id}','PostsController @ show');但是我正在使用Route :: resource('posts','PostsController');方法,所以我不确定如何解决此问题?
在这里,dashboard.blade.php
@foreach($posts as $post)
<tr>
<td>{{$post->title}}</td>
<td><a href="/posts/{{$post->id}}/edit" class="btn btn-default">Edit</a></td>
<td>
{!!Form::open(['action' =>['PostsController@destroy', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close() !!}
</td>
</tr>
@endforeach
这是我的web.php
Route::get('/', 'PagesController@index');
Route::get('/about', 'PagesController@about');
Route::get('/category/{category}', [
'uses' => 'PostsController@category',
'as' => 'category'
]);
Route::resource('books', 'BooksController');
Route::resource('posts', 'PostsController');
Route::resource('categories', 'CategoriesController', ['except'=> ['create']]);
Auth::routes();
Route::get('/dashboard', 'DashboardController@index');
这是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, null, ['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>
不知道您是否需要这个,但是我要添加它
PostsController.php
public function create()
{
$posts = Post::all();
$categories = Category::all();
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);
}
想看看是否有人可以告诉我解决此问题需要做什么?