Successfully reported this slideshow.
Your SlideShare is downloading. ×

Web Development with Laravel 5

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 87 Ad

More Related Content

Slideshows for you (20)

Similar to Web Development with Laravel 5 (20)

Advertisement

Recently uploaded (20)

Web Development with Laravel 5

  1. 1. Laravel 5 The PHP Framework ForWebArtisans
  2. 2. What is Laravel?  PHP Framework for Web Artisans  Built on top of Symfony2 Components  Like any framework, provides services and libraries to make interacting with web requests and other services
  3. 3. Most Popular PHP Framework on Github
  4. 4. Stars 0 4000 16000 Laravel Symfony CodeIgniter Zend Slim 486950715313 5584 9517 12000 9854 8000 15329 CakePHP CodeIgniter Yii2 CakePHP Yii2Laravel Zend Symfony Slim March, 23 2015 https://github.com/search?l=php&o=desc&q=stars%3A%3E1&s=stars&type=Repositories
  5. 5. • Initial Release • Languange • Architecture • License : June 2011 (latest: 5.0.16 March 14, 2015) : PHP (5.4+) : MVC : MIT http://en.wikipedia.org/wiki/Laravel Details
  6. 6. Where to start from? Laravel is very flexible framework. There are at least 3 options how to create new project: - via laravel installer - via composer - clone from github
  7. 7. Via Laravel installer This will download laravel installer via composer - composer global require "laravel/installer=~1.1" When installer added this simple command will create app - laravel new <app name> * Do not forget to add ~/.composer/vendor/bin to your PATH variable in ~/.bashrc
  8. 8. Other options Via composer - composer create-project laravel/laravel your-project-name Get from GitHub - https://github.com/laravel/laravel - And then in the project dir run “composer install” to get all needed packages
  9. 9. Laravel and Composer Using composer in Laravel you can - Add/remove/update packages - Dump autoload file and generate new one - Update laravel version
  10. 10. Overall Architecture
  11. 11. http://tech.knolskape.com/10-‐quick-‐tips-‐to-‐get-‐better-‐at-‐laravel/
  12. 12. What’s New? In laravel 5
  13. 13. What’s New? • New Folder Structure • Contracts (interface) • Route Middleware • Controller Method Injection • Laravel Scheduler • Tinker / Psysh • DotEnv (.env) • Form Requests • Symfony VarDumper
  14. 14. middleware tinker method injection
  15. 15. dd($foo) var_dump($foo) Print_r($foo)
  16. 16. Laravel directory structure The app directory, as you might expect, contains the core code of your application. The config directory, as the name implies, contains all of your application's configuration files. The database folder contains your database migration and seeds. The public directory contains the front controller and your assets (images, JavaScript, CSS, etc.). The app/storage directory contains compiled Blade templates, file based sessions, file caches, and other files generated by the framework. The tests directory contains your automated tests. The vendor directory contains your Composer dependencies. The app/model directory contains your model The app/http/controllers directory contains your model ...
  17. 17. Magic Artisan - Is located in Laravel project root directory - Basically is a php script which performs all actions in Laravel for example: - Manage migrations - Check application routes - tinker - Create Artisan commands - Run database seeds Full list is available with “php artisan list”
  18. 18. Artisan CLI
  19. 19. Artisan commands Artisan commands usually are some scripts launched from command line or with cron. For example you need to have daily export of your orders - write a command and run it with cron. - They accept options and arguments - Have pretty output if needed - Interactive (can ask password/question)
  20. 20. Laravel Environmental Configuration  After installing Laravel and setting up project, the first thing we need to do is Generating Application key ( php artisan key:generate )  Laravel provides facility to run your application in different environment like testing, production,etc.  You can configure the environment of your application in the .env file of the root directory of your application.  If you have installed Laravel using composer, this file will automatically be created.otherwise, you can simply rename the .env.example file to .env file
  21. 21. Environmental Configuration (Continue)  This is a sample .env file  you can both keep configuration/environ ment variables in .env or in a config/ file  Next we’ll see how to keep config in config/ file
  22. 22. Laravel Config Laravel uses config files with arrays in it to store different configurations. database.php -> Location: /config To get config value simply follow dot notation Config::get(‘<filename>.key1.key2.key3’); Can also pass default value on not found Config::get(‘key’, 123);
  23. 23. Laravel actively uses php namespaces to keep classnames short and possibility to use same class names for different components. For example all Admin functionality under Admin namespace. Laravel and namespaces
  24. 24. So Laravel is MVC framework meaning we have folder for controllers, views and models by default, no need to create them. Guess there’s no need to explain MVC pattern. Laravel MVC
  25. 25. Features In Laravel
  26. 26. Features • Artisan CLI • Routing • Middleware • Resourceful Controllers • Eloquent ORM (Object-‐Relational Mapping) • Blade Templating • Migrations and Database Seeding http://www.webdesignermag.co.uk/laravel-‐a-‐modern-‐php-‐framework/
  27. 27. Features • Artisan CLI • Routing • Middleware • Resourceful Controllers • Eloquent ORM (Object-‐Relational Mapping) • Blade Templating • Migrations and Database Seeding http://www.webdesignermag.co.uk/laravel-‐a-‐modern-‐php-‐framework/
  28. 28. Features • Artisan CLI • Routing • Middleware • Resourceful Controllers • Eloquent ORM (Object-‐Relational Mapping) • Blade Templating • Migrations and Database Seeding http://www.webdesignermag.co.uk/laravel-‐a-‐modern-‐php-‐framework/
  29. 29. Features • Artisan CLI • Routing • Middleware • Resourceful Controllers • Eloquent ORM (Object-‐Relational Mapping) • Blade Templating • Migrations and Database Seeding http://www.webdesignermag.co.uk/laravel-‐a-‐modern-‐php-‐framework/
  30. 30.  There’s one main Controller class which all controllers should extend.  By default Laravel has BaseController (extends from Controller) and HomeController (extends from BaseController) Laravel controllers
  31. 31. Laravel controllers More advanced example. Responds only to get method and returns rendered view Responds to post method, and returns redirect to next logical action
  32. 32. Type-hint any dependency in controller constructors Type-hint any dependency in Controller methods
  33. 33. Features • Artisan CLI • Routing • Middleware • Resourceful Controllers • Eloquent ORM (Object-‐Relational Mapping) • Blade Templating • Migrations and Database Seeding http://www.webdesignermag.co.uk/laravel-‐a-‐modern-‐php-‐framework/
  34. 34. Blade
  35. 35. Laravel migrations  Interaction with migrations is happening through artisan commands.  Each migration has two functions up and down to migrate and rollback
  36. 36. Features • Artisan CLI • Routing • Middleware • Resourceful Controllers • Migrations and Database Seeding • Eloquent ORM (Object-‐Relational Mapping) • Blade Templating http://www.webdesignermag.co.uk/laravel-‐a-‐modern-‐php-‐framework/
  37. 37. Laravel migrations  This is how basic migration looks like
  38. 38. DB seeds  Seeds are used to insert predefined data in tables so there is something to start from for example on development environment we can create test users, test products and so on.
  39. 39. Features • Artisan CLI • Routing • Middleware • Resourceful Controllers • Eloquent ORM (Object-‐Relational Mapping) • Blade Templating • Migrations and Database Seeding http://www.webdesignermag.co.uk/laravel-‐a-‐modern-‐php-‐framework/
  40. 40. Models (Eloquents)  Models are located under app/ directory.  Simple Product model.  Will use ‘products’ table
  41. 41. Laravel ORM Why is it good? - Has a lot of useful methods - Is very flexible - Has built in safe delete functionality - Has built in Relationship functionality - Has option to define scopes
  42. 42. Laravel ORM - Models can have relations defined in them for easier access to properties. - $product->category in this case will return Category model object where this product belongs. How? Laravel assumes you have category_id in your products table, so when you call $product->category query SELECT * FROM ‘categories’ where id = ‘?’ is performed. Of course you can define different relation fields
  43. 43. Laravel ORM Cool methods: // Retrieve the user by the attributes, or create it if it doesn't exist... $user = User::firstOrCreate(array('name' => 'John')); // Retrieve the user by the attributes, or instantiate a new instance... $user = User::firstOrNew(array('name' => 'John')); Basically Laravels ORM has function for anything
  44. 44. Eloquent ORM
  45. 45. Q:A

×