Laravel 5.8 – From The Ground Up - Laravel 5.8 Tutorial From Scratch – e03 – Views

Education, Programming

Laravel 5.8 – From The Ground Up

52 Lessons

Laravel 5.8 Tutorial From Scratch – e03 – Views

welcome back in the previous lesson we added three routes to our level application we added a home route which was already there but we did add a

contact and about route now they each are simply returning the text contact us and about is returning about us so of course the next logical step is being able to add some HTML so this brings us

to our next concept and that is the concept of views views are ultimately your HTML and CSS that gets rendered on the browser so in this route here we see return view welcome so the question is

well how do we make one of these views where is this welcome view being stored and so the answer is in another directory here in resources and then views so in resources views we see this

welcome that blade dot PHP now of course you are familiar with dot PHP but you're not familiar with blade for now just know that blade is a rendering engine that ships with laravel to make your

views a lot cleaner and we'll touch up on a lot of blade but for now just know that any view inside this directory should be called your name dot blade dot PHP so let's make a new one of these

I'm gonna say new and we're gonna call it contact that blade dot PHP and inside of here I'm gonna have an h1 tag contact us a P tag with company name a fake phone number ok so now that we have this

contact that blade that PHP how do we get this view to display when we visit contact so you'll write return view and parenthesis and then we'll write contact so contact pertains to the name of this

file notice that I didn't put that blade dot PHP I simply put contact so return view contact is gonna call contact up blade dot PHP go back to the browser and let's visit

contact and sure enough we are seeing our view contact us and we have our company name and our fake phone number let's do one more I'm gonna save this one as and our other page is called

about so about that blade dot PHP and let's change this to about us I will say company bio here okay back in my routes web dot PHP file we're gonna return view and inside of there we're going to

return the about view let's go back to the browser and visit the about page and sure enough there we are so we have our about Us page and we have our contact page okay so there we are we

can now make views now truthfully this is a lot of syntax for such a simple operation that you need to do all the time so I'm going to show you a slightly different way that you can do this you

can say route colon colon View and then the first thing that goes in there is the first thing that we have here so contact so we'll put that in and then comma the second thing that goes there

is simply the view name so we'll say contact contact and that replaces all of this so we can get rid of that and now for the about page we'll say about meaning the URL about and as a second

argument we're gonna pass the same thing that we would have passed to view so we'll say about and that gets rid of that all together so that much cleaner let's make sure that we're still working

all right so we have our contact page still working let's visit the about page still working so a nice little shortcut here to get your views so again you will write route colon colon view and then as

the first argument it's gonna be pertaining to the URL thar you're gonna respond to so we decided to change that to contact slash us that is still gonna work let's change that to contact – us

and there we are we are still responding with the same view so this first argument again corresponds to this argument here and then the second argument corresponds to the view

so in our case we are looking for a contact double a dot php' which of course we have right here inside our resources directory inside our views directory contact that blade that PHP

and then we have another route about which is calling the about that blade dot PHP also located inside resources views about the blade dot PHP so to finish up let's go ahead and refactor

this route here just to show our single line syntax route colon colon view we're gonna respond to the home page and we're gonna call the welcome view okay and that gets rid of that and so now we have

three lines and three routes let's go ahead and test that to make sure it's still working so remember that one it's just a slash and there we are we're still getting the lair of a welcome page

and with that you can now make views and associate them to routes in laravel keep toying around with this and when you're ready let's move on to the next lesson

Up next, let’s talk about how to add view files and how we can load them into our route. We’ll finish it up by talking about the Route::view shorthand notation.

For the best experience, follow along in our interactive school at https://www.coderstape.com

Resources
Course Source Code
https://github.com/coderstape/laravel-58-from-scratch

Hit us up on Twitter with any questions or comments @codertape (https://twitter.com/CodersTape)

About This Course

Ready to get started on your path to Laravel Artisan? In this series, we are breaking down all of the basics of Laravel to get you comfortable using the world’s most popular PHP framework. Let’s get started!

    add to database laravel admin laravel artisan Artisan Command artisan commend create artisan console artisan laravel command authentication in laravel belongsto belongsto laravel example coding tutorials create artisan command create command artisan create new command artisan Create your own crud laravel crud laravel tutorial crud resource laravel crud with file upload custom artisan commands custom artisan commands laravel custom laravel database configuration laravel database relationship digital ocean dotenv eager loading eager loading in laravel eager loading vs lazy loading laravel eloquent eloquent accessors eloquent mutators eloquent orm feature testing laravel fetching data in laravel filesystem laravel form requests full stack vue gate and policy laravel google optimize hasmany hasmany laravel hasmany laravel example hasmany relationship in laravel hasone hasone relationship in laravel How to create how to queue email how to use queue installing laravel intervention image laravel laravel 5 laravel 5 auth laravel 5.4 queue laravel 5.5 queue laravel 5.8 laravel 5.8 artisan command laravel 5.8 artisan console laravel 5.8 auth tutorial laravel 5.8 authentication laravel 5.8 commands laravel 5.8 crud laravel 5.8 crud example laravel 5.8 custom middleware laravel 5.8 deprecations laravel 5.8 eager loading laravel 5.8 elixir laravel 5.8 event listeners laravel 5.8 events laravel 5.8 feature laravel 5.8 features laravel 5.8 global middleware laravel 5.8 install laravel 5.8 lazy loading laravel 5.8 listeners laravel 5.8 middleware laravel 5.8 multi auth laravel 5.8 named resource routes laravel 5.8 named routes laravel 5.8 new feature laravel 5.8 own artisan command laravel 5.8 queue laravel 5.8 queues laravel 5.8 routing laravel 5.8 telescope laravel 5.8 tutorial laravel 5.8 user auth laravel 5.8 user authentication laravel 5.8 what's new laravel 5.9 laravel admin permissions laravel api laravel artisan command laravel artisan console laravel assets laravel auth laravel auth role laravel authentication laravel authorization laravel axios post example laravel background process laravel background task laravel background worker laravel beginner to master laravel belongsto laravel belongsto vs hasone laravel belongstomany laravel best packages laravel best practices laravel best tutorial laravel bootstrap laravel command laravel command line laravel commands tutorial laravel composer install laravel connect db laravel console command laravel console testing laravel contact form send email laravel controllers laravel create laravel crud laravel crud policy laravel custom command laravel custom middleware laravel database laravel database configuration laravel database relationships laravel database seeder laravel database settings laravel db seed laravel db settings laravel debugging laravel deploy aws laravel deploy digital ocean laravel deploy on digitalocean laravel deploy on server laravel deploy to production laravel deployment laravel digitalocean laravel drag and drop file upload laravel dropzone file upload laravel dropzone image upload laravel e-commerce laravel eager loading laravel eager loading tutorial laravel eager loading with condition laravel elixir laravel eloquent laravel eloquent belongsto laravel eloquent crud laravel eloquent hasmany laravel eloquent where laravel eloquest tutorial laravel events and queue laravel events tutorial laravel factory laravel feature test laravel feature testing laravel fetching data from database laravel file storage laravel fillable example laravel flash message notification laravel for beginners laravel form validation laravel forms laravel forms bootstrap snippets laravel from scratch laravel from the ground up laravel front end laravel frontend tutorial laravel gate and policy tutorial laravel global middleware laravel hasmany laravel hasone laravel i18n laravel installation laravel installation mac laravel intervention image tutorial laravel javascript tutorial laravel jobs queue laravel language laravel language switcher laravel language tutorial laravel languages laravel lazy loading laravel listener event laravel listeners laravel localization laravel login laravel mailable tutorial laravel many to many relationship example laravel markdown email laravel markdown mail laravel mass assignment laravel middleware laravel migrate fresh laravel mix laravel mix 5.8 laravel mix vue laravel model factory tutorial laravel multiple language laravel mysql json laravel named resource routes laravel named routes laravel new features laravel news laravel nginx laravel node modules laravel npm install laravel npm run watch error laravel one to one laravel paginate laravel paginate link laravel pagination laravel pagination 5.8 laravel pagination links laravel pagination tutorial laravel phpunit laravel phpunit testing laravel pivot table example laravel policy laravel preview laravel query optimization laravel queue laravel queue event listener laravel react laravel register user laravel registration laravel registration validation laravel relationships laravel reset password laravel role middleware laravel role permission laravel roles laravel route group middleware laravel routes laravel routing laravel routing with parameters laravel sass laravel save file to database laravel scopes laravel seo tutorial laravel server laravel session data laravel ssl laravel supervisor laravel tailwind css laravel tailwind setup laravel tdd laravel tdd tutorial laravel telescope laravel telescope installation laravel telescope tutorial laravel test driven development laravel test workflow laravel testing laravel testing controllers laravel testing tutorial laravel tools laravel translation laravel tutorial laravel tutorial for beginners laravel ubuntu server laravel ubuntu tutorial laravel unit testing controllers laravel upload file laravel upload image to storage laravel upload multiple files at once laravel upload multiple image to database laravel upload multiple images laravel url slug laravel vue laravel vue js crud laravel vue setup laravel vue tutorial laravel vue.js laravel webpack error laravel webpack tutorial lazy loading lazy loading laravel lazy loading vs eager loading learn laravel learn laravel framework step by step localization in laravel localization laravel many to many laravel mvc tutorial for beginners in php mvc tutorial laravel mysql mysql relational database mysql relationship n + 1 problem n + 1 problem laravel new artisan command npm install npm run dev npm run watch laravel one to many one to one one to one laravel own artisan command pagination pagination bootstrap pagination bootstrap php mysql pagination laravel pagination laravel bootstrap pagination links pagination php php php artisan php carbon immutable php framework php framework 2019 php what's new 2019 phpunit phpunit laravel phpunit testing pivot laravel policy laravel polymorphic relationships queue and events queue email queue for laravel queue jobs queue laravel 5.8 registration form relationship laravel eloquent relationship mysql restful controller role permission in laravel roles laravel route model binding laravel routing in laravel save image to database seo friendly seo friendly content writing seo friendly website seo laravel seo optimization simple pagination laravel slugify sqlite relational database sqlite relationships between tables symfony command console symfony laravel tailwind css tailwind laravel mix telescope laravel tutorial laravel unit testing unit testing laravel upload file laravel upload file php upload image laravel upload image to database php upload images laravel upload multiple files in php url slug laravel url slug php vue vue.js vuejs laravel why use laravel queue why use queue