Laravel - Missing argument 2 for UserController::edit()(Laravel-UserController::EDIT()的参数2缺失)
本文介绍了Laravel-UserController::EDIT()的参数2缺失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用框架Laravel。
我有两个表(用户和人员)。当我想同时编辑用户和人员时,我收到错误消息:
UserController::EDIT()缺少参数2
表用户
CREATE TABLE IF NOT EXISTS `festival_aid`.`users` (
`user_id` BIGINT NOT NULL AUTO_INCREMENT,
`user_username` VARCHAR(45) NOT NULL,
`user_email` VARCHAR(45) NOT NULL,
`user_password` CHAR(32) NOT NULL,
`user_salt` CHAR(32) NOT NULL,
`user_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_modified` TIMESTAMP NULL,
`user_deleted` TIMESTAMP NULL,
`user_lastlogin` TIMESTAMP NULL,
`user_locked` TIMESTAMP NULL,
`user_token` VARCHAR(128) NULL,
`user_confirmed` TIMESTAMP NULL,
PRIMARY KEY (`user_id`, `person_id`),
UNIQUE INDEX `user_email_UNIQUE` (`user_email` ASC),
INDEX `fk_users_persons1_idx` (`person_id` ASC),
CONSTRAINT `fk_users_persons1`
FOREIGN KEY (`person_id`)
REFERENCES `festival_aid`.`persons` (`person_id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
表人员
CREATE TABLE IF NOT EXISTS `festival_aid`.`persons` (
`person_id` BIGINT NOT NULL AUTO_INCREMENT,
`person_firstname` VARCHAR(45) NULL,
`person_surname` VARCHAR(45) NULL,
`person_created` TIMESTAMP NOT NULL,
`person_modified` TIMESTAMP NULL,
`person_deleted` TIMESTAMP NULL,
PRIMARY KEY (`person_id`))
ENGINE = InnoDB;
模特
class Person extends Eloquent {
protected $table = 'persons';
protected $primaryKey = 'person_id';
public function person()
{
return $this->belongsTo('User');
}
public $timestamps = false;
}
具有编辑和更新功能的用户控制器
public function edit($user_id, $person_id)
{
$user = User::find($user_id);
$person = Person::find($person_id);
return View::make('users.edit')
->with('user', $user)
->with('person', $person);
}
public function update($user_id, $person_id)
{
$rules = array(
'person_firstname' => 'required',
'person_lastname' => 'required',
'user_username' => 'required|unique:users',
'user_email' => 'required|unique:users|email',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
Redirect::to('users/' . $user_id . '/' . $person_id . '/edit')
->withErrors($validator)
->withInput(Input::except('user_password'));
} else {
$user = User::find($user_id);
$person = Person::find($person_id);
$person->person_firstname = Input::get('person_firstname');
$person->person_lastname = Input::get('person_lastname');
$user->user_username = Input::get('user_username');
$user->user_email = Input::get('user_email');
$user->save();
$person->save();
Session::flash('message', 'Successfully updated user!');
return Redirect::to('users/index');
}
查看编辑
<legend>Edit {{ $person->person_firstname }}</legend>
{{ HTML::ul($errors->all()) }}
{{ Form::model($user, $person, array('method' => 'PUT')) }}
<div class="form-group">
{{ Form::label('firstname', 'Firstname') }}
{{ Form::text('person_firstname', Input::old('firstname'), array('class'=>'form-control', 'placeholder' => 'Firstname')) }}
</div>
<div class="form-group">
{{ Form::label('surname', 'Surname') }}
{{ Form::text('person_surname', Input::old('surname'), array('class'=>'form-control', 'placeholder' => 'Surname')) }}
</div>
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('user_username', Input::old('username'), array('class'=>'form-control', 'placeholder' => 'Username')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::text('user_email', Input::old('email'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('Password') }}
{{ Form::password('user_password', array('class'=>'form-control', 'placeholder' => 'Password')) }}
</div>
{{ Form::submit('Edit the User!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
路线
Route::get('/users/{user_id}/edit', 'UserController@edit');
我做错了什么?
推荐答案
您的函数声明指定了两个参数:
public function edit($user_id, $person_id)
然而,该路由仅注入一个参数user_id
。
Route::get('/users/{user_id}/edit', 'UserController@edit');
它应该是这样的:
Route::get('/users/{user_id}/{person_id}/edit', 'UserController@edit');
或从函数声明中删除$person_id
。
这篇关于Laravel-UserController::EDIT()的参数2缺失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Laravel-UserController::EDIT()的参数2缺失
基础教程推荐
猜你喜欢
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01