I wonder what wrong in my code that I can't protected 2 input username and password
In my controller:
class AccountsController extends \BaseController {
...
public function store()
{
$date = new \DateTime;
$input['updated_at']=$date;
$input['created_at']=$date;
$input['username']=Input::get("username", "");
$input['password']=Input::get("password", "");
$input['sex']=Input::get("sex", "");
$input['dob']=Input::get("dob", "");
$input['dob']= date("Y-m-d", strtotime($input['dob']));
$v=Validator::make($input, Account::$register_rules);
$input['password']=Hash::make($input['password']);
if($v->passes()){
DB::table('accounts')->insert($input);
}
//return Redirect::route('text.index');
}
...
}
In my model:
class Account extends \Eloquent {
protected $guarded = array('username', 'password');
public static $register_rules=array(
'username' => 'required|min:4|max:20|unique:accounts',
'password' => 'required|alpha_num|min:6',
'sex' => 'required|in:f,m',
'dob' => 'required|date_format:Y-m-d'
);
}
In my app/view
...
{{ Form::open(array('route'=>'account.store')) }}
<table>
<tr>
<td>{{ Form::label('username', 'Username') }}</td>
<td>{{ Form::text('username') }}</td>
</tr>
<tr>
<td>{{ Form::label('password', 'Password') }}</td>
<td>{{ Form::password('password') }}</td>
</tr>
<tr>
<td>{{ Form::label('confirm_password', 'Confirm Password') }}</td>
<td>{{ Form::password('confirm_password', array('id'=>'confirm_password')) }}</td>
</tr>
<tr>
<td>{{ Form::label('sex', 'Sex') }}</td>
<td>
{{ Form::radio('sex', 'f', true) }}{{ Form::label('Female') }}
{{ Form::radio('sex', 'm') }}{{ Form::label('Male') }}
</td>
</tr>
<tr>
<td>{{ Form::label('dob', 'Date of Birth') }}</td>
<td>
{{Form::text('dob', '', array('id' => 'dob'))}}
</td>
</tr>
<tr>
<td></td>
<td>{{ Form::submit('Register', array('id' => 'submit')) }}</td>
</tr>
</table>
{{ Form::close() }}
...
Even though I defined guarded these two fields they are still saved in the database.