Laravel:AdminController::getUpdateUser() 缺少参数 1
Laravel: Missing argument 1 for AdminController::getUpdateUser()
我是 larevel 的新手,从昨天到现在我一直在尝试解决这个问题,但没有取得任何进展,我被困在这里....
请帮忙:(
这是我的 路线代码:
Route::get('/admin/edit', array('uses' => 'AdminController@getUpdateUser', 'as' => 'getUpdateUser'));
Route::resource('admin1', 'AdminController');
这是我查看更新按钮的代码(我认为问题可能出在这里,我想不出调用 id D: 的代码)
{{ link_to_action('AdminController@getUpdateUser', 'Edit', array($users->id),array('class' => 'btn btn-info')) }}
--
这是我的代码 AdminController:
public function getUpdateUser($id)
{
$users = User::find($id);
//load view and pass users
return View::make('admin.edit')
->with('users', $users);
}
public function updateUser($id)
{
$validate = Validator::make(Input::all(), array(
'firstname' => 'required',
'lastname' => 'required',
'middlename' => 'required',
'address' => 'required',
'birthday' => 'required',
'contact' => 'required|numeric',
'email' => 'required'
));
if ($validate->fails()) {
return Redirect::to('admin.edit')
->withErrors($validate)
->withInput(Input::except('password'));
}
else
{
$user = User::find($id);
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->middlename = Input::get('middlename');
$user->address = Input::get('address');
$user->birthday = Input::get('birthday');
$user->contact = Input::get('contact');
$user->email = Input::get('email');
if($user->save())
{
return Redirect::route('admin.view')->with('success', 'USER HAS BEEN UPDATED');
}
else
{
return Redirect::route('admin.view')->with('fail', 'An error occured while updating the user. Please double check your inputs and try again.');
}
}
}
这是我的 admin.edit
代码
@extends('layouts.master')
@section('head')
@parent
<title>Manage Users</title>
@stop
@section('content')
<div class ="container">
<h1>Edit User</h1>
{{ Form::model($users, array('route' => array('admin1.updateUser', $users- >id), 'method' => 'PUT')) }}
--textboxes and inputs here--
{{ Form::submit('Update', array('class' => 'btn btn-info')) }}
请帮助我 T_T 谢谢!
您错过的是将 id 实际上作为 route parameter 放在路由 URL 中。像这样:
Route::get('/admin/edit/{id}', array('uses' => 'AdminController@getUpdateUser', 'as' => 'getUpdateUser'));
我是 larevel 的新手,从昨天到现在我一直在尝试解决这个问题,但没有取得任何进展,我被困在这里....
请帮忙:(
这是我的 路线代码:
Route::get('/admin/edit', array('uses' => 'AdminController@getUpdateUser', 'as' => 'getUpdateUser'));
Route::resource('admin1', 'AdminController');
这是我查看更新按钮的代码(我认为问题可能出在这里,我想不出调用 id D: 的代码)
{{ link_to_action('AdminController@getUpdateUser', 'Edit', array($users->id),array('class' => 'btn btn-info')) }}
-- 这是我的代码 AdminController:
public function getUpdateUser($id)
{
$users = User::find($id);
//load view and pass users
return View::make('admin.edit')
->with('users', $users);
}
public function updateUser($id)
{
$validate = Validator::make(Input::all(), array(
'firstname' => 'required',
'lastname' => 'required',
'middlename' => 'required',
'address' => 'required',
'birthday' => 'required',
'contact' => 'required|numeric',
'email' => 'required'
));
if ($validate->fails()) {
return Redirect::to('admin.edit')
->withErrors($validate)
->withInput(Input::except('password'));
}
else
{
$user = User::find($id);
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->middlename = Input::get('middlename');
$user->address = Input::get('address');
$user->birthday = Input::get('birthday');
$user->contact = Input::get('contact');
$user->email = Input::get('email');
if($user->save())
{
return Redirect::route('admin.view')->with('success', 'USER HAS BEEN UPDATED');
}
else
{
return Redirect::route('admin.view')->with('fail', 'An error occured while updating the user. Please double check your inputs and try again.');
}
}
}
这是我的 admin.edit
代码@extends('layouts.master')
@section('head')
@parent
<title>Manage Users</title>
@stop
@section('content')
<div class ="container">
<h1>Edit User</h1>
{{ Form::model($users, array('route' => array('admin1.updateUser', $users- >id), 'method' => 'PUT')) }}
--textboxes and inputs here--
{{ Form::submit('Update', array('class' => 'btn btn-info')) }}
请帮助我 T_T 谢谢!
您错过的是将 id 实际上作为 route parameter 放在路由 URL 中。像这样:
Route::get('/admin/edit/{id}', array('uses' => 'AdminController@getUpdateUser', 'as' => 'getUpdateUser'));