Laravel Starter - PHP User Group (Myanmar)
Laravel Starter - PHP User Group (Myanmar)
Laravel Starter - PHP User Group (Myanmar)
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Laravel</strong> <strong>Starter</strong><br />
Then, we tell our controller that for every request to one of its actions we want to run the<br />
before filter auth. Now, this controller is completely protected behind your authentication<br />
implementation. You will be unable to access the actions within this controller until you've<br />
successfully logged in. If you try to access one of the controller's actions, you will be redirected<br />
to the login page.<br />
Now, thanks to a combination of <strong>Laravel</strong>'s Auth class and its auth filter, you now have a<br />
properly secured admin site.<br />
Unfortunately, a complete description of <strong>Laravel</strong>'s filter functionality is outside the scope of<br />
this book. Thankfully, <strong>Laravel</strong>'s documentation is a great resource for learning more about<br />
what you can do with filters.<br />
4 – Validation<br />
<strong>Laravel</strong> provides a Validator class full of functionality to help with validating forms, database<br />
models, or anything that you'd like. The Validator class allows you to pass any input, declare<br />
your own rules, and define your own custom validation messages.<br />
Let's take a look at an example implementation for our create users actions.<br />
public function post_create()<br />
{<br />
// validate input<br />
$rules = array(<br />
'real_name' => 'required|max:50',<br />
'email' => 'required|email|unique:users',<br />
'password' => 'required|min:5',<br />
);<br />
$validation = Validator::make(Input::all(), $rules);<br />
if($validation->fails())<br />
{<br />
return Redirect::back()->with_input()<br />
->with_errors($validation);<br />
}<br />
// create a user<br />
$user = new <strong>User</strong>;<br />
$user->real_name = Input::get('real_name');<br />
$user->email = Input::get('email');<br />
$user->password = Input::get('password');<br />
41