
APPENDIX More New Features in Laravel 5.8 Laravel 5.8 has many improvements and updates. Some of them seem to be quite interesting and will impact the course of future development. In this appendix, you’ll take a quick look at some of them. One of the most interesting changes is the “dump server” feature. It was first incorporated in Laravel 5.7 and then extended in Laravel 5.8. What Is the Dump Server Feature? The dump server feature allows you to start a “dump server” to collect dump information about the internal processes. Let’s start a new version of Laravel 5.8 installed locally. Then open the composer. json file and take a look at this part: "require-dev": { "beyondcode/laravel-dump-server": "^1.0", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", "mockery/mockery": "^1.0", "nunomaduro/collision": "^2.0", "phpunit/phpunit": "^7.5" }, You’ll see beyondcode/laravel-dump-server": "^1.0" already in place. 399 © Sanjib Sinha 2019 S. Sinha, Beginning Laravel, https://doi.org/10.1007/978-1-4842-4991-8 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 Next, open the routes/web.php file and add this line: Route::get('/', function () { dump("Hello Laravel 5.8"); return view('welcome'); }); This gives you the output shown in Figure A-1. Figure A-1. Dump server output in the browser Next, in the terminal, so ahead and pass this command: $ php artisan dump-server It gives us this output: ss@ss-H81M-S1:~$ cd code/laravel58/ ss@ss-H81M-S1:~/code/laravel58$ php artisan dump-server 400 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 Laravel Var Dump Server ======================= [OK] Server listening on tcp://127.0.0.1:9912 // Quit the server with CONTROL-C. GET http://localhost:8000/ -------------------------- ------------ --------------------------------- date Wed, 03 Apr 2019 00:33:20 +0000 controller "Closure" source web.php on line 16 file routes/web.php ------------ --------------------------------- "Hello Laravel 5.8" Figure A-2 shows the output in the terminal. It is interesting to take note that in the browser, at the same time, the page just vanishes. Figure A-2. Dump server output in the terminal 401 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 Let’s dump all the users the same way. Remember, I have seeded the users table with fake data, and currently there are 21 users in the database. Go ahead and change your routes/web.php file in this way: use App\User; Route::get('/', function () { $users = User::all(); dump($users); return view('welcome'); }); Open your browser, and you will see something like Figure A-3. Figure A-3. The browser is filled with the dumped user data However, you can manage this output by running the dump-server artisan command in the terminal. You will then get the clean output in the browser (Figure A-4). 402 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 Figure A-4. Clear browser without dumped user data Instead, all the user data is being displayed in the terminal, as shown in Figure A-5. 403 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 Figure A-5. Dumped user data in the terminal Now change the routes/web.php code to the following and run the dump-server command again: use App\User; Route::get('/', function () { $users = User::all()->toArray(); dump($users); return view('welcome'); }); 404 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 The output is dumped in the terminal like in Figure A-6. ss@ss-H81M-S1:~/code/laravel58$ php artisan dump-server Laravel Var Dump Server ======================= [OK] Server listening on tcp://127.0.0.1:9912 // Quit the server with CONTROL-C. GET http://localhost:8000/ -------------------------- ------------ --------------------------------- date Wed, 03 Apr 2019 00:56:02 +0000 controller "Closure" source web.php on line 19 file routes/web.php ------------ --------------------------------- array:22 [ 0 => array:10 [ "id" => 1 "country_id" => 5 "role_id" => 4 "name" => "Sarina Becker MD" "email" => "[email protected]" "email_verified_at" => null "created_at" => "2018-11-17 03:46:58" "updated_at" => "2018-11-28 03:15:55" "admin" => 0 "mod" => 0 ] 1 => array:10 [ "id" => 2 "country_id" => 7 "role_id" => null "name" => "Ariel Hand" "email" => "[email protected]" "email_verified_at" => null "created_at" => "2018-11-17 03:46:59" 405 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 "updated_at" => "2018-11-17 03:46:59" "admin" => 0 "mod" => 0 ] 2 => array:10 [ "id" => 3 "country_id" => null "role_id" => null "name" => "Carissa Raynor" "email" => "[email protected]" "email_verified_at" => null "created_at" => "2018-11-17 03:46:59" "updated_at" => "2018-11-17 03:46:59" "admin" => 0 "mod" => 0 ] 3 => array:10 [ "id" => 4 "country_id" => null "role_id" => null "name" => "Jude Johnston" "email" => "[email protected]" "email_verified_at" => null "created_at" => "2018-11-17 03:46:59" "updated_at" => "2018-11-17 03:46:59" "admin" => 0 "mod" => 0 ] 4 => array:10 [ "id" => 5 "country_id" => null "role_id" => null "name" => "Sarai Beier" "email" => "[email protected]" "email_verified_at" => null "created_at" => "2018-11-17 03:46:59" 406 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 "updated_at" => "2018-11-17 03:46:59" "admin" => 0 "mod" => 0 ] 5 => array:10 [ "id" => 6 "country_id" => null "role_id" => null "name" => "Ms. Freda Kemmer" "email" => "[email protected]" "email_verified_at" => null "created_at" => "2018-11-17 03:46:59" "updated_at" => "2018-11-17 03:46:59" "admin" => 0 "mod" => 0 ] I have omitted some output here for brevity. Improved artisan Command Laravel 5.8 now has improved artisan commands. Before Laravel 5.8, you could not run two servers in parallel on different ports. For example, suppose you are running your application in Laravel 5.7 on port 8000. At the same time, you want to run your Laravel 5.8 application on another port. With previous versions, Laravel ran the servers on one port, 8000. Laravel 5.8 has the ability to use another port. Let’s see an example. I have a news application in my code/news directory. It runs on Laravel 5.7. I start it, and along with it, I start a new Laravel 5.8 application in the code/ laravel58 directory. The first artisan serve command has normal output like this: //output of Laravel 5.7 php artisan serve command cdss@ss-H81M-S1:~$ cd code/news/ ss@ss-H81M-S1:~/code/news$ php artisan serve Laravel development server started: <http://127.0.0.1:8000> 407 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 [Wed Apr 3 08:22:26 2019] 127.0.0.1:40984 [200]: /css/webmag/css/ bootstrap.min.css [Wed Apr 3 08:22:26 2019] 127.0.0.1:40986 [200]: /css/webmag/css/font-­ awesome.min.css [Wed Apr 3 08:22:26 2019] 127.0.0.1:40988 [200]: /css/webmag/css/style.css [Wed Apr 3 08:22:26 2019] 127.0.0.1:40990 [200]: /css/webmag/js/jquery. min.js [Wed Apr 3 08:22:26 2019] 127.0.0.1:40992 [200]: /css/webmag/js/bootstrap. min.js [Wed Apr 3 08:22:26 2019] 127.0.0.1:40994 [200]: /css/webmag/js/main.js [Wed Apr 3 08:22:26 2019] 127.0.0.1:40996 [200]: /css/webmag/img/logo.png [Wed Apr 3 08:22:27 2019] 127.0.0.1:41004 [200]: /images/entertainment/ rowan-chestnut-175871- unsplash.jpg [Wed Apr 3 08:22:27 2019] 127.0.0.1:41006 [200]: /css/webmag/img/ widget-1.jpg (Code is incomplete for brevity) Next, I run the new Laravel 5.8 application in code/laravel58. Take a look at the output in the terminal to see the difference, as shown here: //output of Laravel 5.8 php artisan serve command ss@ss-H81M-S1:~$ cd code/laravel58 ss@ss-H81M-S1:~/code/laravel58$ php artisan serve Laravel development server started: <http://127.0.0.1:8000> [Wed Apr 3 08:23:31 2019] Failed to listen on 127.0.0.1:8000 (reason: Address already in use) Laravel development server started: <http://127.0.0.1:8001> [Wed Apr 3 08:23:49 2019] 127.0.0.1:44394 [200]: /favicon.ico [Wed Apr 3 08:24:40 2019] 127.0.0.1:44408 [200]: /favicon.ico In the previous code, these two lines are important: [Wed Apr 3 08:23:31 2019] Failed to listen on 127.0.0.1:8000 (reason: Address already in use) Laravel development server started: <http://127.0.0.1:8001> 408 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 Since port 8000 is already in use, Laravel 5.8 is smart enough to start another server on port 8001. According to the new features of Laravel 5.8, it will scan up to port 8002 and try to find a port that is free, as shown in Figure A-6. This is a great advancement because now locally you can run multiple applications at the same time. Figure A-6. Along with two terminals, two browsers running in parallel on two ports There is another improvement in the form of Artisan::call. You use the Artisan::call method when you want to call the method programmatically. In the past, you could pass some options to the command this way: Artisan::call('migrate:install', ['database' => 'laravelpractice']); But with Laravel 5.8, this has changed drastically. Now Laravel imports the console environment and uses flags just like artisan commands in the terminal. Artisan::call('migrate:install –database=laravelpractice'); 409 APPENDIX MORE NEW FEatures in LaRaVEl 5.8 A Few More Additions The following are a few other additions. Renaming the Mail Format Folder You learned about e-mail verification in Chapter 10. The e-mail validation methods have been improved a lot.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages23 Page
-
File Size-