Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Laravel PHP framework. It grows with you.

The Laravel PHP framework. It grows with you.

There are a lot of PHP frameworks these days, which makes, choosing one of them a daunting task.
I'll show you why I chose Laravel as my favourite PHP5.4+ MVC framework by highlighting the basic parts. Creating the skeleton using composer. Designing the database using migrations. Accessing it using the Eloquent ORM. Generating views through the blade templating engine, …
Once you discover how minimal, readable and fun your code can be, you will want to give it a try!


Bart Van den Brande

September 18, 2014


  1. The Laravel PHP framework. It grows with you. Bart Van

    den Brande – @denbatte Slides will be made available
  2. Does anyone use Laravel?

  3. We will ... • highlight the MVC parts of the

    framework • discover the fun in using Laravel!
  4. Disclaimer I am no expert, just giving jumpstart information Going

    to cover a lot, shallowly, so please ask me questions afterwards Laravel is not unique, it uses a lot of other great community packages (Symfony2 -http, -console, -routes, … ) You will be developing fast and with a smile
  5. The roadmap Current stable version 4.2 (may 2014) – Requires

    PHP >=5.4 – Laravel Forge – Laravel Homestead – Laravel Cashier – Mail api – ... HOT NEWS! 5.0 will be there november 2014 – New folder structure – Flysystem integration – Laravel Liferaft – Route caching – Socialite – ...
  6. Ad: Kickstarter project

  7. Let's explore Creating the skeleton

  8. Do not forget to add the serviceProviders to app/config/app.php It

    uses Composer "require": { "laravel/framework": "4.2.*", } "require-dev": { "way/generators": "2.*", "barryvdh/laravel-ide-helper": "1.*", "fzaninotto/faker": "v1.3.0", }
  9. You can change settings in app/config/<setting>.php Multiple environments – Production

    Default environment – Development Based on device name in bootstrap/start.php Overwrite settings App, Database, Queue, Mail, Cache, Auth, Session, View, ...
  10. The circle of life Route Controller View Model The address

    The logic The page The data
  11. Let's explore Designing the database

  12. Artisan? Customizable Laravel Command Line Interface

  13. Let the Artisan work terminal user@device: php artisan generate:migration create_<name>_table

    user@device: php artisan generate:seed user@device: php artisan migrate –-seed Do not forget to add environment database settings at app/config/database.php terminal user@device: php artisan migrate:make create_<name>_table –- create=”<name>” user@device: php artisan migrate
  14. Generated example files Migration file Seed file

  15. What about all those static classes???

  16. Facades A facade is a class that provides access to

    an object from the container. So, when you make a facade call like Cache::get, Laravel resolves the Cache manager and calls the get method on the class. $value = Cache::get('key'); Resolves to $value = $app->make('cache')->get('key'); Win! Easy code and testable
  17. Migrations: Cool database tricks Soft deleting? $table->softDeletes(); Created_at and updated_at

    timestamps? $table->timestamps(); Getting filled automatically unless otherwise provided with public $timestamps = false;
  18. Let's explore Accessing data using Eloquent

  19. The Model-vc terminal user@device: php artisan generate:model <Model> • A

    model makes Eloquent understand your data. • Use the singular form of your table as convention
  20. The Model code <?php class Joke extends Eloquent { //

    Some extra code if needed // use SoftDeletingTrait; // protected $table = 'all_my_stupid_jokes_table_name'; // protected $fillable = array('joke', 'category'); // relationship definitions }
  21. Relationships – One to One – One to Many –

    Many to Many Define a method in your model class binding it to a other model – Has Many Through – Polymorphic Relations – Many To Many Polymorphic Relations – Has Many Through
  22. The Model-vc $jokes = Joke::all(); Return all jokes as object

    Return a joke on id $jokes = Joke::find(1); Return all jokes about weight as array $jokes = Joke::where('type', '=', 'weight')->get()->toArray(); Return all jokes about weight $jokes = Joke::where('type', '=', 'weight')->get(); Some queries to throw at your model. Return all jokes about weight as json … well ... guess Tell them about Query Scopes!!!
  23. Let's explore Generating views

  24. The m-View-c – Call views using View::make('<viewname>'); – Views.blade.php is

    able to use the blade templating engine • @foreach(jokes as joke) // Your jokes come here @endforeach • {{ $variable }} • Partials with @yield – Using Twig with twigbridge
  25. Let's explore Controllers

  26. Routes • Using Route::post() or Route::get() • Using a Route::resource();

    – Route names – Route filters – Route groups – Route prefixing – Route 404's – Sub domain routing • Route candy
  27. The mv-Controller • A basic controller Direct link from your

    route: JokesController@index index method method in the Jokes controller →
  28. The mv-Controller terminal user@device: php artisan controller:make <ControllerName> • A

    restfull controller – index – create – show – store – edit – update – destroy
  29. Some resources • http://laravel.com/api/ • http://laravel.com/docs • http://laracasts.com • http://laravel.io

  30. Thank you … I survived! Questions? Please give me feedback

    https://joind.in/11927 !