Quick intro to Laravel using a custom CMS app I made
This is mainly to show an example of a small CMS being built in Laravel. CMS (Content Management System) that is at it's most basic level, Authentication, Simple Content Types etc.
What we will cover.
- Installing the "CMS" and what Page Types it comes with
- Looking at the folder layout "Where is...."
- App config setting up the site
- PHP Artisan command to migrate the site
- Routes
- Page example looking at the wysiwyg, Controller, View etc
- Tags - lets add a many to many relationship
This is NOT the end all setup just an example. There are links below to quality videos, blogs posts docs etc to take you to the next level, not only in Laravel but just Object Oriented Design and good Architecture in general.
Note the theme has it's own license and you need to purchase it here in order to use it.
Install the "CMS" and what Page Types it comes with
The repo is here https://github.com/alnutile/cms
In time I will add more features but it really is an app that was made for a client that the base of it I wanted to fork off for later use.
Run the basic laravel install steps noted on their site http://laravel.com/docs/quick
What Page Types
- Pages are the main landing pages for most of the site with a slug to manage the url [1]. More on Pages shortly.
- Portfolios was how this project started. Basically you make One and then make projects that reference it.
- Projects are just that. They fit in a Portfolio
- Menu Sorting there is an admin area for menu sorting as well. Right now it is just for the top left menu. (not the black top nav)
All these "Admin" links can be seen below
Every landing page is a Page
Every URLs is Page, Project or Portfolio so the editor can always edit the description of the page even if there is a "collection" under it. For example /all_projects is a Page that just happens to also show a collection of "Projects" under it. Ideally this will be a less hard coded relationship BUT this particular example just needed a simple data set.
There are Portfolio and Project pages as well that the edit can edit the description on etc.
Looking at the folder layout
This is a standard Laravel App. The one key folder is app/CMS for some items. But otherwise the Controllers, Models etc have all the needed data. [2]
In app/CMS there is the Menu Facade, and the MenuService to make managing the menu system easier. [3]
The system puts it's uploaded files under public/img in settings, banners etc
App config setting up the site
The app default to sqlite and the bootstrap/start.php will default to local without you needing to set anything.
Running migrations will get you a good sample set of data. You can always turn this off in app/database/seeds
In the app/database/seeds/UsersTableSeeder.php file is the admin and test user emails and passwords to login.
Routes
The app/routes.php is where you can manage routes and see what is there right now.
Page Example
You can edit a page or add a page.
Once in there you will see this
You can give the page a title, SEO title, upload images and files via the wysiwyg and set the slug (Published coming soon so there can be a workflow)
Tags
There is a tagging feature that does not yet have the UI setup. (coming soon). The resource is setup but needs to be placed in the view
In php artisan tinker we can mess around with tags thought
php artisan tinker
$tag = new Tag(['name' => "Test 4"]);
Portfolio::find(1)->tags()->save($tag);
Portfolio::find(1)->tags->toArray();
Tag::find(1)->portfolios->toArray();
Portfolio::find(1)->tags()->detach(1);
Portfolio::find(1)->tags()->attach(1);
So we are making a tag, saving it to Portfolio 1. Seeing it attached to Portfolio 1 and Seeing Portfolios attached to it.
Links
- Great videos on Laravel, Oop and design patters https://laracasts.com/
- Laravel own docs are great http://laravel.com/docs
- Forums and Chat room http://laravel.io/forum
- Great overview of Laravel app building http://culttt.com/2013/04/29/getting-started-with-laravel-4/
Footnotes
[1] This will be refactored shortly [2] This will be moved shortly to make it way more extendable but leaving the core easy to manage. [3] Refactor this out so menu is a manyToMany relationship with the models that will use it.