您好我正在尝试使用fname和lname创建一个UI,我想将它添加到我的mysql数据库表中。 以下是我的参考代码。
**register1.blade.php**
@extends('master')
@section('content')
<div class="row">
<div class="span4 offset1">
<div class="well">
<legend>Please Register Here</legend> <br/>
{{ Form::open(array('url' => 'register1')) }}
@if($errors->any())
<div class="alert alert-error">
<a href="#" class="close" data-dismiss="alert">×</a>
{{ implode('', $errors->all('<li class="error">:message</li>')) }}
</div>
@endif
First Name:{{ Form::text('fname', '', array('placeholder' => 'First Name')) }}<br>
Last Name:{{ Form::text('lname', '',array('placeholder' => 'Last Name')) }}<br>
{{ Form::submit('Submit', array('class' => 'btn btn-success')) }}
<!-- {{ HTML::link('register', 'Sign Up', array('class' => 'btn btn-primary')) }}-->
{{ Form::close() }}
</div>
</div>
</div>
@stop
**HomeController.php**
public function getRegister1()
{
return View::make('home.register1');
}
public function postRegister1()
{
$input = Input::all();
$rules = array('fname' => 'required', 'lname' => 'required');
$v = Validator::make($input, $rules);
if($v->fails())
{
return Redirect::to('register1')->withErrors($v);
} else {
$credentials = array('fname' => $input['fname'], 'lname' => $input['lname']);
if(Auth::attempt($credentials))
{
return Redirect::to('admin');
} else {
return Redirect::to('register1');
}
}
}
**in models-> register.php**
<?php
use Illuminate\Auth\RegisterInterface;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class register extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'register1';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getFirstName()
{
return $this->fname;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getLastName()
{
return $this->lname;
}
**routes.php**
Route::get('register1','HomeController@getRegister1');
Route::post('register1','HomeController@postRegister1');
当我执行注册时,它会给我文本框并提交。 onclick of submit我有以下错误
**illuminate \ Database \ QueryException**
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'fname' in 'where clause' (SQL: select * from `users` where `fname` = sonu and `lname` = k limit 1)
please help me out with this issue.
答案 0 :(得分:1)
由于用户表中没有 fname 列,因此抛出错误。您应检查数据库结构,并确保存在 fname 列。
答案 1 :(得分:1)
假设您有一个包含所有必要列的register
表,您需要告诉您的应用使用该表进行身份验证。所以在`app / config / auth.php&#39;中,根据您使用的驱动程序,您需要输入如下条目:
'model' => 'register',
如果你正在使用“滔滔不绝”的话。司机,或
'table' => 'register1'
如果您正在使用数据库驱动程序。
此外,对于它的价值很小,传统上模型的类名是CamelCase,表名是小写和复数。因此,在您的情况下,class Register ....
和protected $table = registers;
。
如果上述内容无法启动并运行,请尝试查看本教程:http://laravelbook.com/laravel-user-authentication/。