Save 37% off PRO during our Black Friday Sale! »

Hello World, I'M Laravel v3

Hello World, I'M Laravel v3

Hello World, I'M Laravel by Christoph Rumpel
Published November 27, 2015 in Programming

So there is this thing called Laravel. You may have heard of it already, but you’re not sure what it is actually about? Or you do, but want to know more about it? Great, cause this talks is especially for you! Laravel is at the same time one of the youngest and most popular PHP frameworks out there. So how does this work together? Let us take a closer look at why it is that popular and how it could be of use for you too. We will go through the main functionalities and talk about all the brand new features in version 5. So be there!

14d39e65f615fd6dcb9dd44ea7f7995b?s=128

Christoph Rumpel

April 25, 2016
Tweet

Transcript

  1. H E L L O W O R L D

    , I ’ M L A R AV E L C H R I S T O P H R U M P E L
  2. A F R A M E W O R K

    I S JUST A TOOL
  3. A F R A M E W O R K

    I S JUST A TOOL could be more!
  4. G R E AT F O R B E G

    I N N E R S A N D R A P I D D E V E L O P M E N T L A R A V E L I S …
  5. L A R A V E L I S …

    M A D E F O R A L L K I N D O F P R O J E C T S I Z E S
  6. L A R A V E L I S …

    A N E C O S Y S T E M
  7. W O R K I N G F O R

    L I E C H T E N E C K E R . AT
  8. F I N D M E C H R I

    S T O P H - R U M P E L . C O M @ C H R I S T O P H R U M P E L
  9. Laravel Facts • Since 2011 • Current version: 5.2 •

    PHP >= 5.5.9 • Composer project • 323 contributors
  10. TAY L O R O T W E L L

    T H I S G U Y
  11. G E T T I N G R E A

    L S TA R T S W I T H T H E I N T E R FA C E , T H E R E A L S C R E E N S T H A T P E O P L E A R E G O I N G T O U S E … . T H I S L E T S Y O U G E T T H E I N T E R FA C E R I G H T B E F O R E Y O U G E T T H E S O F T WA R E W R O N G . “ “
  12. G E T T H E I N T E

    R FA C E R I G H T B E F O R E Y O U G E T T H E S O F T WA R E W R O N G . “ “ G E T T I N G R E A L B Y 3 7 S I G N A L S , C R E A T O R S O F B A S E C A M P.
  13. F I R S T S T E P S

    L A R A V E L
  14. R O U T E S W H E R

    E D O Y O U WA N N A G O
  15. Route::get(‘/‘, function() { return ‘Hello Webclerks’; });

  16. Route::post(‘/recipe’, ‘RecipeController@store’); Route::get(‘/recipe’, ‘RecipeController@index’);

  17. E L O Q U E N T N O

    T H I N G I S M O R E E L O Q U E N T T H A N
  18. Recipe::all();

  19. Recipe::find(1);

  20. $recipe = Recipe::where('name', ‘Lasagne’)->get(); $recipe = new Recipe; $recipe->name =

    ‘Lasagne’; $recipe->save(); $recipe->update([‘name’ => ‘Sushi’]); $recipe->delete(); C R D U
  21. C O N T R O L L E R

    S
  22. class RecipeController extends Controller { public function index() { $recipes

    = Recipe::all(); return view(‘recipes.index’, [‘recipes’ => $recipes]); } }
  23. public function store() { $validator = Validator::make(Input::all(), [ 'name' =>

    'required|unique:recipes|max:255', ]); } if ($validator->fails()) { //… redirect with error message } Recipe::create(Input::all()); // …success message
  24. B L A D E D E F I N

    E Y O U R V I E W
  25. M I G R AT I O N S W

    E L C O M E
  26. Migrations are like version control for your database

  27. 2016_04_25_123134_create_recipes_table.php 2016_04_25_123322_create_ingredients_table.php

  28. class CreateRecipesTable extends Migration { public function up() {…} public

    function down() {…} }
  29. public function up() { Schema::create('recipes', function(Blueprint $table)
 { $table->increments(‘id'); $table->string(‘name')->unique();


    }); }
  30. public function down() { Schema::drop(‘recipes’); }

  31. N E X T L E V E L L

    A R A V E L
  32. M I D D L E WA R E M

    A L C O L M I N T H E
  33. Auth A P P Session Request Middleware

  34. // app/Http/Middleware class Authenticate { public function handle() {…} }

  35. Route::post(‘/recipe’, [ 'middleware' => ‘auth’ ‘uses' => ‘RecipeController@store’ ]);

  36. D E P E N D E N C Y

    I N J E C T I O N D O N ’ T B E A F R A I D O F
  37. IoC Inversion of Control

  38. public function store() { // …store logic Mail::send(‘email.stored', $data, $callback);

    }
  39. Constructor injection

  40. class RecipeController extends BaseController { protected $mailer; public function __construct(Mailer

    $mailer) { $this->mailer = $mailer; } public function store() { //… store logic $this->mailer->send(…); } }
  41. Method injection

  42. class RecipeController extends BaseController { public function index(Mailer $mailer) {

    $mailer->send(…); } }
  43. A R T I S A N C O M

    M A N D - L I N E I N T E R FA C E
  44. php artisan make:migration create_users_table php artisan make:controller RecipeController

  45. php artisan email:birthday

  46. public function schedule(Schedule $schedule) { $schedule->command(‘email:birthday') ->dailyAt(’09:00’); }

  47. F O R M R E Q U E S

    T B E T T E R VA L I D A T I O N
  48. public function store() { $validator = Validator::make(Input::all(), [ 'name' =>

    'required|unique:recipes|max:255', ]); } if ($validator->fails()) { //… redirect with error message } Recipe::create(Input::all()); // …success message
  49. class StoreRecipeFormRequest extends Request { public function authorize() {…} public

    function rules() {…} }
  50. public function authorize() { return Auth::user()->isAdmin(); }

  51. public function rules() { return [ 'name' => ‘required|unique:recipes|max:255', ];

    }
  52. public function store(StoreRecipeFormRequest $formRequest) { } $this->recipe->create(Input::all()); // …success message

  53. T E S T I N G E N L

    I G H T E N
  54. E C O S Y S T E M L

    A R A V E L
  55. Homestead Laravel Vagrant Box

  56. None
  57. None
  58. None
  59. None
  60. None
  61. L A R AV E L I S M O

    R E T H A N A F R A M E W O R K
  62. Thank YOU

  63. Questions?

  64. Thank YOU AGAIN

  65. Resources • http://laravel.com/ • https://laracasts.com/ • https://forge.laravel.com/ • https://envoyer.io/ •

    https://spark.laravel.com/ • http://lumen.laravel.com/ • http://www.laravelpodcast.com/ • http://bossfight.co/man-photographer/ • https://unsplash.com/
  66. Cache::get(); Recipe::all(); Mail::send(); Route::get(); Facades

  67. class HomeTest extends TestCase { public function testHomeSite() { $this->visit(‘/‘)

    ->assertResponseOk(); } }
  68. public function testHomeSite() { $this->visit(‘/‘) ->see(‘My recipes’); }

  69. public function testStoreRecipe() { $this->post(‘/recipe’, [‘name’ => ‘Lasagne’]) ->seeJson([‘created’ =>

    true]); }