我想我的路線中有一個錯誤,但是我開始並且找不到解決方案。 當我提交我的編輯形式,我有這樣的錯誤:Missing argument 2 for App\Http\Controllers\Admin\SportController::update()
我的控制器:控制器缺少參數2:update() - Laravel
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('admin');
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
// Récupère tous les sports
$sports = Sport::all();
// Charge la vue et passe la liste des sports en paramètre
return view('admin.sports.index')
->with('sports', $sports);
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
return view('admin.sports.create');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|max:255',
]);
// process the login
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)
->withInput();
}
Sport::create($request->all());
Session::flash('message', 'Félicitation, vous avez crée un sport !');
return redirect('/admin/sports');
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
// get the nerd
$sport = Sport::find($id);
// show the edit form and pass the nerd
return view('admin.sports.edit')->with('sport', $sport); }
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$validator = Validator::make($request->all(), [
'name' => 'required|max:255',
]);
// process the login
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)
->withInput();
}
$sport = Sport::find($id);
$sport->name= Input::get('name');
$sport->save();
Session::flash('message', 'Félicitation, vous avez mis à jour un sport !');
return redirect('/admin/sports');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
我的路由:
Route::resource('/admin/sports', 'Admin\[email protected]');
Route::resource('/admin/sports/create', 'Admin\[email protected]');
Route::POST('/admin/sports', 'Admin\[email protected]');
Route::get('/admin/sports/edit/{id}','Admin\[email protected]');
Route::put('/admin/sports','Admin\[email protected]')->name('admin.sports.update');
我的觀點:edit.blade.php
{{ Html::ul($errors->all()) }}
{{ Form::model($sport, array('route' => array('admin.sports.update', $sport->id), 'method' => 'PUT')) }}
<div class="form-group">
{{ Form::label('name', 'Nom') }}
{{ Form::text('name', null, array('class' => 'form-control')) }}
</div>
<div class="right-align">
{{ Form::submit('Valider', array('class' => 'btn btn-flat')) }}
<a class="btn btn-flat" href="{{ URL::to('admin/sports') }}">Annuler</a>
</div>
{{ Form::close() }}
謝謝你的幫助。 彼得。
數組你爲什麼這樣做資源控制器'路線::資源(「/管理/體育」,「管理\ SportController @index');'?如果要排除路由,請查看https://laravel.com/docs/5.3/controllers#resource-controllers和部分資源。 – kyle