2. What is Laravel?
● MVC PHP Framework
● Created in April 2011
● Incredibly well documented
● "A framework for Web Artisans"
● Ease of entry
● Something for everyone
○ emphasizes flexibility and expressiveness.
3. What makes Laravel different?
● Bundles
○ Laravel's Package System
○ Easily add plugins to your project
○ Easily share your code with others
● Eloquent ORM
○ Not everyone is a DBA
○ Using PHP ActiveRecord
○ Takes advantage of Fluent Query Builder
■ Uses prepared statements
■ Automatic defense against SQL injection
● Flexible Application Logic
○ Route using controllers or directly via routes
4. What makes Laravel different?
● RESTful controllers
○ Easily separate GET and POST requests
● Class Autoloading
○ Just use your class, laravel takes care of the loading
○ Only required classes are loaded for each request
● Migrations
○ Version control for your database schema
● Unit Testing - PHPUnit tightly integrated
● Automatic pagination
● Reverse Routing
○ Easily change routes down the road
○ Using route names prevents broken links / routes
5. Laravel Project Structure
/application - Most of your Application Code
/bundles - Laravel Applications (plugins)
/laravel - Core Framework Files
/public - Webserver Document Root
/storage - File store for services (Cache)
/vendor - Code used by Laravel
/artisan [file] - Laravel Command Line Interface
/paths.php [file] - Used to determine file paths
6. Laravel Application Directory
/config - Application configuration files
/controllers - The application "Logic"
/language - Localisation files
/libraries - For "drop in" single file classes
/migrations - DB Schema version control files
/models - Classes to interact with a database
/tasks - add custom tasks to the artisan CLI
/tests - Unit Testing
/views - HTML Templates
8. Using Controllers
class Account_Controller extends Base_Controller
{
public function action_index()
{
echo "This is the profile page.";
}
public function action_login()
{
echo "This is the login form.";
}
public function action_logout()
{
echo "This is the logout action.";
}
}
9. Routes with Closures
Route::get('/', function()
{
return View::make('home.index');
});
Here we are responding to requests to the root
of the web app, that use the HTTP verb GET
with a Closure that simply returns a View object
10. Passing Parameters to Closures
To pass parameters to your Closures, simply add the usual view placeholders
to the URI, and define parameters in your Closure, they will be matched in the
order from left to right,
Route::get('user/(:any)/task/(:num)', function($username, $task_number)
{
// $username will be replaced by the value of (:any)
// $task_number will be replaced by the integer in place of (:num)
$data = array(
'username' => $username,
'task' => $task_number
);
return View::make('tasks.for_user', $data);
});
11. More Information
● http://daylerees.com/category/laravel-
tutorials
● http://laravel.com/docs/
● http://forums.laravel.io/
● #laravel on Freenode (IRC)
● https://leanpub.com/codehappy
Major Credit to Dayle Rees and his Code
Happy book. Much of the content here was
from his tutorials. Support him by buying his
book: https://leanpub.com/codehappy