03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

File-Based CMS 332<br />

56 type="submit"<br />

57 name="save"<br />

58 class="btn btn-default"<br />

59 value="Save"<br />

60 /><br />

61 <br />

62 @stop<br />

.<br />

This file should be saved as app/views/admin/layout/edit.blade.php.<br />

1 Route::any("admin/layout/edit", [<br />

2 "as" => "admin/layout/edit",<br />

3 "uses" => "LayoutController@editAction"<br />

4 ]);<br />

.<br />

This was extracted from app/routes.php.<br />

The editAction() method fetches the layout file data and extracts/parses the metadata, so that we<br />

can present it in the edit form. Other than utilising the second custom validation function, we define<br />

in the constructor, there’s nothing else noteworthy in this method.<br />

The edit form is also pretty much the same, except that we provide default values to the Input::old()<br />

method calls, giving the data extracted from the layout file. We also add a route to the edit page.<br />

.<br />

You may notice that the file name remains editable, on the edit page. When you change this value,<br />

and save the layout it won’t change the name of the current layout file, but rather generate a new<br />

layout file. This is an interesting (and in this case useful) side-effect of using the file name as the<br />

unique identifier for layout files.<br />

Deleting layout files is even simpler:

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

Saved successfully!

Ooh no, something went wrong!