Laravel 8 Tutorial - Blade Components

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome back to the laravel 8 tutorial in this video we are going to learn about the blade components components provides benefit to section and layouts there are two approaches to creating components first is a class based components and second is anonymous components to create a class based components we have to use the make component artisan command okay so let's create a class component so switch to the command prompt and here let's type command php artisan space make colon complaint this component name okay let's say component name is header this command creates two file okay so first of all and press enter and run the application so just right here php artisan uh sir okay all right let's make a component command will create two files one files created inside the app directory you can see app request and here inside the components directory you can see here the dot php file okay this is the component class file which has render method by default okay this general method and this uh components render method just return the header view all right and second file which is created inside the resources directory then views and here you can see the components directory and inside this you can see here the letters.blade.php okay this is the template file all right now let's write here some text so i'm just going to write here inside the h1 tag just add here this is header component okay now save this file and to display a component we have to use a blade component tag okay so just go inside the blade template file so i'm just going to welcome blade and here inside the body tag just add here the blade complete tag okay blade component tag start with a string x dash okay so just write here tag x dash and component name okay so enter here the component name which is header so just right here here and just close this okay now save this file now let's check so switch to the browser and just refresh this page and you can see here the component header complete and you can see here the message this is the header component okay now let's pass some data to the components okay so for that go to the welcome.blade.php file and here let's add the name and inside this just enter the name let's say third side media okay now save this file and go to the header component class file so just go inside the app use components and just open this header.hp file okay and here let's create a variable so just write here public dollar name okay and inside this constructor just pass here dollar name okay and here just write down that download this arrow name is equal to dollar name okay now save this file and just go inside the header.blade.php file and here just add the tag h3 and let's print this name variable okay so just right here access this name okay so just right here hello and inside the double curly bracket just right here download name okay now save this file and let's check this so switch to the browser and just refresh the page and you can see here hello subside media okay you can also pass the data from the controller so let's see how we can pass data from the controller so first of all let's create a new controller okay so this to the command prompt and here for creating new controllers just type here php artisan make column controller controller name let's say controller name is product controller okay now press enter run the application just write your php artisan okay so press enter now go to the product controller so switch to the project and just just open http and controllers and open this product controller okay and here let's create a function so just write here public function and function name that's the function in this index and inside this uh just create a variable so i'll just write here download this is the variable and create an array so just write here array and pass some element here so just right here mango orange banana okay now just return the view here so just right here return to view and view name view name is welcome so just right here welcome okay this is welcome and here just pass the this area okay so just right here compact and inside okay just copy this variable and paste here without dollar sign now save this file and go to the welcome.blade.hp file and here just add here column roots is equal to just pass here okay now save this file and now go to the header component class file and here let's create another variable just write here public dollar and pass here inside the constructor okay and inside this function just right here all right now save this file and now go to the header.blade.php file and here just add s3 puts okay and just add here well tag so just write your email and inside this uf use the college so just write your query tag inside the ceiling tag double curly bracket and head here download it okay now save this file and now modify the welcome route so just go to the web.php file you just go inside the routes and open web.hp file and just modify this welcome route okay so just remove this this callback function and here just add the controller name product controller so just right here product controller okay and also add here this use app http controllers and sorry this one product controller okay and here just add the column column class comma function name just write it inside the single code function name which is okay so just write here index okay and also provide the name so just write here the name product dot index okay now save this file now let's take this so switch to the browser and just refresh the page and you can see here it's okay so in this way you can create and use blade components laravel it so that's all about black components in laravel 8 so thanks for watching this video and if you still have any kind of question you can ask me in the comment box don't forget to subscribe my channel thanks for watching
Info
Channel: Surfside Media
Views: 22,414
Rating: undefined out of 5
Keywords: How, to, Program, laravel (Software), laravel, laravel v8, laravel 8, laravel project, laravel setting up, laravel v8 setting up, laravel v8.0, v8.0, laravel 8.0, laravel 8 playlist, laravel 8 tutorial, laravel 8 lesson, laravel tutorial, laravel 8.0 tutorial for beginners, laravel for beginners, laravel tutorial for beginners, blade components in laravel, blade components in laravel 8, laravel 8 blade components, laravel8 blade components, blade components in laravel8
Id: nvdwOF40hxA
Channel Id: undefined
Length: 11min 47sec (707 seconds)
Published: Sun Sep 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.