我有我的表单,当我按下按钮提交时,我呼叫控制器用户使用方法Create,添加一个用户。
路由转到控制器,然后我得到一个错误未知列inputemail
@section('modal_body')
{{ Form::open(array('id' =>'formuser-create', 'role' => 'form', 'url' =>'users/create', 'class' => 'form-horizontal')) }}
<div class="form-group">
{{ Form::label('inputuser', 'Nombre de usuario', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::text('inputuser','', array('placeholder' => 'Introduce la contraseña...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('inputpassword', 'Contraseña', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::password('inputpassword','', array('placeholder' => 'Introduce la contraseña...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('inputpassword1', 'Confirmar constraseña', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::password('inputpassword1','', array('placeholder' => 'Vuelve a introducir la contraseña...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('inputemail', 'Email', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::text('inputemail','', array('placeholder' => 'Introduce el email...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('es_admin', '¿Es administrador?', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::checkbox('es_admin',1,false) }}
</div>
</div>
@stop
@section('modal_footer')
<div class='form-group text-center' id='editor-actions'>
{{ Form::submit('Guardar', ['class' => 'btn btn-success']) }}
{{ Form::reset('Limpiar', ['class' => 'btn btn-primary']) }}
{{ Form::close() }}
</div>
@stop
@endif
我打电话给我的控制器
Route::Controller('users','UsersController');
我的控制器的代码是
<?php
class UsersController extends BaseController
{
public function __construct() {
$this->beforeFilter('auth'); //bloqueo de acceso
}
public function getIndex()
{
$my_id = Auth::user()->id;
$is_admin = Auth::user()->admin;
//control permissions only access administrator
if($is_admin==1)
{
$users = User::where('admin', '<>', '1')->where('id', '<>', $my_id)->get();
return View::make('admin/users.index')->with('users',$users);
}
else
{
return View::make('errors.access_denied');
}
}
//metodo para agregar al usuario
public function postCreate()
{
//validamos reglas inputs
$rules = array(
'inputuser' => 'required|max:10',
'inputpassword' => 'required|min:8',
'inputpassword1' => 'required|min:8',
'inputemail' => 'required|email|unique:users'
);
$validation = Validator::make(Input::all(), $rules);
//Si no pasa la validacion
if($validation->fails())
{
return Redirect::back()->with_input()->with_errors($validation);
}
//Si todo ha ido bien guardamos
$password = Input::get('inputpassword');
$user = new User;
$user->username = Input::get('inputuser');
$user->password = Hash::make($password);
$user->email = Input::get('inputemail');
$user->admin = Input::get('es_admin');
//guardamos
$user->save();
//redirigimos a usuarios
return Redirect::to('admin/users.index')->with('status','ok_create');
}
}
我收到以下错误跟踪
我
lluminate\Database\QueryException thrown with message "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'inputemail' in 'where clause' (SQL: select count(*) as aggregate from `users` where `inputemail` = mangulomx@gmail.com)"
Stacktrace:
#35 Illuminate\Database\QueryException in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Connection.php:625
#34 UsersController:postCreate in <#unknown>:0
#33 Illuminate\Routing\Router:Illuminate\Routing\{closure} in <#unknown>:0
#32 PDOException in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Connection.php:299
#31 PDO:prepare in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Connection.php:299
#30 Illuminate\Database\Connection:Illuminate\Database\{closure} in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Connection.php:617
#29 Illuminate\Database\Connection:runQueryCallback in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Connection.php:581
#28 Illuminate\Database\Connection:run in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Connection.php:304
#27 Illuminate\Database\Connection:select in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:1412
#26 Illuminate\Database\Query\Builder:runSelect in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:1397
#25 Illuminate\Database\Query\Builder:getFresh in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:1384
#24 Illuminate\Database\Query\Builder:get in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:1830
#23 Illuminate\Database\Query\Builder:aggregate in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:1768
#22 Illuminate\Database\Query\Builder:count in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Validation\DatabasePresenceVerifier.php:57
#21 Illuminate\Validation\DatabasePresenceVerifier:getCount in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:1020
#20 Illuminate\Validation\Validator:validateUnique in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:322
#19 Illuminate\Validation\Validator:validate in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:283
#18 Illuminate\Validation\Validator:passes in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:297
#17 Illuminate\Validation\Validator:fails in C:\wamp\www\viversoft\app\controllers\UsersController.php:38
#16 UsersController:postCreate in <#unknown>:0
#15 call_user_func_array in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:231
#14 Illuminate\Routing\Controller:callAction in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:93
#13 Illuminate\Routing\ControllerDispatcher:call in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:62
#12 Illuminate\Routing\ControllerDispatcher:dispatch in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Routing\Router.php:967
#11 Illuminate\Routing\Router:Illuminate\Routing\{closure} in <#unknown>:0
#10 call_user_func_array in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Routing\Route.php:109
#9 Illuminate\Routing\Route:run in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Routing\Router.php:1033
#8 Illuminate\Routing\Router:dispatchToRoute in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Routing\Router.php:1001
#7 Illuminate\Routing\Router:dispatch in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:775
#6 Illuminate\Foundation\Application:dispatch in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:745
#5 Illuminate\Foundation\Application:handle in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Session\Middleware.php:72
#4 Illuminate\Session\Middleware:handle in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php:47
#3 Illuminate\Cookie\Queue:handle in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php:51
#2 Illuminate\Cookie\Guard:handle in C:\wamp\www\viversoft\vendor\stack\builder\src\Stack\StackedHttpKernel.php:23
#1 Stack\StackedHttpKernel:handle in C:\wamp\www\viversoft\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:641
#0 Illuminate\Foundation\Application:run in C:\wamp\www\viversoft\public\index.php:49
我不明白,因为未知的colum&#39; inputemail&#39;
答案 0 :(得分:2)
unique:table,column,except,idColumn
验证字段在给定数据库表上必须是唯一的。如果未指定
column
选项,则将使用字段名称。
由于您的输入名称与数据库中的列名称不同,您必须指定它:
'inputemail' => 'required|email|unique:users,email'
// ^^^^^