03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Access Control List 49<br />

.<br />

This was extracted from public/css/layout.css.<br />

One last thing we have to do, to get the error messages to look the same as they did before, is to add<br />

a bit of CSS to target the Bootstrap-friendly error messages.<br />

With the add view complete; we can create the addAction() method:<br />

1 public function addAction()<br />

2 {<br />

3 $form = new GroupForm();<br />

4<br />

5 if ($form->isPosted())<br />

6 {<br />

7 if ($form->isValidForAdd())<br />

8 {<br />

9 Group::create([<br />

10 "name" => Input::get("name")<br />

11 ]);<br />

12<br />

13 return Redirect::route("group/index");<br />

14 }<br />

15<br />

16 return Redirect::route("group/add")->withInput([<br />

17 "name" => Input::get("name"),<br />

18 "errors" => $form->getErrors()<br />

19 ]);<br />

20 }<br />

21<br />

22 return View::make("group/add", [<br />

23 "form" => $form<br />

24 ]);<br />

25 }<br />

.<br />

This was extracted from app/controllers/GroupController.php.<br />

You can also see how much simpler our addAction() method is; now that we’re using the<br />

GroupForm class. It takes care of retrieving old error messages and handling validation so that<br />

we can simply create groups and redirect.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!