Laravel 10 Full Course in 8 hours using Open AI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this amazing level course which is a seven plus hour of course going to take you from very beginning of what is level how you can set up how you can get started till creating a project using open AI the artificial intelligence to create or generate the avatar for our user and if I get 1000 like for this video I'm going to give away one udemy course and one person will win my in-depth level course which is just the extension of this course so in depth level course and a udemy course so if you want to win the in-depth level course and udemy course just hit like button and comment your views about this course as I told you this course is the only course you will find in the entire internet for learning level from very beginning till the advanced level so the in-depth larval course which is the extension of this course will include three more project for inertia.js Live Wire and test driven development with react and open Ai and chat GPT amazing fun on the in-depth level you can check out the in-depth level.com for this course yes you have to finish this course to start working on other courses I am damn sure that this course will give you the information about each and every important concept of reliable from like what is MVC how is the routing Works how controller Works what are the best practices for the controller what are the best practices for writing level specific codes everything in this video so yes if you want to show some love and if you want to support me just hit like and make sure I will reach or this video will reach 1000 likes very soon and then I will pick some people from this comment section to give the giveaway for the udemy course and one in level course for free so let's see what we are going to create in this course now let's see what we are going to create in this awesome level 10 codes so the first thing I want to tell you is we will going to create a authentication system with GitHub or I can say login with GitHub this process will be done with the help of level socialite package that means we will going to see how we can use the first party or the official level package integrating them in our lateral application and actually do the authentication with GitHub so how this works no need to register the user no need to do anything once I click on login with GitHub it will check if user is already there on the application on GitHub if there then it will automatically do the process otherwise it will ask for the permission so if I click on authorize Savvy then socialite package will first get the email from the GitHub then it will check if there is user available or not if it is available then obviously it gets logged in if not then first user is created into the database and then logged into the application so all these process you will going to learn how to login the user how to create a new user how to encrypt the password everything okay so this is good but you can see now if I once again click on login with GitHub it will not going to ask because we have already authorized the user and user is already available in our database so the only part is to log in the user yeah that's great that's so easy obviously you can see we have a traditional login and register system and we have achieved this by using laravel Breeze package so again one more learning of how to add a package how to implement that and how we can set up the full authentication system you will also going to learn what exactly happening behind the scene of this register form how everything is submitted on the level end in the controller and stored finally into the database so this is all we will do for the authentication part of our level 10 application now once user is logged in we are going to have a profile page and in this profile page I have created a system of user Avatar so with this system you will going to learn how to add a new column into the database how to update the migration how you can actually upload a file into the larval and all these things will make the system of uploading a file for a user so if I click here once again I can choose another file click on save you can see my avatar is now changed this is obviously the traditional choose a file upload it on the laravel end that's it but you can see we have generate Avatar using the AI so we are going to use an amazing package from Luna Maduro the team member of larval and he has created one amazing open AI PHP package we will going to use that and generate the avatar for the user so see this is really amazing so if I click on generate Avatar so it will do something you can see process is happening here and then very soon user will have a new and nice Avatar so see this Avatar is generated by a I obviously does not look that cool so you can generate another one so this way you are going to learn how you can use a new open AI API and implement it how you can write the prompt for an open Ai and generate this Avatar this is the Amazing Power of larval with the AI we are not just sticking to this part we will have another section for creating a ticketing system now what this ticketing system will do first you can create a new ticket by giving the title and description here you can choose any file if you want so suppose I upload my photo and you can click on create once the ticket is created you can click here you can check the attachment like this everything is there you can edit and title up dated all these forms and how we can navigate from one page to another page you will going to learn you can click on delete to delete it but you have seen two amazing button resolve and reject so what are they and how they are useful so for that I will go and create another user or log in another user which I I already have so let's login bitfumes at gmail.com password is password I am logged in I click on support ticket you can see I have created that means this this user bitfumes has created one ticket called my first ticket now the status is resolved so this means any user can create their ticket and that user will going to see the ticket created by himself but this user sarthak Savvy is an admin and admin can see all the tickets so this ticket my first ticket is created by this user bedrooms user and ticket from admin obviously created by admin so you can see if I create a new ticket like new ticket description and here we have so if I now reload like here new ticket is there so if I click and here for the new ticket the status is open and this user doesn't have any permission to close or resolve or reject the ticket but admin has so we will see how we can make some user admin how we can show some of the things just for admin and just for non-admin and how we can click on any button to change the status and you will see if I reload here so it's taking time and now it's reload and resolved because I clicked on the resolved for this button so all these things you will going to learn in this course and this is going to be the real amazing course for level 10 beginner all the code all the source code is available on level 10 for beginners repository and you will find the link in the description everything is available here we are having some kind of structure of ticketing system and this course has a you can say homework or a task for you to work on the replies part of this ticketing system so once you learn the level 10 by having this course after that you need to work on the replies part of this ticketing system and take the screenshot tag me on Twitter or Instagram so that I can understand that you have learned so much many things okay not only this if you are still hungry to learn more about how to create API how to write tests how to use level Livewire how to you can do some of the amazing thing with react with vue.js with open AI more things how to use the tallest tag how to use the inertia how you can deploy your application how you can create the CI CD pipeline everything is available in this in-depth level 2023 course so if you already have this in-depth level you will going to get the full course update for 2023 for free you don't have to worry about that you will get the email that course is launched and this course will be launched in mid or end of the April and if you buy this course right now you will going to get once again free upgrade to this 2023 course and after the launch the price will be increased so it's your time to get this course and make sure you will going to have the best learning of laravel with me with bit fumes so if you get this course right now you will also going to get the 2019 full course which is of 32 hour of course but this is old that's why I'm creating the 2023 course so it's all yours and let's start by learning of larval 10 for beginners foreign is now released and we have to start learning with level 10. if you are new to level then this is the only course you can take so to get started with level first you need to go into this laravel.com and once you will be there you will see something like this now there are two options one is this documentation or this get started both are going to take you to the docs so if you click on get started or documentation you will land on this laravel.com 10x 10x means whatever the 10 point something version so if we are running with 10.02 later on it could be 10.05 but the documentation stays the same because this is the same version now you see when we are here we landed on this installation part we will come back to this very soon but let's get started with the first ever link given here which is called prologue and here we have release information now laravel has a release cycle of one year that means every year it releases new version so next version will be released on 2024 q1 and the number will be variable 11. obviously since larval 10 is now released you can read all these information and understand what actually has added or updated into level 10. so this is how you get into the new version now if you have old version you are using and you want to start upgrading here we are and if you want to contribute to the level it because it's a open source framework you can read it here but as we know we want to get started with learnable so first let's click once again on installation and we get here so the first ever thing you have to do is create new level application using this composer create project command you can also install Global installer for laravel in that case you don't have to do all these things you just say larval new example app but I really like to have the composer create project level laravel and the application let's start so here I am on my terminal and I already have installed composer so let's check the version and it's giving 2.5.4 right now that's okay what about the PHP version I'm using 8.1 so first thing you need to make sure which version of PHP is supported by this version so if we go to the release note here you can see level 10 supports 8.1 and 8.2 so both are already supported so we are good to go with PHP 8.1 if you want 8.2 there is no issue okay so since we have the PHP since we have the composer we can get started by the way if you don't have the composer you can go to the composer and get composer.org this is the website and here you can install the composite but you will say sarthak what is a composer so composer is a dependency manager or you can consider it as a package manager if you are familiar with npm npm is a package manager so npm is for JavaScript for node but for PHP the package manager is called composer so you can get started with this and see how you can set up this composer in your system so every operating system has different installation and you can follow it and once you are done you will get this kind of composer now let's create new project composer create project I will say level slash level and I will call it level 10 for beginners now if I hit enter it will going to create a new directory called level 10 for beginner and then it will start downloading level 10 because this is the first time I'm doing so this is doing like this installing and then getting all the packages it need and very soon we will have our level so yeah you can see it is done but how I verify that it is really completed so what I have to do first I can check how many files I have so here is the one level 10 for beginner this is the one we have created so let's CD into level 10 for beginner like this and now I will use the code or vs code to open this project okay so very soon it will going to start the vs code and here we are let's maximize it and boom you have the first level application but what after this let's go on the documentation and see what it says once you are done with this you can CD into the project which we have already done we have also started on our vs code then it says that run PHP Artisan serve command once you run this command you can go to your browser and visit localhost 8000. let's try to do this so since I am on vs code I can go at the top click on this terminal thing and here is the new terminal click and new terminal will be something like this so now I have to say PHP Artisan serve this is the thing which documentation says I don't know anything so I'm just following the documentation cool let's go and hit enter okay so something happened it says that hey server running on the port given which is localhost 8000. so I can either copy it like this and go here or paste it or we can just press our control if you are on Windows if you are on Mac then press command and click on it so you see whenever I just press command the cursor changes to hand so you will see if I zoom it like this see this is I am pressing the command if I'm not pressing the command you can see it's not converting it to the hand icon so now once we click we can see our amazing lateral application home page is here this means within a few minutes we are up and running the lateral application in our local setup isn't it really amazing and that's why level is so famous so amazing so easy and I am going to make level more easy for you so let's get started with level foreign here and it is running here but I just want to know from where this serve command is coming up so you can see we are using PHP it's a normal PHP thing so if I say PHP hyphen version which give me PHP so we are using PHP to run something called artisan and by the way you can see I'm getting some autocomplete my style of terminal is different if you want to get these kind of things I have actually set up everything on bitfumes website so go there click on free course click on tools and here you will see Mac OS setup so in this Mac OS setup I have given like how to install o my Z shell and writing the highlighter Auto suggestions whim highlight everything for laravel okay so getting back to The Artisan thing from where this Artisan is coming but what if I first hit enter without giving any serve so now you can see here we have lot of artisan command so it first says that you are on laravel 10.0.0 the level 10 version and then it says that we have a lot of amazing commands and over that command we have the we have just familiar with the one command which is called serve and the description of this command says that serve the application on the PHP development server and that's we are seeing here so this is I get that okay when I have to use any command I have to use the PHP Artisan but why this is coming directly on our application why not anywhere else so if I just open that terminal and if I say PHP Artisan it says command not found because on the directory structure if you go you will see a file called Artisan just the Artisan without any extension so if I click here this is the file which is responsible for our commands when I say PHP artisan okay so how I can prove that this is the real file which is responsible for all the commands we are getting here so what if I just rename this file to anything else so RSN like that so file is there but if I now try to once again run the PHP Edition so just I pressed up commands to get the previous ran command so here we are click here and now it says that could not open input file Artisan but what if I say one two three four five six times so one two three four five six and hit enter and you can see we are again getting so this means whatever the name you give to this file will become your Artisan okay so now we have done that but you know writing PHP Artisan every time is a boring and lengthy task so what I did is I have created one and you can call it Alias so if you open the Z shell RC here you will find that from now if I have to write the PHP Artisan I will just write p a for PHP Artisan okay so I can just get out of it by pressing escape shift colon queue and that's how you get out of whim okay so that means if I say PA just to the PHP Artisan short form which I have created it's same as the PHP Artisan so don't get confused from later on if I say p a serve if I do this it's actually running PHP Artisan sir anyways so we get that whenever I say PHP Artisan this file invoke which gives us lot of amazing commands from here which we will going to use very soon and that's how when we say PHP Addison serve we get this home page but my question is from where this page is coming now whenever you have to find from where something is coming get started with the route but for this since I am new to level I even don't know where is the routing thing what I can see is this page and this is the project I can give you a very nice trick to find from where this thing is coming so see we have some text so copy just this text little bit and go to the vs code press Ctrl shift and F this panel curve and just paste whatever you have copied so now from wherever we have this text in any file it will come up here so you can see now we have two kind of file one is something like welcome dot blade dot PHP and other is a storage framework View and some random number so I can give you one important information regarding variable you have this storage file and remember this storage file is one obviously for storing some files but it also responsible for storing caching and temporary files for laravel so this means if I once again press Ctrl shift and F you can see this file is coming storage framework view so I am not interested in any temporary or caching file that means the targeted file which we have to see is this welcome dot blade so if I click here you can see we are actually getting the file but how do I confirm that this is the file which is responsible for all this view let's just change something so here I say welcome to bitfumes if I save this file and go here reload and cool you can see we are having welcome to bitfumes this proves that the file we are here is actually responsible for this view okay now I can undo this and now the next important thing I need to understand is how larval use this file to show here okay so now what we need to see search is welcome dot blade.php so once again press Ctrl shift and F here I say welcome dot blade dot PHP this is the file but we are not getting any result whenever you are not getting any result for this kind of searching then just try to reduce the words you are using now we have welcome and welcome is used in various files but the first file is called web.php and it says return view on view name is welcome seems like this is a route file and where this route file exists it's inside route directory and there is a web.php file so let's first open and see what actually this file is so here is a route file if I click you can see we have one two three and four files but among the four five we are now only focusing on web.php file and here it says that whenever you go to the base route slash means the localhost 8000 or whatever your domain is so whenever you go to the Local Host 8000 like this then it says that there is a function which return a view called welcome now what is the view so any blade file you create so where is the blade file so this blade file is inside resources views welcome dot blade so where is the resources here on this resources then views and welcome dot blade so whenever you want to return the content from the blade file then you use this view Global function this is a global function given by laravel if you hover over it very soon you will get the description or definition of This Global function so this function need the name of view and remember the amazing thing is it doesn't need dot blade.php but how do I ensure that this is the correct thing I am seeing so now I just going to return and call it well not welcome so if I reload now it says that hey there's no view called well now what I can do I can just rename this file from welcome to once again just well okay now well dot blade.php file exist and here we say that whenever you go to the paste URL return a view called well dot blade.php and remember dot blade.php is done or added by laravel because Larry will know that if you are talking about the view that means you are talking about the dot plate dot PHP file okay let's go here reload and once again you can see we are getting this page this means this is the route file which is responsible for anything so let's get back with a welcome and let's get back with the welcome file Here and Now what I'm going to do instead of this view dot blade I'm going to create a new file called home.blade.php and here I will just press shift and exclamation mark this is a vs code thing which is going to auto complete the HTML skeleton once you are done then once again I say welcome to bit fumes save this file and now instead of this welcome file I want to show this home dot plate where we have the welcome dot welcome to bitfumes let's add it into the H1 tag go here and instead of this I say home and once again remember we I'm not saying home dot blade because dot blade.php is automatically added by a variable get back reload and yes you can see welcome to bitfumes is here so we are now 100 sure that application start from this web.php from this route file here whatever we Define will going to be here okay so little quick trick for you so if you just want to return a view level provide a very nice route which is called view route So when you say view you just need to Define as a second parameter just need to define the name of your view file and this is actually similar to this behind the scene lateral is doing the same so now let's go once again and you can see it is still working if you say welcome reload and once again it's working so this is the power of laravel which actually gives you more uh different different way of doing the same thing whatever you like you can do but for now let's get back to this thing I'm going to clean it so that we can see it properly I'm going to remove this home.blade because we don't need get back with welcome and now let's move to larval 10. now before moving into level 10 and understanding some of the important file and directories it is very important to create the git repository for this course so I am first going to do git init so by doing the git in it it initializes git in our application by doing that you can see a lot of things are become green this shows that it is now git is tracking all the file now I need to say hey git add everything so when I say add all it will move everything into the staging once we are done with this then I say git commit with a message and call the messages let's begin so let's do this and you can see now directory is clean everything is now on git but we need to move this into the GitHub and for that I'm going to create a new repository under bit fumes and I call it laravel 10 for beginners okay so I call it level 10 goals for beginners it's a public repository obviously and let's create now once you create it then GitHub says that hey have you done all these things if not you can use all these commands otherwise if you have already existing git repository you can run these three which is just going to push your code into this repository so since we have already done the git add git commit we just need to run these three command which is like git remote add origin so it will just going to Define the remote repository then it will create a branch called main which we already have done and then it will push so let's hit enter and now let's see what's going to happen so very soon all these things will be available on our repository so once this is finished go to github.com reload this page and you can see all of the code which we are working is here now first thing is you can see there is a readme file so to understand the file and directory structure let's start with the readme so readme file is just a file which is going to Define about the project so I will say level 10 course and get this course from wheat films YouTube Channel now once I done with that what I will going to do I'm going to open the new terminal once again if you don't know what is a shortcut you can click here and see this is the shortcut in my case you can check for your shortcut to open a new terminal so once you have done with this then you can see git status is this it says that readme file is now modified so I will say git add all since I need to Stage all the files and then I said git commit instead of let's begin I say updated the readme file once I am I have committed everything then I just need to say get push so git push and wait for a minute or for some few seconds and you can see everything is now synced so now if I reload you can see GitHub is now having the latest version of readme file okay so this is done and you can see the readme file is changed with this commit and it says now cool so whenever you need any help from the code you can just visit this github.com bitfume level 10 for beginners and you will going to get all the source code from this course now let's press command k to just clean this terminal and open the Explorer here you have seen the readme now what about this fight dot config so this is a front-end thing I don't think I need to explain it much this is the real important thing PHP unit dot XML so whenever you write the test in level you write test in PHP unit PHP unit is a framework for PHP test and for that this is the configuration file for the PHP unit so this is only useful when you're writing test now all you already know package.json this is for npm dependencies similar to this we have a composer.json and in this composer.json we are defining what are the packages we need now this is extremely extremely important why because we have two different kind of require requiring the packages now first it says it needs the PHP which is 8.1 then it says it need a guzzle then it says it need a laravel framework oh wait what's that mean I said I am having a level framework or laravel project but then it says that laravel itself need a level framework package what's going on here okay let me explain what actually happening so if you go on level website or documentation if you scroll down you will see this GitHub link so click there and if you open this one if you scroll down you can see there are two public things one is larval larval uh project and then this is a package so this is the project which we required remember composer create project level slash level this is the real thing which we have used but this level project need a framework package so level framework is a package where we have all the level related things or you can say laravel configuration so this is the package which is required by level project so that's why here it is then there is a sanctum there is a Tinker all these are required some are required div now what is mean by required Dev so see when we are creating project we create on our local on our system but when we push our project to server then we don't need the packages or some helper functions which are helpful in writing the code or in creating the project so just like Faker just like paint sale mockery Collision PHP unit level ignition all these package are only available or should only be available on our local so when you run the project on the server you only require these things not these packages but then you will say sarthak hey where is these packages so whenever you have composer and you say composer install and you hit enter then it will read all this composer dot package file then it create a composer lock file which is locking the version so that if you share your project with another people it will not download any other version so basically when you say composer install it will read all these things and then it will install everything in your project inside this vendor file so we just saw that level need a level framework package is it available here let's see so we should have laravel yes and yeah we have the package called level framework cool and remember we also has the paint we also has the sale sanctum and Tinker but along with these packages which are which are available on our composer Json composer Json only have one two three four five six seven eight nine ten eleven twelve packages but here we can see list of all the packages because every package require other packages so all the dependencies packages are also here think about vendor folder as the node module folder in your node application so vendor need everything but what if I delete this directory so I have deleted it how I can get back everything remember just like npm install we have composer install so I say composer install and when I do that you can see it's installing each and every package and their dependency packages in our application and soon we have this vendor directory filled with all the packages or dependencies this project needed so this is how this composer dot Json file is extremely extremely important now there are some more things like auto loading auto loading Dev similar to choir and required auto loading will be available everywhere but Auto load Dev only available on the local or on the testing then some of the scripts you run whenever you create whenever you run composer script then these runs and some of other things which are not that important for now okay so this is composer Artisan we already know kit ignore as the file or the directory which we want to ignore we don't want to push to our GitHub repository this one then we say that it is git ignored so we never push dot EnV we never push the content of storage we never push the vendor so where is the vendor yeah here is the vendor so like that there are a lot of files and folder okay so now we have this dot EnV file it is extremely important file because it hold all the important configuration secret Keys name username all of these things so this is a centralized place for everything suppose you need to connect to your database how you connect you define the database name username password but instead of writing all these things in a file where you have to change for every environment you put everything inside the dot Envy so that when you go on the production you put the production related things on a centralized place called dot Envy file or the environment file okay so that's the file structure and now let's start to understand the larval 10 more you know level is really really powerful framework why because if you have to do something most probably there is a package but for very essential things later will provide some official packages now we already know what is package level actually is build of different different packages it actually combination of different packages so what if I want to have an authentication system like having registration then user login forget password sending email for the password how we can do that all of these things if you are having level then you don't have to worry so let's go to the documentation of level 10. then if you scroll down at the bottom you see packages these are the first party packages or we call it official packages also here you can see the first package is really great called Breeze and since the name is Breeze I sure that using this package is really a breeze so what this level Breeze package will do it gives you full authentication in your application so introducing you the first ever package you can use and how you can install it so to get a new package you need to say composer require D name and on which environment you want to have this package so the documentation suggests that we have to use this package in a required Dev so that's why this is a hyphen hyphen Dev flag so let's just copy this and go open our terminal clean it by pressing command okay and paste it now right now you can see on our required div we don't have level Breeze but let's hit enter and very soon you can see we now have a new dependency added on our project called laravel Breeze and one thing more since we are using the vs code we can see this green bar which represent that there is a change at this line number 19 which is really helpful to understand what has changed okay so since we already installed it let's go to the documentation and see what next now it says that what you need to install so first you need to say after installing the composer you need to run this command called Breeze install now remember we have the Artisan command and remember I have the shortcut PHP Artisan is now PA so if I hit it and see lot of command but since we have installed this package some of the command related to this package will also add it to the list if you scroll down now we have a breeze related commands and only one command available called Breeze colon install so we have to do we have to run this command which is given like here PHP Artisan Breeze install so copy that and paste it now remember I just have two changed file but if I hit Breeze install first it is asking like which stack would you like to install are you going to use front-end with blade file or react view or just creating the API for your Authentication I just go with the blade so either you type the blade or you just type 0. so let's say 0 hit enter that says do you want the dark mode I say yes because I like the dark mode and finally it says would you prefer best test instead of PHP unit we will come back to paste later but for now I will say no okay now it is doing something and that something is coming here so what happened is this package actually export every file in the respective directory for Authentication you can see what first it has the Tailwind configuration so Tailwind CSS is a CSS utility framework then you can see we have a post CSS which is obviously related to Tailwind then since we have front-end things we also have the node module because it has already ran npm install installing node dependencies that's why we have npm then npm node module and since we have run the npm install we have package lock file and if you go here we have the test for all our authentication system authentication test email verification password reset registration profile test everything is here we are not looking into the test right now later we will do that but first let's see what actually this package has done so we just need to see for that we need to go here click on this reload and you can see now we have two new button login and register from where these two buttons are coming previously we didn't have that so we know from where this file is coming this is coming from welcome dot blade which is inside the resources views and welcome and welcome dot blade by default from the initial Point has this code so if it says that if you have the route for login then show all these things which is responsible for this buttons so I can say that login I can turn it to sign in save this reload and you can see now it converted to sign in that means we are damn sure that this is the real file but this file says that I am going to show only if there is a route called login do we really have the route for login and where is all the route routes are available in the route directory if you open this directory you can see there is a web.php which we are familiar but at the bottom we have some other routes there is a route called dashboard this route with some route middleware or group thing and having profile related and at last it require another file called auth.php so where is the author.php it's inside the same directory so here we have auth.php now inside this you will find that there is a grout called login so there's a name for each route which we can use so it says the route has login so here is the name of login what if I converted it to sign in okay and now if I go reload you can see this is gone because we don't have any route naming login but we have sign in if I reload uh it says so something else like this and there is somewhere else we are using yeah this is the one and that's why we are getting error and boom we are back with the login so we understand that all these code are responsible for showing and hiding the buttons and these are all login related or I can say authentication related routes we will not go into deep of each and every route and controller and everything but we just need to see the authentication working right now if I try to register new user let's say sarthak and then sarthak at bitfilms.com password is password password [Music] I will click on register now it says that hey you don't have any database called larval so how do I connect our laravel application to a new database because there is a problem with the database connection remember I told you this EnV file is responsible for all the configuration of your project so from where larval is finding this level database called laravel from dot EnV file so see here is the database called level what if I convert this to sartha the database name is sarthak if I reload you can see it says that hey there is no database called sarthak and this proof that everything is coming from this dot EnV file now I'm going to create a new database called laravel 10. so yes I can do that by creating by going into the my SQL like that but since we are on laravel we don't have to go into MySQL and create the new database what we have to do let's go to the documentation of reliable Breeze next say it says that you need to run PHP Artisan migrate so let's copy this thing paste it and hit enter so since level is smart enough and it says that hey you don't have any database called level 10. would you like to create it wow this is mind blowing level is creating database into the MySQL for me so I say yes if I say yes it not only just create the database it also created some of the tables into it this means if I now go reload the page and you can see it's registered and I am logged in so log out try to log in once again sarthak at betweens.com password is password hit on login I am logged in and this is the dashboard which is coming remember we had some routes dashboard route this is coming from this view called dashboard and we know views are inside resources views dashboard dot plate here is the dashboard and you can say if I type something save this file reload and that's coming here like this okay so we know that how this happened that means when we created the when we ran the PHP Artisan migrate command it created the database it created the tables and when I do the registration it create the user into the table how all these things are happening and what is this migration and how Lara will know that there is a table called user where is the table I have no idea I just asked level to create the database how everything happened isn't it really a magic let's understand this magic so to understand the power of migration or migrate command let's understand what this migrate command do first let's open the terminal and here I will say PHP Artisan first and remember we have one my one command for migration so now we have a command called migrate this command is useful but how do I know what this command do so now I need to say my great PHP Artisan migrate but if I need to know what this command is useful for I can say help by pressing either hyphen help hyphen hyphen help or just hyphen h now here this command says that run the database migrations now what do you mean by running the database migration and what is migration okay so let's open the sidebar and here you can see on our sidebar there is a directory called database inside that we have a directory called migrations and this is the real point my Creations so if you open this migration we have four files which are defined in a very different way first there is a timestamp then there is a name of what this migration do so first migration says that some timestamp create users table second create password reset tokens table so you see a pattern first we have a create then the name and then the table create name table create name table create name and table so create table name and the table dot PHP okay so let's understand first file which is called create users table now what this will do and why it is useful let's first understand by going into the documentation and press Ctrl and forward slash with which is on the left side of shift right shift left of right shift confusing okay so I will press command and and and forward slash and I'm going to write migration now you see the first result is database migration just press down key and hit enter you will be redirected to the migrations documentation here it is given the definition of migration it says that migration are like what is that migration are like Version Control for your database allowing your team to Define and share applications database schema okay so I get it like the migration or the database schema and every migration file is responsible for a single table schema now what is schema so schema is you can understand it like the skeleton of your table so what are the thing we need inside the user's table so in a user's table we need the ID we need a name email verified at password some remember token and what are the time timestamps we don't know but some of the fields we can understand and each name each field name has the field type so name is a string type email is a string type and also it is a unique field so whatever you can Define by writing a MySQL Query to create new users table instead of doing that you define everything here in your migration file and then when you run the PHP my PHP Artisan migrate command then it will read everything from each of the file and then create the database so since we have the database let's open the table Plus and try to connect with level 10. okay so I have already created the connection now you see we have one two three four five five tables and user table is here and the structure of user table is exactly what we have defined in our schema so see first we have ID so yeah we have ID field then we have a name then we have a name field then we have a email email verified email email verified password password remember token yeah we have a remember token then the time stamp is actually created at and updated at so whenever you use the timestamps in level migration this this code actually create two columns called created at and migrated at which are generally handled by user okay so since we have created one user so that's why we have a entry for one user now remember we have more than one migrations so here if you see for every table we have we have a Associated migration user stable password reset token table fail to fail job password personal access token for migration but if I go here I can see five tables so the one table which is extra is the migration stable now what is this migration stable and from where this is coming it's not here migration table is handled by laravel itself so basically it record all of the table it has created so since lateral has created four tables which we have defined here so this table is taking all the record that hey when you first ran the migrate command PHP Addison migrate level created these four tables and this name is exactly same the file name so this means once you create the migration you never have to touch it okay so it's not like once you run the migration you can change it hey I need the name to be like username no you cannot do that so how do I update the field so what we have to do we have to create a new migration how do I create a new migration so there is very simple command for that once again go to the PHP Artisan scroll down to the migrations and we we have make migration actually so there's that yeah make migration command create new migration file okay so PHP artisan make migration migration and now similar to this pattern I'm not creating any any table I'm just updating the table so I say update user table add I can say not adding update user table name to user name that's it so there is one more thing if I get help you can see we can Define which table I am going to change so if I am not giving anything you will see it has created one migration and this is the latest migration and it has prefixed the timestamp if I open this file you will see that this schema is empty and it says that there is a table called username but we don't have a username table we have a table called users so let's just delete this file open the terminal and this time I will say that hey that table is users okay now this is done once again try to see the migration and this time you can see there's a correct table name and since we want to update this table what we have to do we have to Simply say uh like here and I say table then I say rename column and from name to user name okay so this is this is the only thing you have to do but remember whenever you do something for up you have to do the reverse on that down so rename from username to name because what if you you want to roll back then this will be the useful code okay now see the difference between this table this migration and this migration the only subtle difference you can see is schema create here is a schema table because we have not used it to create new table we just want to update users table and that's that's the difference between create and update okay how do I run this migration remember we always need to run the migration okay we always need to run the Migration by using PHP Artisan migrate command and remember one more thing that batch one that means the first successful migration had these migrations but now this is a next migration and since I have a migration file which is not listed in this migration stable that's why it ran the migration and now if I reload you can see this is the new file which is on the batch 2 and now if I go to the users table you can see the column is now changed to user name isn't it really amazing exactly this is how the migration works and this is how everything is there so for now I just undo this thing all the migration I don't want to rename it so I just delete the entry from here I just rename this column once again to name instead of username so that we will be on the same place where the level is and this is how you understand you create you update the table using the migrations and this is how you connect with your table but still one thing is remaining I created the user by using this register form so what actually happened behind the scene when we filled this form and clicked on the register button let's understand all these concept now to understand actually how this form is filled we first need to find this form to find this form we have to go here on our resources views and here we have auth and then we have this register dot blade dot PHP and now if you don't know where you have to go you can search some of the keyword like I always told you just press Ctrl shift n f or command shift n f if you are on Mac write it and then you will see lot of files but here is our register okay so we got that we have this file and to make sure this is the right file I can just write something and then go reload and yeah something is here okay so first we need to see what happens when we click on this register button so if I go and find the register button here is the button called register and this is not a normal text it is using this double curly braces and then underscore underscore and then inside that we have register so this is actually the localization feature of level we will come back it later but for now consider it as the word register simple okay so if you do that and yeah so it's same okay so let's get back here and since this is a button and this is actually going to submit a form and where's the form so at the top you can see this is the form which is having this post request and there is a route called register now whenever you use double curly braces here that means you are trying to do something PHP or level related thing inside this double curly braces so these are double curly braces spatial Syntax for blade files okay now here we have a route Global function and inside that we have given the name of the route right now if I go to our auth drought which we can find from here routes Earth you will find there is a route with a name of register but wait this is a get request we are looking for post request so is there any post request with the same name hmm so so here is this post request and this is actually scene route so that's why the name will also be exactly same now you will say that sarthak this is also register this is also register yes so with the different type of request we provide we can differentiate between the two route with the same URL so here is the URL for slash register here is also URL for slash register but since we are using different method of hitting this routes we will consider these two route as different but since we are adding the name to this route where we have the URL called slash register this will also applied to this post request because the URL is exactly same so what if I say register not ter and here also first I need to submit this form and you can see now it says that register is not defined so if I just do like this and reload and yes you can see it is there oops okay so yes it will going to work surely now it has this password validation fields we will check about this how this is coming but first let's understand what happened when we go on the post request of this route so let's just undo things here we have this register user controller but where is this register user controller this registry user controller is inside app HTTP controller auth register user controller okay now you will say sarthak what is controller we will get back to it from the next episode when we start the MVC pattern right now just think about it as a file which is responsible for doing something so here we have register user controller and we found it inside that we are looking for a function called store okay so where's the store here is the store and all these things are responsible for registering a user I think this is not a good time to explain you each and everything because it is little Advance we are going to learn it very very soon so this is how our laravel works behind the scene when we click on register button to submit this form similar thing happened with the login so login also have a button which is going to submit the Swarm and I am damn sure that there will be a route which is we are going to hit through the login page so let's go to the login.blade and yes you can see there is a post method for login route so there has to be a route called log in so let's go on the routes auth.php and yeah you can see similar to register we have a login route but on the get so there has to be exactly same URL slash login for the post and yeah we are here and we can directly go to this controller by pressing Ctrl and click or if you are on Mac then you have to press command and then click and yes you can see we are here so click there and then we land it here so it will be on the store method so here we have the store method and this is the code once again responsible for login okay so we understand that how this laravel form actually works but we are not happy with this because we need to understand the real MVC pattern of laravel you know level is actually based on the MVC pattern now what is MVC pattern and how this MVC pattern is useful and why we need to understand about it so let's first open any file so let's open this one an image actually and I will open this one to new tab and here we are so this file or this image explains MVC pattern so first what is the full form of MPC so it's very simple m stands for model v stands for view C stands for controller so I believe two of these things are familiar with us why because we know what is View where these are situated so let's start with the view view is the UI part user interface part or I can say the HTML part which represents the current model State basically here whatever the blade file you define is considered as The View this means when you create a new blade file that blade file is actually the view of your MBC pattern then comes the controller and controller seems as a brain of your system which control and decide how and where data will be flowed or data will be displayed and we also have a little knowledge of controller so controller sits inside app HTTP controller and all the controller of our application we will put inside of this controllers directory now right now since we have installed the laravel breeze package we have this profile controller some of the auth related controllers so click on profile controller and see every controller must extend the base controller now where is this base controller it is here so it's very simple and this is the controller which actually represents the real base controller from laravel okay so this controller actually decide what's going to happen where will be the data flow basically all the controls and the data flow will be decided by the controller so that's why the name is controller it controls the data flow so here the data will flow from this controller to this view so here this returns a view but inside that we are passing the user information now what about the update update just going to validate it and then if it is empty then making email verified at null otherwise save and redirect so very few things controller do and make sure always controller has to be very lean minimal and very very short controller should not include any logic of your application okay so that's done now comes the new thing which we have never touched it is called model now what is model and why it is extremely useful so we know that we display the data on view on the HTML file we get the data from the controller we tell controller hey the controller I need some data controller will provide but from where controller will get the data and if just just for just out of this MVC think about this where will be the data stored data will be stored in database now how we will interact with the database here is the thing models here is the model which interact with the database now remember we understand that there is a migration file for each of the table inside our database now this file is responsible for creating or defining the structure of database now Suppose there is a file which will only going to be responsible for all the crud related part like reading updating storing and what's that deleting the data from the database so that's why we have app model and user model right now so if we have the user model this model is responsible for doing all the crud part doing all the queries in the MySQL user stable and that's why the name of this model is user and that's how this user model is responsible for getting the data storing the data deleting or reading the data that means all the correct part related to the users table will be responsible by this user model now it seems like yet another PHP class but how we will make new model if any class extends not this one let's open this in a new file so I was saying that if any class extends model this model file or model class of laravel then that class will become the model so it is confusing let's now try to create a new model let's say I'm going to create a model called book dot PHP now so let's start with the PHP tag PHP then name space namespace is app then we have models and then we say class book X tens model now if I do this the extend model then this book dot PHP file will be considered as the model of MVC pattern this means this book model is directly going to interact with the books table by default now how do I know that this is going to interact with the books model so that will provide this convention that whatever is the name of the model the plural form will be the table but you can explicitly Define that hey my table name is going to be not books it's like my books so this should be my table name and from now whenever you use book model it will not going to interact or not going to fetch data from the books table it will use the my books table name so this is just an example I have given to you so I'm going to delete it and let's now once again focus on MVC pattern so MVC pattern states that whenever you need to read something you you are not going to directly tell to the model that hey user model I need some users you first get the data from controller you tell to the controller that hey controller I need some data now it's controller's responsibility from where it will get the data and then pass back to the view so now let's understand how we can use the model to fetch the data in three different ways foreign but it's very important to understand like how we can actually run a raw SQL query we don't want to do fancy stuffs what if I just want to run a normal SQL query for that I'll take you to this section of database so if I click here you can see we have this getting started now when you do the get started it will tell you like how you can connect the database how you can Define the database like username Fields all of these things but now we have a very nice thing called Running SQL queries so how do we run a SQL query inside the level we have to use a DB facade so consider DB facade is like a class which is going to interact with your database and how do we write the query you need to just do something like this DB select okay so if I have to fetch all the users from the database how do I do that and to show that thing I will take you to web.php file and this is the welcome page which is this one but now I'm going to comment it and I will introduce you with the DD thing which is a dump and die so first it's going to dump and going to kill the code at that point so what if I say sarthak if I save it go here reload you can see it is having sarthak and the best part is it is it is telling you like where this DD is so it's inside the routes web.php at line number 19. okay so we will use this but first I need to fetch all users how do I do that so I say users is equal to we know we have to use the DB facade and make sure it is imported and make sure it is facade slash DB then after that let me Zoom this for you after that I have to say select so inside this as a string I will run my query so I say select everything from users okay so now we have the users all the users will be stored inside this user's array and I'm going to now dump this users here and for that I will now reload this page and you can see I have one array of users and each array include the user detail all the table information is now printed here so this is the power of the DB facade running SQL queries but this is just for selecting what if I want to select a user by id1 so how do I say so it's like very easy select everything from user where ID is equal to 1 is this going to work let's see it's working but what if you have to select with the email field so where email is sarthaket bitfims.com now at this point it is giving error why there is a error because it's it can't actually differentiate between this as the part of the query or as the value for this email field so can we do that like this with the backticks still it's not working it is considering it as a column so what what we have to do we just need to say question mark here and as a second parameter we need to pass whatever the bindings we need so first binding is question mark replaced by this email field so now if I go reload you can see we are getting the data back because we are using the bindings and now laravel is not get confused with the email as the column name okay so we get the user so we can get back like all the users like here okay now it's time to create new user create new user how do we create new user so we have to say once again DB but this time we need to go to the documentation to see how we can insert so here is the running insert statement you need to use once again the insert you can say function and then run the query and similar to previous state we have to use the question mark whenever we pass some bindings or the values okay so it's going to be very easy we have to say insert and inserting inside the users table so insert users into users insert into users now what we have to do we have to define the field name so inserting the name email password now this is good but what are the values you know value we have to pass as question mark column comma question mark comma question mark because as a second parameter we are going to Define all these three things so first is sarthak second is sarthak at bitfumes.com and third one is password okay so you see we are doing something like this is it perfect seems like perfect but you said that you may have this question like why only these three Fields why not all other field like ID created at updated at so if I open the migration for user see ID is auto generated so we don't have to give ID name field we have to provide it email field we also have to provide it email verified at field is nullable so it can be null so we don't have to provide password we need to provide and these two will will also be taken care by laravel okay so now we have this and let's now see what we will get when we insert a user so click and now it says that user email unique so email I have to change so like this okay and it says true congratulations you have inserted First Data into the database now I will comment and fetch all the users from the database and now see we have two user and fun one is the old one and this is the new one with this ID email ID of sarthak1 bitfilms.com cool so this is really great now we have done the create part how do we update the user so we need to use use the update user so once again this has to be related to DB and I can just think about that if I have to select I said select if I have to insert I said insert what about update do we have the update yes we have it so now this become very easy because we get the pattern we have so we can simply say update users and here we need to Define what we have to update so let's go on the documentation and here we have the update statement it says update users set field name value and then the where field okay so we say update users set email as ABC at bitfumes.com where ID is equal to okay this is outside like this where ID is equal to 2 okay so let's verify that we have the id2 ID3 actually okay so ID three let's make it ID three Okay so this should also return true if everything is fine like this but we know we will going to get so we are getting 1 wow that's great now if I comment and fetch and see all the users second user is having ABC at bitfilms.com you will see here that we didn't have to do anything for the bindings but if you want you can do that so suppose you have to do select this question mark and here also you can say question mark as a second parameter you can provide first as the email ID so back with sarthak one and ID is three so let's just log only the response of this statement and it says one very nice so let's comment and fetch all the users and here we see that now it's back with a startup one at bitcoins.com very very nice okay so just we have done with the update a user we need to do similar with the delete uh user okay and I can just uh think about this and say that hey I just need to delete see level is that amazing if you know one thing then you can predict what you can do for the next day and that's why the readability and the user or developers easiness is the key point of level so when I said select DB select then I instantly got that hey if I have to insert it will be DB insert if I have to update it will be DB update and if I have to delete it has to be DB delete so I say delete from users where ID is equal to 3 and all these things will be as a string now obviously if you want you can do the bindings and now let's try this reload and it says one that means I can comment it and get all the users so we should get only one user which is here wow so amazing we saw that just by using this DB facade or select insert update or delete methods we can do all the correct part and this is running raw SQL query but you can see that every time we have to define the user table like here inside this statement and the where condition we have to Define should also be inside this and there is no problem with this but in my opinion this is not that handy and this is not that powerful so that's why laravel has another amazing thing which is called query Builder so once you are done with this once you understand all these things then you can go to the next part of our level database documentation which is query Builder okay now let's do all the this all this crud part with the query Builder and how we can perform the crud so let's now use the query Builder to do all the crud similar to this okay so for that we have this documentation which says that now this time instead of directly saying what you are going to run like insert update delete or select you first Define the table and then you can use some of the built in functions which will be very handy and easy to write so first when you have to get all the user from the database you use get command after this table defining the table on the DB facade so let's do that I have to fetch all the user so instead of this select I say DB then defining the table which is users and then I say hey I need to get all the users obviously we have the diadem for this let's go reload and see we are getting here all the user which we have in our database but there is one thing to notice this is actually not a simple array it's a collection of array now collection is a level specific thing which is having more power than a simple array consider as the bunch of different different array which is the collection of an array where you can perform various tasks okay so this is how you get a user but what if you want to get a user with a wear condition so you don't have to say where because we are not writing a raw query so there is a nice wear function available so we say where so first you have to Define what you need to do and at last you say get so what is the wear condition where ID is uh let's say one okay now if I go and see you can see still we are getting the same result because we only have the one user but the wear condition is working this is the power and how do I know that there is aware Condition it's given here the where or you can go to the collection documentation and here you can find the collections we have yeah so you can see all the collections we have now here we have the WHERE condition like this one we have a lot more amazing collection features collection methods available here so you can try and see all of them so now let's see what we can do with the insert how we can insert so let's go at the top here you can see we have the insert statement we had the inserted statement we can say DB table insert in the data and the array of the data so here let's comment this one or actually we need this so we are going to fetch all the users so I can remove the wear condition and now to create new user using the DB facade I can simply say user DB colon colon table and the table is users and now I say insert and here I am going to define a proper array of the field and the value so name is sarthak then comes the email is sarthak at withfilms.com and then the password is going to be the password like this okay so this is done so let's see what we are getting in the response so here we are creating it's storing the response and the diagram the response go to here reload and this time it says duplicate entry okay once again the duplicate entry so I can say one at betweens.com and boom we're getting true so if I try to fetch all the users like this and yeah we are now this time getting two users as we know it's very simple so if we have the inserted statement we should also have the update statement and you guessed it right you need to use the table and then update and whatever field you want to update so easy and I can just write it very very quickly so that you don't have to be like understand and making your time valuable so I say hey I need the email to be ABC at bitfilms.com but where if I do this it will change for every user I need to First Define the where condition where ID is what is the ID let's see ID is five ID is 5 then update this okay let's once again get what we are getting as a response one we are getting now if we are getting 1 then we can easily check for all the users and yes the second user is now having ABC at bitfilms.com cool and I think you guessed it right how about deleting a user so it's not a big deal now because we are becoming Pro on this so instead of where condition of update we can finally say delete and we don't have to Define anything inside the delete because we just need to fetch the user with the id5 and do the delete part there so delete 1 that means we can get back fetch all the users and now we are getting only one user okay so you will say that so the there is no big difference in between using the DB facade normal query and using the query Builder it's just having some functions what is the real power of using the query Builder so to understand the real power of query Builder you need to see this documentation where it is given that yes you can do the fetch part but what if you want to get the first user from the collection from the different users we have so instead of doing this I can say hey give me the first first user so if I reload you can see I'm now having a simple object of the user and this is the first user I get from The Collection or from all the users I have this is very very handy what next you can also fetch some of the value instead of selecting in all you can say select email so yes you can do that in a different way but it's really useful and very handy now suppose you want to say where user is uh like this I can say hey where ID ID is one I need to fetch the user where ID is one okay so how do we do this it's very easy we did that and we are getting it but with the query Builder you have very nice function which is called find with ID of one that's so amazing so clean that you don't have to write two different different methods like where then defining the field the value and then getting the first so clean this is the real power of using the query Builder it's not just like that you can do the pluck that means you can just get the title and then there are chunking system you can have thousands field in your database but you can get the first 100 work on that something and then get the first next hundred and next hundred and that will actually reduce the load on your database and on your PHP memory so these are the things which are really useful and that's why I consider query Builder more powerful than the raw query obviously you can do all these things in the Raw query actually behind the scene obviously these methods are doing the raw query but you don't have to worry about writing the raw query and even if you know the raw query you can see that it's really difficult to write the raw query instead of doing or having this autocomplete features like this so if I say hey I have this I can do the first hit enter and auto completed so these are the benefit of using the query Builder over the raw queries now this is the time to really look into the amazing feature of laravel which is called eloquent and now let's get started with eloquent and C how actually you can use the model to do all the crud part in your laravel application using eloquent is a breeze is really a soothing experience why I am saying this first of all you need to understand what eloquent is so level includes eloquent and object relational mapper that makes it enjoyable to interact with your database and that's I told you when using eloquent each database table corresponding model remember I told you about the model user this user model is only going to interact with a single table called users so that's written here each database table has a corresponding model that interact with the table in addition to retrieving the record of the database eloquent model allow you to do all the crud part okay so we get how we can do that but now let's see how we can perform all the grid with the user model but why we need the user model if we have the DB facade to run the raw query and a very powerful DB query now see here we are doing this DB then defining the table again we can reduce all of these things just by saying right now we can remove it and we say that hey just use the user model and like this just by using this user model happened here I have to import it yeah so just by using this user model we are skipping this part also and all of these things will still remain the same because behind the scene the query Builder things are still valid for our model for our eloquent model now we can see that yes we are getting the model all of these things are here so we can see we have the user where ID is one and first we are not just getting uh the user details which is here inside the original and attributes we are also getting lot of amazing data related to our database related to our data modeling related to the table and more other things okay so now you will see that here we can fetch all the users how we can create a new user what you have to do it's very very simple so user is here and I can do like here so user is equal to user model and then we just need to say hey create user model create new user and I can copy all these data paste it here and then I can save this and say that sarthak one is there and the power you will feel when I just return the DD so once you create the user you get the response in the user array variable and then here user variable is di dump now let's see what's going to happen see we are getting new user but instead of getting either true or false query is successful or not we are getting the newly created user in the response this is really useful because obviously when we have created the new user we need that user so this is how you create new user isn't it isn't it really really amazing and yeah that's the power of eloquent models okay so similar to this I'm going to this time update the user so I say user where ID and ID is obviously six I believe and ID is six yes so I need to update the email previously we know how to do that so it's very easy I can just copy once again like this and ABC okay so let's once again go reload and this time we are getting zero that's not the case why because whenever you do the user update you obviously need the user first so we can do something like this user is equal to user where this or give me the first one and then we can say that hey the user need to be updated like this okay so let's once again run this query and it says update on null it has to be six actually so reload and you can see it is ABC at bitfilms.com but what if I can say find remember we also have one amazing method called find and this is also going to work easily yeah so that's good so we can get back the user with sarthak1 and see if we are getting the result and yes you can see we are getting the updated version of the user so first we get the user we update it as soon as we update it it has also updated the user variable and we dyed up we get the user cool this is so amazing and finally it's time to delete the user and to delete the user we are going to do the same thing first we fetch the user from the database and then we say user delete and now and now you can also do delete here like this but I like to have something in a different line to make things clear okay what's going to happen when I do this it says that hey this is the user you have deleted and to confirm that this user is deleted I will try to log or die dump all the users so we only have one user so that's why we just have user with the ID of one cool now we understand that how we can do the correct part with the eloquent model but still I am not convinced that why I should always use the eloquent model instead of query Builder or DB facade yeah with a query Builder we get this where and first that's same with the user model what is the power of user model now the power comes when you understand the eloquent more so how do we understand the eloquent more eloquent models are not only just to fetch or do the crud part from the database it has also connection with the factory with a seed with the controller with the policy and pivot and lot more things obviously you are not aware of these things so don't worry about this but consider the model as the powerful thing which can connect with a different part of laravel with very ease so that is the real thing now every model is a basically is a class okay so when we say this is a class that means we can Define different things and do the powerful queries so as I told you we can Define the table name here inside this so if I change the user model table so I can Define the table and change the table name easily I can also change the primary key I can say that hey not do not use the ID as the primary key use the maybe the email field as the primary key it could be anything for you you can also disable the auto increment of the ID like whenever we create a new user it will give the next ID as the first as the incremented one so you can just disable that so these are the powerful things which you can have when you use the eloquent model to interact with your database okay so remember I also told you the timestamp thing so whenever you create a new database using the query Builder or with the eloquent you this created it and updated ad will be Auto filled by laravel you don't have to Define that but with the query Builder what if you want to disable you don't want to fill this by laravel you want to do something on your own you cannot do that with the query Builder but yes with the elegant model you can disable the timestamp the created at and updated ad filled by level you can disable that hey I will take care of that to create it at and updated it do not fill the current time there so yes you have more power with the eloquent model okay so these are the things which you have to make sure so that you can be pro at the at the eloquent models or eloquent orm inside the larval but you know I want to show you more amazing thing more powerful thing for level with the eloquent so you can see there is amazing feature called all just like we get we get the user like saying user uh get so is this going to work so let's see yes it is working we have the one user we are getting it but we can also do the all when I say all that means I'm getting all the user and I don't want to do any wear condition I don't want to do any other thing just give me all of the database for the users table we can do that so these are the things you have to understand and now let's start the real power of eloquent now we have to understand more about the power of eloquent models right now I have deleted all the users from the database let's try to create them one by one using three different methods we have so one is this one where sarthak one second is query Builder I can say sarthak 2 and third is going to be the user model with 3 as the emails okay and then I will reload it it has done something and then I'm going to comment everything and then fetch the users and see we have three different users very good now if I open the first one and see that the password is just a plain text password it should be encrypted one this is obviously with the raw SQL query so we don't have any expectation what about the query Builder if I do that query Builder is having the plain text this is not expected with this what about the user model user model still is not encrypting the password so how do we make sure that whenever you use the model the eloquent model you can encrypt the password so there is one thing is we can just do this we can say hey the fourth one and we have to use a very nice function or a global function called decrypt B Crypt okay so this is a function given by laravel which actually hash the value or the string we provide and convert it into a hashed password now let's try to do this and see what's going to happen reload then comment it and once again check the latest one and this time you can see the password is actually encrypted but this is all good but we don't want every time to decrypt the password like this what I want is if user is giving just the plain text then automatically it will be decrypted or hashed into the database for that the power of eloquent user model will come so how we can use this elegant model to do this automation thing we call it mutation now if we go on the database documentation of laravel go inside the eloquent orm we have this mutator slash casts so we are interested in the mutated mutation so if you scroll down you can see that there is a mutation thing so how we create a mutation you have to create a protected function with the same name as the field name and then the set part is the mutation the get part is the accessor we will talk about this accessor very soon but for now we just need the set part so how do we work on this for our password thing go to the user model at the bottom create a protected function and I'm going to call this function as pass word obviously this function has to return attribute so you have to type in it then you need to return attribute and here then make inside that as we know we have to create a set and using the arrow function we get the value now what we need to do with this value we always need to do the decrypt for this value that's it so we have successfully created one mutator this means whenever we use the eloquent model to create a new user the password will automatically be decrypted and then stored into the database so let's try to create another user like this one and I'm going to actually use the user model and say sarthak 5 or maybe 6 and I need to do the user here and try so you can see we have the user but this time password is encrypted although we are not using decrypt here the password is still encrypted I just want to make sure this is working so I just comment this one and change the email field and try to create another user once again and see what's going to happen and see the password is not encrypted this means this function is really responsible for first decrypting the password or hashing the password and then storing into the database so this is the power of our mutator and power of the eloquent user model now next is the accessor so accessor is just the reverse of a mutator so what mutator do mutator first change the field and then store it into the database accessor is reverse accessor will first get the field and then change something okay so what I'm going to do I'm going to fetch a single user so here let's say I want to get a user with the ID of what's the id 17 okay so let's use the ID 17 this is the user we have so call it user not users so we have the user reload and now what about I want to get the name so right now if I see here the name field is as it is which is inside the database but what if I want to upper case all the user name so how do we do that similar to mutator we need to create one get field here which is called accessor so it's going to be super easy here I go and instead of password I create another protected function but this time the name is the name field because we are going to interested in the getter or in the accessor of name field so now change it to get and I just want to say Str to Upper okay so this is going to make things uppercase when you fetch the field not just directly from the database but first we get from the database and then you call for single field okay so let's go reload and boom you can see it is all uppercased isn't it really amazing to have the accessor and the mutator inside our laravel eloquent and that's the power of electment one more bonus tip is here since level is making life of developers easy it can also provide the SDR class so you have to import it at the top you say use Str and it should always be from the illuminate support Str and once you do that you say colon colon upper this is the same thing doing str2 upper with str2per is the core PHP thing stron upper this Str class is very useful given by larval and that is the same thing okay now if you want to learn more about the Str thing so just search for Str and colon colon upper and here we are the helpers are here and there are a lot more amazing helpers available here if I scroll up at the top you can see array helpers are there but we have created we have used a string helper so string helpers are here which is like this okay so I think you got the point like how we can use the accessor how we can use the mutator and what is the difference between accessor and mu data okay so that's really cool let's move to the next topic foreign so now let's understand some of the configurations of larval but before that let's get back our home or welcome page you can see so first I need to open the web.php file and what I'm going to do I'm going to remove everything by the way if you need these things you need to go to the uh to the git repository and you will get everything so return view of welcome okay once this is done then you can see we are here so zoom out that's great so I told you I am going to explain you some configurations here so configurations always start from dot Envy file each of these entry in this dot EnV file has corresponding configuration in lateral but where let's take an example of DB the database so database configuration where should be we go to where these informations will be connected to level so we are talking about the configuration and there is a directory called config if you open this directory we have a lot of files but we are interested in some database related and exactly we have a database.php file so let's click here and you can see if you scroll down there is a default connection for the database and the default connection is not hard coded is actually coming from the EnV file so this EnV is a global function which actually read the information of dot EnV file and from that it will fetch the value for DB connection so DB connection is MySQL but what about this second parameter so second parameter is the default one so if there is no value available for DB Connection in our DOT EnV file then the value of default will be the second parameter which is MySQL in this case let's take another example so we have my SQL related more information like username host Port password Etc and you can see everything is coming from dot EnV file so these things are exactly which is written here and as I told you like here uh if DB username is not given then it will use the forge as by default one okay so this is how we get the information from dot EnV into our configuration file and similar to database we have lot more information let's take an example of app.php app.php is responsible for the application related configurations like the application name which is again coming from the dot EnV file and here we are so if you change here that will be affected in your application then environment which environment you are working so if you are not giving anything it will be production so like that you can see lot of information are already available here now this is good that we have all of these configurations available in this file but all these files are reading configuration mostly from the dot EnV file and reading file is an expensive task and it's not good to read the dot Envy file again and again so what level does if you go on the bootstrap directory you can see there is a cache directory and in the cache directory we have a packages and services so this is the PHP file which is more easy or less expensive to read by PHP and this is why we are having all the packages information here all the services information here but how about reading all the configuration putting all the configuration into one file inside this caching which we call configuration caching in laravel how do we do that so if you open the terminal if you click here it will open the new terminal and let's open PHP artisan and see how many commands we have now if you scroll up at the top you will find we have some configuration related commands and very useful command is config cache which says that create a cache file for faster configuration loading so what if we run this command so we say PHP Edition config cache if I run this command instantly you can see we have a config.php file in our bootstrap cache directory now let's open this file and see what we have inside it okay so I can see that it's actually returning a simple array but this array is huge how this array is reading all of these config files one by one and putting the information in this file so right now first it is start with app so now we have app related information then we have auth so once we end up with that we should start with auth yeah we have this then broadcasting broadcasting and similar to that we have all the information from the config directory into this single file now how about changing something right now all the information from dot EnV file is available inside this so when I say the name of the application is laravel but what if we say it's with fumes of course this is the name of the application now but if I see here config it is still have this name so what we have to do whenever we change something in dot EnV we have to run this config cache once again but this time it says Hey environment file is wrong because you have a space so you need to use double quotes here so let's start once again and say config caches and this time it is recreating the cache file which is the config.php inside the caching directory and this time you can see it's having bit fumes course but what if you don't want to have this caching file what you can do yes you can manually delete it from here but there is another command for it so once again if you see the Artisan command for configurations you will find another amazing command which is called where is that here config clear remove the configuration file so we can obviously run config clear and you will see that this file will be deleted when you run this command so what is the purpose of this command so generally you don't want to remove this in production but in local you are often changing the value of dot EnV file so it is either recommended that you don't cache your configurations in local or in development or if you want you can run that command to delete it so this is the power of caching and this is how you read the information from dot EnV and put it on the configuration and finally on the caching let us start with something cool so we have a user here so we know we can actually get the user by logging into it like this using the email and the password so right now it says that it doesn't have the the user but if you don't have you can register what if I want to give the functionality to upload the user image or avatar for a user so let's now start by registering a user so when I say register I will use these information password hit register and you can see I am logged in now since I'm logged in I can go to the profile but in the profile I don't have any way to upload my avatar so let's start working on this first we need to have a column in the user table to have the image information right now if I scroll if I go on the database we don't have any column called Avatar so how do we add a new column remember we need to create a new migration we cannot use this migration because these migrations are already ran so these are not useful now so we have to create by using PHP artisan make migration and I can say update user table add Avatar field once again this is the name it's up to you how you want to give and obviously the table name is users and make sure it's a plural form of the model it's not model it's the table name so let's hit enter and very soon a new migration is here which is this one okay so now click here and you can see it has the migration which is having this schema so it says that we need to add a column so I can say table add column in the column type is going to be string column name is going to be Avatar and if there is any parameter but this is a normal way you can also just Define in a in a way which is more of the older migration type so whenever you go you define something like this so this is not creating a table this is updating table so obviously it will going to work so a string field and name is Avatar but what if I want to add this Avatar field after the email or maybe before the created ad so you can Define where this column should be added so you can say either after or you can Define before like that so let's have the after effect and now I say email so this should be Avatar after the email but remember we are saying nothing about if this is nullable or not so if I'm trying to run this the existing data we have in our database doesn't know about the column which is coming so what should be the value of avatar for older data that's a problem and this is why we need to make sure that this is a nullable field when you add the label field then for the older data it will be always null the Avatar field will always be null and it will not give any error in the migration when you add this Avatar field but as I told you remember always you need to take care about the drop so I say drop column and the column name is Avatar great so here I'm adding the column here I'm removing the column everything is set Avatar field after email null label everything is good now let's open the terminal and we need to run the migrate command so PHP artson migrate just by doing this if I hit enter you can see it ran a new migration only and now if I go scroll zoom up reload you will see that after email we have another field called Avatar which is null all null and it's given here also text field string field and it's yes nullable okay and on the migrations we should have another entry for batch 2 this is a second successful migration so here we have on the batch 2 we ran we created this migration okay so now everything is good we have the field in the user table so how to add a new data in the Avatar field I will go and introduce you with a new thing called tinker and what is Tinker so once again run the PHP artisan and here if you see we can have a new thing called tinker Tinker is just a command line interface which interact with your application which is specifically for laravel okay so if I say PHP Artisan tinker then you will get into a shell which is for lateral consider it as a laravel shell how I can prove that this is a laravel shell I can say app name is this going to work I'm not sure let's see okay so it says the name is not available so if I just say app yeah we have information about the app and now it says the environment is local I'm an environment file is dot EnV more of the information version lot of things that means yes it is working that's great so if you just press down key in your keyboard it will give more information so I can press Q to quit from this the app information so right now you know that this is a command line shell for lateral specific now what we can do here we can do all the PHP things so suppose I say SDR to Upper of sarthak if I do this you can see it's working str2 open and all the cases are upper so you can also do level specific things like suppose you need to get a user so I say user is equal to user find with the idea of 1 and hit enter and it says it's not having anything inside this because all the information is inside this user variable so I say user hit enter user with ID of 1 is not available so how about I can check ID 10 is available so ID 10 yes all these information is here so you know if we can find a user if we can query using the user model we can create a user we can update a user oh yes if we can update the user then we can fill the Avatar field how do we fill that let's try so we say user Avatar is equal to let's say some command close the line and then I say user and you can see now the field is filled is it really that easy let's check on the database so for the user ID 10 if I reload still Avatar is not available but here it says that because yes we have added the Avatar field with this value but we have not saved this changes into the database so what we have to do we just need to say user save okay so when I do this it says true and you can see if I go reload this page and yeah we have the Avatar field filled with the text which we have given here okay so this is how we can store or update the field on any model on any table so what we have to do we have to first fetch the user find with the ID of let's say 11. we get that now we have to update with the Avatar field so we have the user in this user variable then we say Avatar and I say here new value and after that I say user save that's great and now you can see we have a new value for the user ID of 11. that's still okay but you know there is one more way and that's why I love larval and that's the power of laravel so what we can do instead of doing this in two way first uh defining the value of Avatar and then doing the save let's get the user once again this time these are 12 we get that Avatar is null but now I will use a function called update and you know whenever there's the update we need to pass an array and this time if I try this new value from update let's see what's going to happen here if I hit enter it says true and now you can see oh wait what happened I am updating the value but user 12 is not updated with the Avatar field what happened let's try to update something else and see whether update is working or not so for the 12 let's update the name so instead of this I say updated name and this should be the name field name field still on both cases it's returning true but if I go here you can see name is updated but not the Avatar why what happened with this approach just for the Avatar field okay so here I am introducing you with mass assignment so let's open the level documentation because documentation is the king go to the documentation and search for Mass assignment okay and let's understand this in detail so let's just click on this and see what Mass assignment is now it says that you may use the create method to save a new model using a single PHP statement this is giving for create buttress it is also available for update so what it says that before using the create you need to specify either a fillable or guarded property on your model class now what is this and why we are using this fillable things so my assignment well vulnerability occurs when a user passes an unexpected HTTP field request field what does this mean this simply mean that we are saying to the model that only some of the field are fillable only fill the information which I have told you it doesn't matter what you are getting from the array we are having here it doesn't matter what you are giving if I have defined this field to be fillable then only fill this so if I open my user model you can see here the fillable property does not have Avatar inside this and we are only saying to the user model that hey only create or update the fields which are written here and that's why when I used update for the name it worked and when I use update for Avatar it didn't work so how we can make it working it's very easy just add Avatar field here and that's it so if I now go and try to update the avatar so something bad happened I think I can go out go inside the Tinker get the user 12 and then add the Avatar field it's still saying true but is it really true reload and yes you can see since now we have added the Avatar field to the fillable property it's now working so you can see this is really great but here is one more thing remember it's not saying just for fillable there's a guarded property also now fillable as the names just the fields which are fillable which we want to fill but suppose I know what I am sending and I know that there is no problem and no security issue I can actually turn this to guarded now guarded is just the opposite of fillable so here we say that what are the fields you need to guard or you need to uh restrict and I say that I don't want to restrict anything whatever user is giving I know it's good and just start working so what if once again I try and this time I say um my avatar this time it should be converted to my avatar and yes you can see it's now becoming my avatar okay so this is called Mass assignment and this is extremely extremely useful when you are using the model it's only working when you are using the eloquent model not with the DB query not with the query uh what's the query Builder yeah so these are the important things you need to understand about the mass assignment but it could be the case that suppose I want to not have Avatar in this syllable but still I want to update the Avatar field so what if I once again try to fill the Avatar or change the Avatar field so I say changed it says yes but is it really going to work oh yeah it's working because we need to go out of the Tinker session Tinker actually read all the configuration of laravel and then works so whenever you do any changes you need to go out of tinker and start working again so let's try to update updated it says true and you can see now it's not updated okay so it's not updated but still even after doing this even after not having Avatar in the fillable field even after not using guarded then I want to fill the Avatar field how do I do that so we can use one very nice method which is called unguarded this is exactly the same when we say guarded here so now I'm saying that unguarded actually it is ungaard I believe yeah so now I have done with unguard and now try to update it it says true let's try on our database and you can see it's changed wow this is great but remember if you are saying uncard that means it's not checking for fillable or guarded so what you have to do once you've done the thing or you do the trick you need to once again say re-guard so regard means start guarding again so if I update now this is not going to update you can see it's not updating cool so this is called Mass assignment is extremely extremely useful information you need to understand it is a really amazing Concept in laravel so finally we know that how we can add value to the user Avatar field so first thing we have done which is creating the field second we understand that how we can add a value to the Avatar field now it's time to really use the form here and then we can have a form and send that image to our backend to the level and then store that information how do we do that first we need to understand like from where this is coming and you know my way I if I have to find anything from the browser and where this is situated the code for this I just copy the text and start pressing Ctrl shift and F search for the global thing and yeah we have it which is from update profile information obviously we get this update profile information and we can just proof check by having any text reload here and yes we have the text that means we are on the right file so once we know that we are on the right file what we need we need a simple form which should add a avatar field here so right now we have a save just for email if we want to change email or the name so we have the form that's good we have the name field we have the email field and now we need another field just let's say above of the name so above the name field I'm going to add another field right now it will look similar to the name that's okay but now we will say that hey the name is actually going to be Avatar so yes this is Avatar and let me Zoom this for you and then it should be all Avatar wherever I am using name Avatar and here also Avatar Avatar Avatar Avatar so what I did I used the multi-cursor for me it's command D you need to check what is the multi-cursor and how you can use the multi cursor there is one way of using multi-cursor by pressing shift and control I believe yes shift and option is this you can see we are having the multi-cursor like this okay shift an option for Mac shift and ALT for the windows user anyways so we get that and here we are but now here instead of this text field we need a input field so instead of type as text let's say type is file field not the input yeah now it's good so now I can click on this choose file and choose or select any file like this so file is selected and when I save we we need to send this information to laravel and yes we are sending all the information because this is inside the form which is this so how do we send the information and where this information is going this information is going to the post request of a route called profile dot update so since this is related to the user I believe this will be inside of routes auth so let's see do we have the profile related things let's search for profile it's not here so let's try with the web.php now and yes so we have a profile dot update here it's a patch request not a post request is it profile dot update it's a patch request but we are getting the post request strange why we don't have the post requests so remember if you see at the bottom we have a method called patch so this is called methyl method spoofing that means we are tricking the HTML that hey this seems like a post request but actually it's a patch request this is for laravel so if we add this then lateral will understand that hey although this seems like a post but it's actually a patch request okay so we get that a patch request is here which is for updating the profile which goes to the profile controller now where is profile controller app HTTP controller so here's the app HTTP controller and profile controller or you can just press your control or command if you're on Mac and hit the mouse it will open the controller now here we have the controller and now here on the update part you can see we are first having something called request and then we say that hey fill request validated what are these things and what it is doing so we need to understand this by doing it ourself so what I'm going to do I'm not going to use this form because to get or to understand something is by doing and we are not doing we are just reading so what I'm going to do so instead of having this Avatar field here I just want to have a full dedicated card just for Avatar so how do we do that similar to this update profile information form which is situated inside the resources views and we have a profile then partial then we need to create another you can say partial so how do we create it so we can actually just copy and paste this one so copy and paste and now let's call this as user Avatar user Avatar form okay in the user of tar form this is the text so I say user Avatar okay and here we can say add user Avatar or add or update or update okay so yes we have this file but where should we use this file and how we can use this file so this is a partial file and this is actually inside the dashboard so in the dashboard we can see we are having this dashboard and then we have you are logged in actually this is profile not the dashboard so where is the profile page so we have a profile slash edit this is the file this is the blade file which is using include this is at include which is going to include the partial files in your other blade file so just like we have this one we can also use partials and then user update user Avatar form okay once by doing that if I reload you can see we have a user Avatar and then we have a profile information now in the user Avatar card we just need this Avatar and the save button not the name and the field so let's close every other thing and then we say that hey we don't need any other information so I'm going to remove everything so that we can learn from very basic and we don't need the email which is taking long time and now it says updated I don't need this and yes you can see now we have this so let's add a margin for this so margin top of 4 and yeah so we have this choose file and the save button so what if I click on this save right now it's not doing anything because it should be inside a form so we have the form but we have to give a proper form so form will start by having this input field and the save button so let's say a form and here is the form so what if I'm not giving anything in the form and try to submit it when you submit a form without anything so obviously we have to choose it submit it will submit on the same URL when you are not giving anything okay so first we need to Define what is the method so method is a post method and then we need to define the action where it should be posted so if I try this right now click on Save once again select file click on save you can see it says post method is not defined for slash profile okay so we need to create a route which will be like profile Avatar this should be the route we have to create so that we can send all this information to this route let's see how we can do that foreign to create this route we first need to go into the routes directory inside this directory we can see we have this web.php file and now we have to create another you can say route and I'm going to call route and it's a patch request because we are updating our user information and then it should be like slash profile slash Avatar and now I will create a new controller called Avatar controller colon colon class and inside that I will use a function called update and I am going to name this profile Dot Avatar you can name it anything but I am just giving profile dot Avatar okay so how do we use this profile dot Avatar in our form one is like you can use directly like this but suppose later on you said that hey this should be not profile dot Avatar it should be user dot Avatar so you have to come here and change it here or maybe if you are using it in 10 different places then you have to do changes on the 10 different places so instead of that what we are going to do we are going to use route and we call this as the route of profile dot Avatar so whenever you change something the route will automatically get reflected here as soon as the name is not changed okay so this is done and let's see what's going to happen what if now we send or submit the form so reload this page click on choose choose the image click on Save and now it says hey what is this route what is this route so this is actually a level or a PHP thing remember if you have to run something PHP thing then you have to use the double curly braces with the double curly braces whatever you put inside it will be considered as the PHP code and will be executed while compiling or doing this converting the blade file into HTML so save this file go back reload and then once again select the file click on Save and now it says that post method is not supported once again it says that post method is not supported and it says supported method is patch how do we add a patch request so HTML doesn't provide a patch method like this okay so it's not having any patch request so you can see it's not having patch it is treating it as a get request okay so what we have to do we have to provide a method spoofing which is called like this and provide the name of the method you want to send okay how do we know about this you can just search for method is spoofing yeah here we are so la yeah so method spoofing is like this so either you can use at method blade directive or you can also use the input hidden field with the name of underscore method so let's first see what's going to happen when we try to submit this form by having the method at method directive so click on Save and you can see it says 419 but at least it is going towards profile Avatar and not giving any method related error as I told you you can also do like an input of input hidden okay and the name will be underscore method and the value will be actually patch okay so if I do this exactly same thing choose the file and hit save we are on the back track so we are doing same thing so how this is working actually when we are submitting this form this input field will also submit with the underscore method and whenever level sees a underscore method field then it says that okay what is the value this will be the method so this if you inspect and if I scroll Zoom little bit you can see we have this method and when you use the directive like this this is actually doing the same thing behind the scene but giving you a more flexibility so you can see even after doing or using the directive we are still having the same exact input field which we were using by ourselves so basically the at method directive is a helper to create this kind of input field okay so that's good but still we are not good because even after doing this if I save this we are getting error which is 419 page expired now why is this so for understanding about this thing we need to go to the documentation and search for csrf okay so on the basics of documentation we have a csrf production now what is a csrf protection csrf stands for cross site request forgeries these are the malicious exploit where unauthorized commands are performed on behalf of authenticated user so suppose uh external command is running on your website to submit a form so if this is a plain form then anyone can submit it from any command but if we add this csrf forgery token like this not this one like here we have yeah so just like the underscore method we have hidden of underscore token with the csrf token which will be only generated by laravel so when you submit this this is actually checking for csrf token on this middleware thing okay so let's first understand how we can add a field called csrf and then we will understand the middleware so once again let's create an input field called hidden because we don't want to show this is underscore token and the value will be once again we need to run some PHP code or actually a lateral code so c s r f underscore token and like this so if I do this if I inspect this file you can see now instead along with the underscore method we also have underscore token and this is the token generated by laravel and if I submit the form with this token since this token is generated by laravel when you submit this form with this token will be also submitted and lateral verify that this token will this form is actually submitted via a valid person not an invalid or not external form is submitting okay so this is good but how do we check how do we actually perform this csrf protection so before that let me just tell you that we can also use the csrf directive to just populate this input field without writing lot of code so if I reload you can see still we have the token and token input field this is really great okay so when you choose file and when you hit on this one click on Save now it's giving the error for Avatar controller that means it passes the csrf field now how this works this works by going to the app then HTTP then we have a middleware and then at last you can see we have a verify csrf token so what happened inside this csrf verification token so this took this class or this middleware actually extends the larval csrf middleware so let's once again click on press Ctrl or command if you're on Mac and click on this file to open it and let's understand this one little bit so basically whenever you have a middleware so middleware run with handle method so in this handle method it says that whenever you are submitting this form it will check if it is reading the request if it is running unit test if it is accepting array or token batch so if all of these are true then only it will pass otherwise it will give token mismatch exception csrf token mismatch let's open this one and this is actually raising an exception and that's how when we were not using the not using the csrf then obviously it will give the error like this okay so that's how csrf thing works okay so now what next so we need to work on our controller because if I see select image and save this file you can see it's asking for Avatar controller which we don't have to create the Avatar controller we need to go and search for The Artisan commands if you scroll up we have a make command for controller and we can use this so let's say I'm going to say PHP Edison make controller but this time I want to create a controller not just inside the controls directory I want to create inside Avatar field Avatar directory so I just say I just want to create it inside user directory or maybe profile directory because it's related to the profile so let's create a profile and then provide the slash so this is going to be the directory name and then I say Avatar controller if I hit enter you can see it has created a profile directory and now we have Avatar controller okay so now what I'm going to do I will open the web.php file which is the route we have and now import this at the top so here we can see we have this f-star controller now let's see what this is going to say if I reload this page this time it says that hey yes you have the Avatar controller but you don't have the update method on it so we said that on the Avatar controller there has to be update method so let's open the Avatar controller once again Avatar controller and create a method called update okay so we have created the update method what next let's see so if I hit enter you can see we are not getting anything a white screen why because this method is neither doing anything not returning anything so let's first try to return hello and let's go reload this page once again and you can see we are having the hello here okay so let's first see what if we just want to redirect user to their profile page once again so suppose we have done all the store Avatar field everything we have done and then we can say return and response after response I can say redirect to slash profile okay so when I do this it will submit the form and get back to the profile so once again let's try go here choose a file like this click on save you can see I'm back on the uh on the same page because I have said that return back to the same page I can also use my route name here so I say profile page I just want to go into that but do we have that where's that profile dot edit so profile dot edit is the page name like this one so once again let's reload this page and try to choose a file click on submit and it's back on the same page you can also do one more thing and this is the thing which is really powerful and I say that I just want to have a session or session for the alert so how do we do that maybe we can take the example from laravel so let's say I have a re-direct and HTTP responses we have the redirect yeah so we have the redirect we can also use back that's really powerful so let's try to use the back instead of redirect so just um back so I say back like this response back reload to the file click on Save and we are back but it says that with input so that means we can also return something from the controller so we can say that hey when you get back then have some information and the information I want to send is uh like message and this message is Success so I say uh Avatar is changed okay so suppose I have to do this and I get this and huh that's okay I have the input but how do I show that input let's go once again here and then we can use that input field but it's not given here how do we use it yeah it's given here so if session has message then we can show this like here so copy this go to our user Avatar just above this form I am pasting it and I say if there's a message message then show the value of the message as the alert success this is not a bootstrap I say padding off or not padding just text Red 500 because this is a Tillman CSS okay so once again try save it should be there but we have this message hmm so message is there so it seems like this is not working so what happened here okay so we have to use width not the input we are not getting the input back we are just getting into the session and for session you don't have to provide the array it should be like first is the name of the session at second is the value so it has to be message obviously and now let's try this once again so if I reload select save and it should be red but it is black but not an issue because we just see that Avatar is changed whatever information we are passing from the controller we can see directly here in the session okay now then you will say that what was that with input so see we are passing some name and uh email field Suppose there is some error and we just want not to give this field as empty when user redirected back to the same page that's why whenever you want to fill these information or the input with the older input which user has already given then you can use the width input okay so we got that how we can get back with the session and how we can use the redirect also and how was that redirect if I undo yeah redirect to the route instead of giving response we can directly say redirect redirect only redirect not redirect to okay so reload and once again select a file and redirect back okay so you got the point like how we can redirect back or redirect to specific URL if you want to redirect to google.com you can do that also no worries on this foreign of what file we have uploaded so how do we get the request body or the data we are sending form data basically so for this we need to once again go to the documentation search for form data Let's see we do do we have anything no form data yeah we have this form request they call it form request or requested data something like that so let's first try this one form data so here we are and okay so we always need to use the request and if we scroll up and see from where the form is working so it's all about validation how about just the form yeah so basic blade things we have this form thing so it says the form put validate error but it's not about the controller so once again search for form and form request validation we did that form data okay so digging deeper form data this is the one which is more useful no this is also not the one so form data I'm trying to explain you how to search inside this uh this documentation so at last we can see retrieving all input data is it the thing we need seems like this is the real thing so we have to use the request and then we can get all to see to see what actually we are doing so it seems like request is the only thing which we need so there is a HTTP request and when we go on the HTTP request we understand how we can get the things so whenever inside your controller you are using any function and that function need something from the form you have to use this request and what is this request it is actually illuminate HTTP request this one okay so we got that so we have to use the same request on our function here or we call it method so let's have the request and make sure it is illuminate HTTP request and we call this as a dollar request and the first thing I want to check is do we have the token so here I am going to die dump I say request input and then underscore token because this is what I understand from here that if I have to get any field I can use the arrow input and the field name okay so let's reload choose a file very easy click on Save and yes we are getting this now if this is true can we get the Avatar so what about the avatar if I reload yes we get the Avatar field and obviously you can use the all to see how many fields you have we have three Fields one for underscore method underscore token and the real which is Avatar okay so this is what the path of the file is we got that but we can first make sure that whatever we passing in the Avatar field has to be a image not just the text field because we don't want the text to be here we want the real image so that we can store so in that case I am going to introduce you with the validation so this is the validation thing I need to search for validation validation okay and it's very very very important Concept in larval so you can directly go on the documentation on the basic there's a validation okay so form validation when you send something you have to validate the form request data so how do we write the validation so you just need to say once you use this request illuminate HTTP request then you can say request validate and whatever is your validation rule okay so first I need to say hey I need the request and in that I need to validate in the array I have to say Avatar field has to be a file this could be the file okay so if this is true then it will pass along and do the DD otherwise it will redirect back with the error okay so how do I know that there is a file validation rule so if you scroll up then you will find there are available validation rules there are lots and lots of available validation rule here you can search for file so it is start with f and here we are there is also an image I believe so yeah here is the image so instead of file we can use the image and how do we use it just like this so file under validation must be an image of jpg jpeg PNG BMG BMP GIF SVG or webp okay so instead of file I can say it is going to be the image wow this is good so what if I go back reload and try to select file click on Save and now you can see instantly I'm getting this Avatar field must be an image right now what happening here let's see how this is coming so if you go on user validation here is really important message field called X input error this is a component by larval so we will talk about that later but something like this consider it as a text field which is showing in red when you use the error so it says that if there is any error and if there is any error for Avatar then show the error and how this error is coming whenever this validation fails the level redirect back with the session as we have done with the session name errors and on that we have the Avatar error so if you scroll up here should be the validation error working with error message so it says that whenever validation fails it will give you the error so you can also manually get the error and redirect however you want or you can directly use the error get and the field name okay so this is how the validation is coming here validation error is coming here but once again I'm sending the image why level is saying that hey this Avatar not an image remember whenever you are sending an image or any media then instead of this normal form you have to use one more attribute of this form which is called ANC type so n type has to be multimedia formed data okay once you do this then instead of the path of the image or path of the Avatar it will actually send the file behind the scene so once again reload choose the file like here click on Save and you can see it is not giving any error even it is giving me the die dump because this laravel validation is passed so that's the power of larval validation if it is failing it will not execute anything after this validation because it is failing and it will redirect back with the error and we can show that error right here okay so that's good so we get the image what we are sending and you can see it is image is something like this illuminate upload file we can save this later but on the validation there are more things so if you get here this is the validation is starting so let's explore this documentation so it says that you can do the validation like this you can also provide the required field which is extremely important so obviously when we are sending it we cannot save this because this HTML field has the required field but suppose one user came and he says that okay this is the thing and this is required I'm going to remove this required field and let's see what's going to happen when I submit the form so I have removed it click on Save and you can see even though I don't have the Avatar field level validation passes because I have said that if there is a avatar field it should be image but we didn't have Avatar field so that's why we need to tell to the validation that hey validation we need this Avatar to be required that means we need this and obviously since we need it it has to be image so there is two validation rule required and image so validation rule works from left to right first it will run this one and second it will run this one the image okay so now once again if I reload you can see now we are getting another different error which says that Avatar field is required why because we said that it is a required field okay so since you can see I am having or adding new validation rule by the pipe sign but if you want you can use the array and inside array you can Define like this required and then it has to be the image and it will going to work exactly same okay so I can just remove the required required field from here to show you that it is still working okay so we got that the validation rule is really really powerful okay so we got the required field and then let's scroll down it says that you can do lot more thing required with bags and bags having some different things we don't have to worry about that so there are different different ways of getting the error you can also get all the error and show all the error at the top instead of instead of under each of the fields that you can do but I'm I want to introduce you with really amazing thing which is called form request validation now what is form request validation remember I told you initially during the starting of this course that controller should not do more Logic the work of controller is to control and redirect but see we are doing something inside the controller so it is not good to have the validation inside this controller so what we have to do we have to create another file which will be responsible for this validation and that's why we have to create a new form validation request how do we do that we have to use this PHP artisan make request command and then give the name of the request and see the name pattern first where you are what you are doing where you are doing and the request let me explain you so I have to create a request but what I'm doing I am doing update where on Avatar what is this it's a request request so I said my request name for this task is going to be update Avatar request okay so that's done so it will be available inside app HTTP requests so if I hit enter you can see there is new file available called update Avatar request so click on update of the request here is this thing so let's go here and what it says it says that on the rules function or rules method you have to put all your rules okay is there any rules yeah here's the rule so let's go to Avatar controller I can cut this rule from here paste this rule here like this and that's done so I can totally remove this form request validation from here but how do we use this file to use this file what you have to do you have to say hey this is the file type for the request and this is coming from our service container service container is a really Advanced topic I will explain you later on this course but right now consider it like if I type this that the request is going to be store post request then it will use the request we have created so right now here the request is the normal HTTP request but I need to say avdar update Avatar request if I use this file instead of eliminate HTTP request now it is using this file which we have created and make sure and and remember this update Avatar request file we have created is actually extending the form request so basically we are doing the same just having another layer of this class over the normal HTTP request so that's the cool part so this means if I go here on this and if I try to submit this choose a file or maybe I can see by removing this read required field save it you can see it says that this action is unauthorized this is really good one this action is but why I'm getting this action is unauthorized let's go on the form validation and see what it says so if you scroll down on this here is the authorize form request now since this form request can be used by many people so what I'm saying that hey I want to check if someone can use this validation or not for this on this authorized part I can put my logic and if I want that anyone can use it I can go on the authorize method and just return true that's it and now if I go and reload once again you can see the validation is actually working and we got Avatar field is required and that's how it is working so by using this all the logic of validation is coming under this file called update Avatar request and when I get back to my controller it seems like nothing has happened it's once again so clean and the responsibility of controller is not increasing it's just getting the request and doing what you want but behind the scene this request file is doing all the logic all the validation so that's the power of validation or request to validation with the form request validation that means creating a new file okay I think you got that how we can protect our fields and how we can show the error to the user and how we can not put any uh wrong type of data inside the database because if we are putting a text field inside a numeric in MySQL then MySQL will give error why go to the database if we can protect everything on the laravel level great so this is how level validation works but still we need to store the Avatar field to store the Avatar in our Avatar field first we need to visit the documentation and search for a store and there are a lot of store so I can change it like file so there are two things one is file storage second is HTTP file other than that we have a package file storage testing for file storage no so let's start with digging deeper file storage okay so here we are on the file storage and let's see what it says first you need to see the configuration so all the configuration are inside the file systems so if I go here on the config the file system so here we Define which disk you want to store your files right now so here the default one is file system disk and if it is not given on the door dot Envy file then it will be taken from local so search for this field obviously it is local here also so this means we will go and store on local but what is local so here is the disk information local means on your computer on inside the storage path and here we have the storage path inside the storage we have to provide the app directory here we are and inside this we will store the file if you want you can also use the public one which is obviously storage app public so inside this public directory if you want to store it on the S3 AWS you can do that or if you have any custom one you can Define the details here and then use it okay so we got the point that this is the configuration but what next so we have to use storage facade like this and think about facade as a normal class which has this disk function so storage facade has disk and first you define the disk and then you say put your the file name and the content of that file this is the one thing public disk can be linked via storage we will see very soon but what I am interested in is showing you how you can actually use the request to store the file so search for request and arrow and here we are so whenever you have any file in your request you can directly say request file the file name and store and storing where the avatars directory okay so let's try this one and then we will move to the storage facade thing cool so here what if I say storage file and my file name is Avatar okay so here let's go click on choose file then select the file click on Save and you can see we are getting the file only so when we are getting the file next task is to just store it and we say store and inside this I will Define the path so if I have to say avatars this means it will store inside a new directory called Avatar okay so let's go and once again reload this file and you can see it is done and this I can prove by going into the storage directory there's the app and now we have a new directory called Avatar and here we have the file and this is the image I have just uploaded and it is having a very nice weird name which cannot be replaced okay so once you are done with this then we can return with a session name like message and message is Avatar is updated okay so this is obviously done so this we have done that so once again let's try choose a file save it and it is saved and you can see this time we have ftar is updated okay so next task is to store the information of this file with the file name into the database so first thing I'm going to do I'm going to diadem and see whether we are getting the detail for this file name or not so once again let's choose the file click on Save and yes you can see we are getting Avatar and then the file name that's really powerful since we are having this path then we can simply use it as like path and then we have to update the authenticated user so learn will provide a very nice way to get the authenticated user so how we can get I can just show you by diadem and say auth and user this is obviously the authenticated user always so let's try to see what we are getting you can see we are getting the authenticated user now if we have the user and this seems like a normal user model so if we have the user then we can just update this Avatar field with either using the update function or defining the Avatar and click on save so I will use the update method like this and here I will say Avatar is going to be test okay so just do this and then I will once again fetch the user and see if we are really updating the Avatar field or not so open it and it seems like it is not updated let's try once again and so what happen is this user is cached so what we have to do we have to say fresh so that it will get the fresh version of user model from the database and if I do that still we are not getting it so maybe this could be the case of user model Mass assignment remember this Avatar okay so once again reload and see this great we can see Avatar is really updated since we have added eight new the mass segment so instead of the test what we have to do we just need to fetch the path and then here we simply say storage underscore path so this is actually give you the the path for this storage file and then provide the dollar path so this will actually complete the full path for your file so maybe we can say like storage path then concatenate with slash but okay so this will going to be the avatar so once again reload this and now let's open the table plus and reload and you can see we have this full part of the user Avatar and if I hit enter so it should be there but we have some problem anyways we are actually getting the full path like this now what happened here is you can see the Avatar is inside the app directory so we have to say a storage path till app and then we have to provide it so let's now once again update it we have a new entry and let's try and yes you can see we are getting the image that means it is really stored in a very nice way okay so this is how you can store the file or the image in your storage directory inside of the lateral plus the information or the path of the file will get stored into the database next task is to show the Avatar hair which is going to be very easy and let's do that with the blade files or the views we call so we have to go to the profile and here we have the edit inside this we have to show the avatar to show the Avatar field here first need to see if we are getting the Avatar or not so what I will do I will first go on the profile controller which you can find inside the app HTTP controller and here is the profile controller and here on this edit part we are sending user information to our view okay so this is really important to understand see here we are having all the name email of the user so how this is coming on this page we are showing it on our update profile information partial so let's open that we use profile partial update profile information partial so inside this we can see we have dollar user and then Avatar so how this dollar user Avatar is coming so it is coming as I explained you from this whenever you return a view in a second parameter you can provide an array of the data you want to send so here you can see we are sending the request user the user who is requesting this edit page this means the profile page okay so first let's die dump and see what we have in the user request user so save this file reload and yes we have it and we can easily get the Avatar so can we do something like this request user Avatar okay reload and yes you can see we are getting full path this means we don't have to worry about sending the Avatar because it is inside this request user so obviously we are getting the request user here so let's go to the partial of user Avatar form we have this one and just above this one so reload and here user Avatar and here after this we can show the avatar so here we have the user Avatar and just below that we can create an image tag and the source of the image tag will be dollar user slash Avatar because we know it will be available but this has to be in double curly braces so that blade can know that hey this is actually a PHP syntax and all tag will be user Avatar okay so that's good and just close this and reload it says nothing so what happened let's see okay so it is actually getting me from localhost 8000. so what that mean so if I remove it okay so this is not what I want let's open it and it should be something different so when we are getting the the user Avatar like this so if I try to open it in a new tab it's working because this is actually coming from the disk from my computer but what I want I want to have it on localhost 8000 slash and the path of the image so what is the path for our case in our lateral so in our level the image is stored inside the storage app Avatar so how about saying like storage app with our okay so after that we need to provide the Avatar what is the Avatar name or any file name slash Avatar but still it's not working why because larval does not get any file or information directly from Storage so let's go to the laravel documentation once again and search for storage and here we are on the file storage so if you scroll down as I told you we need the request to file store but it should be um so here we are on the public disk and whenever we have anything in the storage which we want to link to our public directory then we can use this link but why we are using this see here we have this public directory whatever we have inside this we can access so we have robots.txt can we access it directly so public slash robots.txt and it's not giving maybe I need to remove the public yeah you can see we are getting so instead of just you saying public if I just say slash and any file name it will first check inside the public directory and if it is available there then obviously it will provide you so similar to this what if we put this image inside this public file public directory now what's going to happen if I just say look close to 8000 slash in this file name and yeah you can see it's working and if I get it back to the avatar and reload it's not available to our public directory but letter will provide something different that will say that you have to run this and then the public the storage app public directory will be Sim linked to public directory inside the storage and then it will be to the storage it is confusing so let me explain You by doing it so see first we have the storage app public we will Sim link this public inside the public directory but rename it to storage what I am saying I can explain You by running this command so when I run you will see that there is a new directory called storage but here is a very nice Arrow which represents that this is actually a Sim link or a simply a link to this public directory so if I open the storage you can see something is similar so how about moving this file into public and now you will see that if I once again Create a Sim link um it should be available so let's remove this Sim link and once again create it yeah you can see now we have this file once again and this means what we have to do we have to Simply say localhost 8000 slash storage slash the file name wow so this is how we get the file from this public directory now everything is good we have created a Sim link for this public directory inside the root public direct directory with the name of storage but instead of doing this even after doing this we are not able to show our Avatar because our Avatar is stored in the avatars directory how about moving this full Avatar's directory into this public directory of storage this means when we store the Avatar here we said that it should be storage path with app and inside app we are storing in the Avatar directory how about having slash public here and then inside the public we will create a avatar and then use that so let's remove this Avatar directory from here go and comment this and go to the profile choose a new Avatar field like this click on save it is saved and it is still storing in Avatar what happened because if I open actually when we store we said that it is storing on the avatar so how about saying public slash Avatar so in that case we don't have to Define public here so one more time save let's see where it is and yeah congratulations it is inside public Avatar great so now what we have to do we just need to open the terminal and run the PHP AdSense storage link and this means now we have a storage Avatar and a file name and this should be easily get and we can say storage slash all these things inside avatars and yeah it's working it is working this means what we need to see that this should be the exact path stored in the database also so what should be the what should be the avatar path here on our database it is still user salt we don't want all these things what we want we just want the the file name to be Avatar and whatever it is okay so let's see instead of having this let's see what path we are getting so once again reload choose another file click on Save and yeah we can see we have the public Avatar still this is not good because we don't want the public keyword here if we store this in our database we don't want public so to solve this let's go to the level documentation and here we know that we can use a store but there's one more thing we can use the store as and there are two things so what is the difference here you define the file name and here on the storage when you are running it you can Define the disk where you want to store remember I explained you about the disk in the config file system here is the disks available and the public disk is actually having the public you can say directory inside the storage and this is yes we want so instead of using public slash Avatar we will just Define that the disk is going to be the public okay let's now once again try this select and save and this time yes we are just getting Avatar and the file name and we know this is inside the public directory so if it is inside the public directory of Storage Public directory Avatar and the Avatar which is 5q something and here is the 5q1 this is the one and now it should also be available in our Storage Public Storage Avatar here is this okay that's really cool so we just need to store this path without the storage path link so we have to store like here okay so one more time and then we are good to go select choose this file and I'm going to first remove each and every image so that we will start fresh okay so delete permanently it's actually deleted so if I reload you can see it's deleted okay so now if I click on Save and it is saved and how to verify okay file is here file is also Sim linked here I can go on the profile uncomment the Avatar link and boom we are getting it so when we want to show the Avatar so once again see here when we want to show the Avatar this image tag we go here this image tag should include the storage path which is actually saying like this has to be slash storage slash and the path name like here okay so let's see is it going to work boom finally it is working let's now give this image a nice styling so we get the class we say width is 8 height is 8 rounded full and like this reload oh it is very large okay so if these things are not not working I can have another trick I can simply say that hey the width is going to be the 50 and height is going to be the 50. this is for the image not the CSS thing cool so here we have the Avatar wow that's so easy and so amazing to see that we are storing the file and we are keeping that file in our storage directory and then Sim link to the public directory and finally showing up on the user profile so create that now we can move forward foreign thing we need to do with our file is suppose user changed the file so I'm actually using the same file but if I upload this file yes this file is showing here but if I open my avatar this there are two files one is the previous one and second is the new one I don't want to have a lot of file if user is keep changing daily all the files so what I need to do when user change the file we need to first check if there is any other file available remove the old one and then store the new one okay so let's remove that one and now open the Avatar controller here we say that okay we have to upload a new file to the user and then we are updating the user Avatar path but before updating first we need to check if user is already having any Avatar or not so if request user so remember we can either use the auth user or we can use the request user so I'm just using the request user if we have the request user Avatar then I need to remove it but how do I remove it for that let's once again go and search for delete on this file storage so here we are going to use a very nice feature of laravel called storage facade there's a storage facade can be used to do anything with the file so we can now delete the file with storage and delete and providing the file name is it going to work let's see now so here I say storage make sure it is imported at the top and then we say hey delete now what if we want to pass the Avatar field here so I can yes say something like this but I don't want to repeat myself so I say old Avatar and on this if a statement and yes checking for Avatar but if it is available I will add it in the old Avatar variable and I can paste it here so this is going to remove the old Avatar so let's try and store another one and it should be deleted but it's not so what happened so first let's check do we really have the old Avatar field here or not so I will choose the file select it and yeah we are giving the old file detail so this is fine everything is good now let's go to the documentation to understand how this works So when you say delete it's just try to find the file inside the storage but you can also Define on which disk you are going to look for this file and then delete it so it's very easy because we know we have used the disk called public like this and now it should delete the file so right now if I select and here we just have four files click on Save and once again we have the four that means the older one is deleted so what I'm going to do I just go and see what actually the file name is so I can open it in a new tab and it start with h t m c okay so we're just going to use the htmc and delete all other one and delete so htmc is there so this is how I can now change the file and it should be removed htmc is now removed and we have the new one wow that is so amazing to see that we will be able to use the storage facade to delete the file this is really nice but can we use this storage facade to do something more yes you can actually create some files or you find the directory you can create the directory and obviously you can store the file so we can see that if we go at the top here we have put file now with the put file you provide the directory and the real content for the file okay so there should be some other things put file photos and the file this is actually the name and then the content and finally the disk if you don't want to provide the disk at the beginning okay so let's try this one put file we will go here and then we will say path is equal to storage then we provide the disk it's a good always provide the disk and then we say put and when we do the put let's see what we have inside this put so inside the put we are giving first the path second the contents okay so content is going to be the request file called Avatar and the path is going to be since we have already defined the public it has to be avatars okay let's see what we are getting in the path when we try to upload it from this storage facade okay so let's go click save and once again we are getting the path wow that's so easy so if this is working I can see that it should be available so remove the temporary one and try to reload and select the file once again click on save it is available and you can see file is changed and it is showing here that means everything is working absolutely fine so in this way yes this is uh like you have to use the storage disk kind of things but I believe this is more you can say stable one instead of file request file storage because this maybe we can forgot but this we never going to forward okay so this is the way you can use the storage facade to not only just delete but also to store any file or any image great till now we have understand various things about laravel but I just want to create something awesome something cool that you will love to work with and that's why I'm going to create something AI related with larval but before that I just want to thank Nunu Maduro for creating this amazing package called open AI PHP client so this is the open AI PHP client with that you can ask something and with a super models we have on the open AI we can get the result so first how we can use it and then we will going to create something awesome with this package let's start the journey so this is actually the PHP client for our open AI but we are looking for larval we are learning level we need to find something related to Largo so whenever you are finding any package which is just for PHP yes obviously you can use it PHP variable is a PHP framework you can use it as it is but it will be good to search for any package with laravel so if I search for open AI level you will find there is a one for lateral and obviously this is also done by Nuno so what we have to do we have to use this package instead of this and what's the difference there is no difference just this is actually created for laravel it is created over the core package okay so I will just copy this go to the terminal and paste it and you will see that this is going to install it and if I open the composer.json you can see open AI laravel is now available in the required one not in the required div okay so this is done from our side now what next we have to actually publish some some of the things so copy this this thing which is going to publish all the assets or files we need for our PHP open aiphp client now what actually it says it says vendor publish if I just run this I get list of all the packages or all the things we can export from vendor directory to our application so that we can modify it and over this you will find something related to open AI laravel service provider and this is the one which it is trying to export so either you can use this full command or you can just see here this is the eight number you can just press 8 here hit enter but since we have it so it will be good to have here now it says that copying from vendor directory to config open AI now we can see that in the config we have a new open AI related configuration and this is just having two things open AI API key which we need to provide and we can find it from our openai.com and then some organization if you want to give that's good so this is fine but how do we start working with this there's a sample code given so I will going to copy this code and go to our web.php file and here I will go at the bottom and just for now I'm going to create a get request for open Ai and then provide a closure yes this is not a good thing we need to use the controller but just trying out things you can create a route with a closure so paste it and we have to use it at the top obviously and then now we are having this open AI now it says not found this is not an issue when you run it it will create the facade on the flag okay so this is good we are done with this but what next we have remained One Step very important step which is the open AI key how do we get that we need to go to the open ai.com and here we can click on API then just log in if you don't have any account you first need to create an account so now I am authenticated and I will redirect it to the home page here I am so let's click on the quick start and if you scroll down you will find there is a it is for security secure key a secret key actually not security so click on create new one and copy this close it it's very important to first copy because otherwise it will not give you back so what we have to do remember we have the config and open AI we have to create this entry in our DOT EnV file so let's open the dot Envy file and anywhere you put it like this but here if you put and here is the key I generally want to have a comment here which is going to help me to find the open AI open AI why because suppose I just want to search open AI like this then also it will be available to search and obviously if I have this I can find that this section below is for openm anyways this is good we are done with this thing and let's try to hit slash open Ai and see what we are getting so here we are let's go and click and open AI like this hit enter and it is doing something and now it says you exceed the current quota please check your plan and billing detail so I get this and I have just changed the account so I am now having a fresh account and this means I can go on the manage account and here you can see the usage is having nothing so we have the free usage till 18 so what we can do we can create another API from here and you can see I don't have any API so click there got the new API so searching for something and now I can paste it okay so that's done and this means now I'm going to use this API for this I can say account okay right now I have nothing but if I go reload this page and very soon we will get the result so since this is a AI model it will take some time and what we have asked we have asked this thing PHP is and AI has completed it like this PHP is a powerful scripting language designed for web development PHP recursive anonymous so seems like it is working and if I now reload on this open AI thing you will see that I am going to get that I have used something but right now it's not updated but very soon it will be updated and show you that hey you have used something and actually it's given like there should be five minute delay to show the graph anyways we are running it and we are successfully uh added a new package for our open AI things and now we can do so much amazing things with this open AI let's explore this foreign so we have just seen that how we can use this package to run the open Ai and get some result using the completion model or we can say text DaVinci but open AI can do more things so I can go on the documentation and here on the API reference you can see making request then we have model completion edits images embedded files fine tune moderation a lot of amazing things are here so what can I do I can just click on images and see yes I can create image just by giving some prompt like a cute baby C otter so let's now see how we can do the image creation using the open AI API and then what we will do we will create users profile using the open AI isn't it really amazing let's try this so how do we get that it's not given on the documentation for this larval open AI PHP but I will going to teach you how you can read a package and how you can get more information about it so first thing first this open AI is having a facade so we didn't get any information from facades because it's some kind of magical thing so don't worry about this but we know that we are using a package called open AI so let's first find a package called open AI inside the vendor directory so just go to the vendor scroll down and you will find this open AI click there now we have two things one is open AI client and one is open AI laravel you will say that sarthak I have just installed openai laravel why we need open AI client because open AI level package is just a wrapper around the real open AI PHP client okay so that's why we have two but the real code is actually inside the client thing so if I open this source and let's go to the uh responses then you can see we have here used completions so completions is here similar to that we also have images so can we just use something like this so open AI instead of completions can we do the images okay let's do this and see if it is working or not but we don't have to provide these things now something else we have to provide for that let's go to the documentation for open Ai and we have to provide at least these three parameters first is the prompt so let's copy this and paste it here okay according to this prompt the open AI will create the image next it says n now the definition of n is here it says number of an image you want to generate let's have two number of images so n is equal to 2. next after that it says what size you want because the larger the size the bigger the size we the larger you have to pay for it so I don't want to waste my credits just on the images so I will use uh maybe 5 12 by 512 is good so size will be this one like here okay so everything is done and I don't know what will I get inside it so I just uh go die dump instead of echo I will do the diadem this is lateral thing okay so I die dumped this result and we'll see what's going to happen now okay so let's go to localhost 8000 slash open AI hit enter it's doing something and very soon we will get the result yes we are here and now if I zoom it for you you can see we have the data then we have two images because we said that number of images has to be two if I open then we get the URL and open the full URL copy this image URL and paste it and see how it is created so the prompt was acute BBC order so while this is opening let's open the other one and this is the second image AI has generated so here we go what's this cute baby see otter so c order cute BBC order here is this what about if I Google it cute baby c order and exactly this is the power of AI but now as we have decided we need to have the user avatar for our application now I want to use I want to create the user Avatar according to the name so I don't know what it's going to do but first I will use uh the ought user name okay and then I will say uh I will actually provide everything which I am talking about so uh create avatar for user with name and then concatenate with this name and I just want one and I just want the lower quality so that my will not waste my credits okay so let's now try so let's go here on slash open Ai and let's see how this is going to be I'm really excited what should be the result so we get the image and let's now see how it is going to be run this is really bad AI what you are doing I'm not looking like this so this is really really bad Avatar so I need to give some more information so it says that this is the name and some Avatar is good and I don't have this kind of hairstyle neither this kind of beard this is not me obviously and you can see name is incorrect so I'll say create avatar for the user with this name obviously and maybe I can remove the name and I can describe some Moves In creativetar for user with uh cool style animated in uh in uh in I can say Tech world so I'm not sure what it's going to return me but let's once again reload this page and see how this open AI will going to be will going to generate okay so here we are we have the new image I'm going to copy this let's see I'm really excited for what's coming okay so open here you are funny but you are not that good anyways we are able to achieve what we want to do so we have all these things so how we actually get this URL from our level so we have this result from this result we need to fetch the data so we can say hey I need the data and since we always going to create one image so data is an array so I will first get the first result and from that first result I need the URL okay so we get this now instead of this I can say return response and I can say URL is going to be something like this okay one more time reload this page and we are going to see what this time AI will give us okay so here we are and we get this let's press command and click it has opened and seems like this is the nice one okay so nice Avatar we already have and since we know that how we can generate the URL for AI generated Avatar we just need to push this to laravel so that level can store this Avatar instead of the Avatar we provide from our computer our system I am really excited for this let's see how we can move so to get started with AI generated Avatar we need to create a button which will when clicked submit the form to the backend to the level level will create a new Avatar store that Avatar to the storage file update the user Avatar path and then redirect it back to this page with the new Avatar let's see how we can do that the first step is to have a button so let's go and start with resources views profile edit and inside the partial actually we have a user now here we have the user header and actually we need to move this out of this header foreign looks okay anything is good now we have to first create another form just below this image so this is going to be a post request and action has to be something new route which we are going to create for profile Avatar I can say profile dot Avatar dot AI okay and here inside this I'm going to add another button just like we have this one okay so have this button and we call it generate Avatar and above this I will put this and say generate avatar from AI like this okay and for this form I will give some margin top of 4 let's say and see how it is looking now it says that you don't have this route and that's why it's giving this error Now to create this I need to go to the route web.php and at the last we have some our a open AI code now let's create another route maybe here we can create we have this Avatar and just like this one I will create another which is called post and it will be same as profile slash Avatar slash AI and it will also go to the same Avatar controller but we will create AI generate so maybe I can just use generate and then give the name which is very important profile dot Avatar dot AI okay so this is done and now if I go reload this page you can see we have generate Avatar button and I think I need to say or upload Avatar this will be good so I can create another P tag here and I say simply or margin y will be 4 so 4 up and 4 down and here I can say not generate its upload Avatar from computer okay so either generate or upload like here so this is good and we are good to go so when we click here it should say yeah because we don't have remember csrf token so for the form we have created we need a csrf directive of Blade and now this will submit but now it says that hey after controller generate function is not available here we just have one function called update let's create another function and we have named it generate now how this will going to generate the image from the AI so obviously we have the code to generate the image so we can copy this code and paste it here but right now we don't want to just waste the apis it's really crucial to not waste your API so here what I will do first I will remove this code or maybe just comment it right now because maybe I can use it later for now I just need to know that how we can store any image from URL and then update the image avatar for the user so first thing first we can see this is the this is the way we can use to store the Avatar into the storage app public avatars directory now so we have to do this thing same but we don't have this request file so what we need actually this says it need the content content of the image so we can say okay we will generate the content for you how we can get the content so content will be like file um get content so when we provide any file into this function it will give us the content of it so let's now go and search for any image let's say Mac OS wallpaper just anything I don't want to just waste time on getting the image so we can get this URL and from this URL we can fetch the image now let's diagram the contents of this file and click on generate Avatar and you can see we have this content we just need to pass this content to our yeah to our contents section on the storage and it will store that file so that's good and it should be inside the Avatar so once again go back like here reload click on generate and it's written nothing because we have not done anything but it's even not creating any file so whenever you are actually is storing the file through contents you need to provide the file name inside this directory so I will generate file name by using Str random and let's say 25 characters and Str has to be imported like this illuminate support Str and this file name should be like here so I will use double curly brace and double quotes not curly braces and then dot jpg so this file will be generated as the JPG file okay so now you can see this is the name and here we have the image great so now we know how to create the image what if we can also do the Avatar update and finally return and redirect with the same thing like this so it should return the path and path will be here authenticated user everything is good let's now go back click on generate Avatar and you can see it is returning something not good so when you use the content this is not going to return the Avatar path this is either written true or false so this time we cannot use the path so we have the file and we know this file is inside the Avatar file name so previously how the the code was generated or how the path was generated we can actually see by uploading like this open in a new tab and see it's just Avatar and the file name oh wait we already have it Avatar and the file name can we use something like this so path will be here great so once again generate Avatar and you can see the file which we have hard coded is now becoming the avatar for the user this is very very nice now what next you know we don't want to hard code this we want to First generate this from the AI and then pass that URL to the file get content great so just uncomment everything so here we have the prompt and obviously we need to use this open AI so we have this open AI from here copy and paste we used it now everything is good instead of this thing we can simply say hey this is the URL and you need to fetch the content from here right now everything is fine let's now see how we can do that reload click on generate Avatar now it's doing something and you can see at the top here we are having this loader which is actually taking time to generate the URL which is obviously AI generated and finally we have the Avatar wow so cool I am really happy with this thing which we have just created so one more time click on generate Avatar and this will going to generate a new and fresh Avatar this time so let's now see how this Avatar is created okay really cool so once again it's filled with lot of avatars and lot of other files so what we can do we can remove everything and we know that if there is Avatar available we have to remove it so before doing the store we just need to delete this but you can see we are repeating our code this this this also this also and obviously these two lines are exactly repeated so what we need to do we have to do some refactoring in the code and then we will move forward with something amazing in this level 10 tutorial so we have done that and yeah since I have removed that file so I can just click generate avdar it will now once again create a fresh new avatar for our user wow so a little time it take obviously we can remove This Time by using something else now it says request variable is not there okay so this doesn't have the request variable um here so we need to say request and then request okay so one more time let's get back and click on generate Avatar and it takes time because first it taking time to generate the Avatar the AI is taking time and then the file read is the second point where it's taking the time so avtar is once again ready and I know this is not good but yeah it's okay so I can remove this Tech world and see what's going to happen if I create an or generate a new Avatar final thing then we will wrap up this tutorial so let's see I'm actually loving this one okay so yeah we have the Avatar ready Cool really amazing now let's move to the another important thing which is login with some other website have you ever seen like login with Facebook login with GitHub let's Implement that thing in our application so first thing how we are going to do it and remember the level is so easy it provides everything for you this means if you go at the bottom of this documentation not exactly at the bottom but on the left side you will see the packages these are first party packages that means created by laravel team now if you scroll it down at the bottom you will find this package called socialite if you just click on this package it will give you the documentation how to use it which says that form based authentication there will also provide a simple and convenient way to authenticate with oauth provider using larval socialite so let's do this first thing we need to is the composer required socialite package let's click here to copy this and then go to the vs code close the sidebar create a new terminal and paste it while we are pasting this or this is running let's go back and see what we have to do now it says that whatever website you want to link with the oauth to you need to provide some of the things like client ID client secret and redirect URL now how we will get all these three things so first we need to copy this and we need to put this on our config Services dot PHP file this is really important so let's go open the sidebar and here we have a config then if if you scroll down we have a services.php and when you open this if you scroll down you can see we have some configuration already given but since we are going to login with GitHub we need to paste like this now it says that yeah you need to get the client ID by EnV file so do we have the GitHub client ID in our DOT Envy let's open the dot EnV file and open and if you search for it you can find because it's fresh we are just starting so let's say GitHub and then paste it like this similar to that we also need to have the secret from our DOT EnV because while we are testing while we are developing these credential could be different but while we are on the production it could be different why not we have the redirect URL also from the dot EnV file and we can just remove this and say GitHub redirect URL redirect URL copy this and go to the dot EnV and paste it so these are the configuration we have done our socialite package is installed let's move to the documentation and see what next yeah we need to get this we will get that from GitHub but let's see is there anything yeah so it says that once you have done with the configuration then you need to create these two route one is the redirect other is the Callback so now copy this one and go to our web.php so web.php is inside the routes web.php that's good so let's remove this one and paste it it says it need to import this so I press Ctrl and spacebar to get the suggestion if I'm not getting I will delete the last one and try again okay so something is wrong it should be there because we have installed the socialite package if not I can directly get it via copy and paste boom so we are getting it and it says it like it's not available maybe I need to reload my vs code let's try that um seems like it is working great now if that is good we can just copy the second route and paste it and now instead of getting the token I will just tie them the user I will get from our GitHub so is this the only thing we need to do let's go more and see it says now authentication and store we will talk about these later but let's first see whether we are getting the user from GitHub or not first we need to go to this route and see what's going to happen so go to this route and make sure it is right hit enter and now it says that hey you have to go to the proper client ID and secret we don't have it so how do we get that so let's first go back to the localhost 8000 and then open the GitHub now on the GitHub if you click on your username go to the settings at the last you will see at bottom we have developer setting now on the developer setting you can go oauth application so because we are working with the oauth so click on oauth app then new oauth app and let's name it so I say level 10 course now what will be the home page it's localhost 8000. localhost 8000 any description yeah learning larval now what should be the Callback URL so remember this is the Callback URL but this actually means localhost 8000 slash the real one so http localhost 8000 then slash auth and slash callback like this once you are done with all these things click on register application and it says that it has to be proper so HTTP colon colon slash slash and yeah it's working now since this is working you can see now we have the client ID and obviously the client secret so copy the client ID from here and it's very important to put it inside the dot EnV so remember GitHub client ID this one now I need to create new client secret so it says generate new client Secret click and it need to verify and now you can see we have new secret so click on copy paste it and once again remember GitHub client secret should be here now what about the redirect URL we already have given it so we again simply copy and paste it that's great we have done the configuration is it now going to work let's see so I will open the URL and slay alt slash redirect hit enter and boom you can see we have the application name authorize level 10 course and then we have all these information and when I click on authorize sarthak Savvy because this is my user GitHub username and it says yes and it will redirect me back to the route which we have given the Callback route and on the Callback route we said that get the user from GitHub and then die dump and yes you can see we get the user from our GitHub so nickname name email Avatar everything is there this is incredible so once we have the user how do we get the user logged in what is the process for Authentication so it's given here inside the documentation so next important thing is authentication and Storage so once you get the user on the Callback we get the GitHub user so you can either create the user if not in your database or you can update the user information on your database so it says that first you need to have a GitHub ID field for your user then you also need a GitHub token or GitHub refresh token field these fields are not right available in our user model or user table so we can do this thing and then we will make the user authenticated you can also provide some scope for the GitHub user like you need the public repository you need the read of user access like that so lot of information you can do with the socialite you can also get the user so whatever the driver you're using or whatever website you are using you can directly get the token the refresh token expires in lot of information are available directly with the socialite package so you don't have to do much here but our Target is to just authenticate the user so how do we do that so you have two options either you can get the user by GitHub ID or you can get the user by the email so using the email you don't have to have the GitHub ID or token a lot of other things obviously if you need the token like to fetch the repositories for the user then yes you need the token so you have to create this field but what is the most important thing we need to do we need to authenticate the user so we're going to use the email only let's see how this is going to work first we have the user I can get the email like this okay so once we have the email I can find the user with this email if there is a user then we will authenticate it if not then we have to create the user so there is a another amazing eloquent function available called update or create so how this is going to work let's see so we say user model we need to import it then say update or create now is either going to update if user is there if not then it's going to create but how do this function know that if user is available or not so as a first parameter we need to provide the field which eloquent will going to match on the database so I will say hey find a email only and the email will be the email we get from the GitHub and then as a second parameter we will provide other fields if user is available with this email update the fields I am giving on the second array if not available then create a new user with this email and the data I am giving on the second array so we have done that now what we need we need to give the name and obviously the password so provide the name and just for making sure do we really have the name field and yes we have the name field we need the password also so name is also I will get from the GitHub and if you remember we have the name field here okay and we also have added an avatar field yes you can use this Avatar but since we are using the AI for creating the Avatar I don't want to update it next is the password and password has to be decrypted and we need to check if we have done that or not so yeah we are already updating the password with the Big Crypt whenever we store a new user so we don't have to use the Big Crypt we just say password as the password thing that's cool so this will going to return always going to return the user now once you have the user then it will it become really easy so we just need to say auth attempt and actually attempt not attempt what says login just to login and login uh user okay once we are done with this we need to return redirect to slash profile edit what's that so maybe we need to go to the login first let's do the login and login with sarthak at bitfunes.com password is password to the dashboard log out slash dashboard and that's done okay so this is done very easy stuff first get the user from the GitHub then using the user model we are checking if user is available with this email or not if user is available then update this field if not available then just create a new user let's try all these things and first when you go to the slash auth slash redirect hit enter and you can see we are logged in that's really amazing and this we have done with the help of this socialite package and that's really great but remember what's going to happen when we see the name name is actually sarthak srivastava and that actually name coming from the GitHub now suppose I am going to change the username so I'm going to change the username from sarthak srivastu to SAR text Savvy now if I save this if I reload you can see it now becomes such as savvy if I try to login once again it will update the username because we said that either create or update so yes user is available with that email address so it's going to update the password and the email so instead of update and create actually I need to fetch or create do we have the fetch or create or get or create something like that so let's go to the documentation and press the forward slash which is just on the left side of right shift and say find or and we get the eloquent orm and here we get let's search once again find or and yes you can see we have find our new first or new first or create update or create so yeah we need the first or create so it is either going to give you the user or it's going to create it so now since we have the user let's once again save this now reload and it's become sarthak Savvy let's log out and this time I say auth redirect and see what's going to happen yes the Samsung 7 name stays as it is because we said that if user is available just give me the first user with the email and that's it and this is how the authentication with any with any website using the oauth's thing you can do you can achieve with the social like package the last thing I want to do is instead of directly going to the slash redirect auth redirect I want to create a post request so this is going to be the post request and I say auth and redirect but this only going to happen when I click on login with GitHub button here so let's go to the login page so I will go to login Dot Dot blade.php here we have this form which is going to submit with a email and a password but Above This I need another form so let's create a form once again and this form as We Know is going to be useful to have a simple button and instead of normal button I'm going to use the X primary button like this and here I say login with GitHub okay that's good and this has to be uh submit button and method is once again a post request action is going to be let's create a name of that route and the route I will call is lock GitHub login okay so I say or maybe login dot GitHub how about that so go to the web.php at the bottom uh not at the bottom actually this one I need to say hey give a name to this one and name is going to be the login GitHub okay that's it let's try reload this page we have a login with GitHub and which is not looking good I know so what we can do we can make this at the center so how about text Center yeah that's good and I can just provide a margin bottom of 10 so that it will be staying away which is not working by the way um how about padding bottom okay anyways both are not working uh maybe we need to add another div but for now this is going to work so let's click on login with GitHub okay so I need to add the csrf field at csrf once again reload click and boom it's doing something and you can see I am logged in with the help of GitHub that's so amazing and so easy that I really love laravel and socialite package cool now let's move to the Amazing Project we are going to create with the Live Wire yes we are now going to start with larval Live Wire to start with our new project we first need to understand what exactly we have to create what is the flow and what client will need so I'm going to open this readme file and here I will say the project idea like this project idea so here the project idea will be like very simple first we need a ticketing system so I'm going to say like user can create a new help ticket okay so this is going to be easy then what about the ticket so there has to be an admin an admin can reply on that ticket admin can reply on help ticket also admin can either reject or resolve the ticket so admin can reject or resolve the ticket most important thing when admin update on the ticket then user will get one notification maybe via email that ticket is ticket status is updated okay so this is going to be super easy now let's talk about the ticket user create so user can give ticket title and description also user can upload uh document that could be a PDF file or a like PDF or image that's I think enough okay so this is all amazing and we are going to create this structure or this project from scratch using level 10. so once we have the idea all I can say the client need let's work on the table structure or first the schema so what about the schema what should be the schema of this project so think about that what are the things we need to store we need to store the ticket title and ticket description so with this information I get the point that we need to create a new table called tickets or maybe if you want you can say help tickets where tickets is good for me so what I'm going to say I'm going to say uh table a structure and first I need a table called uh tickets and in this decades I need one title then description obviously status is it resolve pending or rejected like that and attachment attachments could be the image the document like that okay and is there any other thing yes obviously who actually created this ticket so user ID like this so this is done for the ticket now we said that user can create the ticket upload the document but along with that there has to be some admin admin can reply on the ticket that means there has to be some comment section okay so we need the reply from user we need the reply from admin so lot of replies that means what we need a reply table so reply stable will have the reply body okay then user ID who actually replied and where that means on which ticket so we need the ticket ID okay so from this reading this we get these two things like yes um what's that so like yes user can create a ticket with the title description and some attachment if user want then admin can change the status also admin and the user can chat for a single ticket so we need the ticket ID like this okay and what else so we need to have anything else no so that's good but remember we said that admin can change the status of ticket this means we need to know like when admin has changed the status so either we can allow admin to reply and then change the status so why he is changing the Status or we can have another table for just for the status of the ticket let's think about it first so in my opinion there has to be one more field which is going to tell to the ticket that this ticket is the status of this ticket is changed by which admin so I can do something like this is status Changed by so this is again going to be connected to a user but this time this is connected to the admin user now how we will Define the admin we will talk about that later but maybe this could be status changed by ID so status changed by ID okay so that's going to be pretty easy things let's talk about the admin so either you can create a new table for admin or you can use the existing user and then add one more field to Define that particular user as admin but for now we will going to use the email ID to Define if user is an admin or not so there is nothing we need to create in terms of table structure so we are good to go with the table we need two tables one is ticket one is reply now on the reply also we can add some attachment now we can add that but I don't want to complicate Life by adding the attachment on the reply this is just a tutorial so let's leave it just as a text reply now let's talk about the type of this so this is going to be normal string or wire car or bar chart what you want to call this going to be the text or you can also call it Json but for me text field is good now status can be either 0 1 2 you can use the number or you can use the enums which will going to resolve to some value like open then resolved and then reject it like that this could be the as I said attachment now talking about the attachments so attachments basically are the URL of the file now if we want to add more than one attachment then we need to use it as a Json file where we should have the name and the path for the file but once again as you I don't want to complicate things so I'm going to use as a string and calling as attachment that means user can only attach single file either PDF or an image for single ticket now user ID and status changed by ID is going to be obviously integer and this is our structure table structure now let's now talk about the replies obviously body has to be the text one and user ID and ticket ID are going to be integers once you define all these things you need to Define one more important thing see when the ticket is created then the status has to be open by default so we need to make sure this is a default value okay and if this is complicated what you can do you can make it like this okay so this will be like this and good so we are good here so this one is the default one when user create the ticket user is going to fill title and description so these are required so required required okay status is not required we will automatically make it open attachment is not required because what if user doesn't want to add any attachment so it could be in the label so I can say hey this is nullable null able like this now user ID obviously this is required but filled by laravel because we don't want user to give their ID the logged in user we can get by level and it will be filled by laravel so filled by laravel and this one status changed by ID initially has to be null why because initially the status is not changed it's just open so it has to be once again nullable okay so that's good let's come to the replies here we are body obviously required because how will the reply will be created user ID obviously required but once again failed by laravel okay and then ticket ID this is really important so ticket ID obviously required but again filled by lateral and when I say filled by a level that means the coding we will do that it will automatically fetch the user ID or the ticket ID when we create the reply or the ticket user doesn't have to do this so that's why I said failed by liberal or I can instead say filled by back end so this is the structure we have given and now what we have to do we have to work on all these things and we have to create the migration now since we have all the requirements we want let's create the migration and create these two tables let's start with the ticketing and then after once we complete the ticket system then we will move to the reply now only target is the ticket so as we know we need to start with the migration so PHP artisan make migration and this could be like create tickets table so yes you can do that but let's get the help for it when you get the help it says that yes you can Define the table name if you want with a create but I can give you an amazing thing you know when we are working with any table how the data will be stored in the database and fetched from the database obviously we know it's a job of the model then how the data will be flow from request to the database or to the model it's the job of controller so obviously we need the model we need the controller we need the migrations for this tickets can we create all these things in one go or in one command yes we can do that so let's first search for make Command of make a model here we have the make model command now what's going to happen here when you get the help for make model command make model help it says various things it says you can create all means creating the migration Cedar Factory policy resource controller and form request class now apart from all these things we need yes migration right now resource controller and form request so we can create all these things individually if we need the resource controller so you can see it says give the hyphen R flag indicate generate controller which will going to be a resource controller now what is the resource controller we will see very soon now we also need a request so we need to give the capital r to create a new request form then we also need one more thing which is the migration and for that we need m so let's create a model called ticket now make sure the model always has to be the singular form of whatever your table name is our table name is tickets so the model name will be obviously ticket not tickets just ticket now with this yes we said that we need the migration hyphen m we need the resource controller so small R and we need the rig form request so capital r you can do like this or you can directly combined like this and hit enter now you can see it says that it has created the model the migration the request and request for storing request for updating and ticket controller wow that's amazing one two three four five files in one go and we can see where all these files are situated so first let's go on the app then models and here we have ticket dot PHP file and this extends the model class which is responsible to make this class as the model ticket model great now let's open the HTTP controller and here we have a ticket controller and I told you this ticket controller is actually a resource controller what do you mean by resource controller that means a controller which will already have the crud related function so crud for create update delete all these things are there now you can see some of the files like create and store so store obviously a post request create will give you the form for the for that particular for that particular create section of the ticket now that's really good for now I am going to remove this response thing because we are not always going to return the response this is actually fixed in the latest update of 10 version or if you just want to say composer update it will actually going to update the level version for the minor changes which is going to fix that thing you can see a lot of amazing changes are there and it's now upgrading so this is the way you can upgrade to the minor versions this means if I now try let's I can just do I can just select all and I can say discard the changes and now once again I'm going to run the command and this time if we see the controller doesn't have the colon response so yes you can use the composer update command to update the minor version of laravel cool so we have done all these things we have created all these things but the first requirement is to create the table and this table ticket stable we need to refer to this tickets structure we need so title as a string description is a text now how do we do that so we need to say dollar table and where's the documentation for this okay that's really important so go and search for my creation and here we are in the migration you can click on the column and then you can see we have a lot of available column so we said that this could be a simple string so is there any string so let's search yes we have the string you can click and see how we can use it so we just need to say table a string the name of the column and how many you can say characters it could be so if you are not giving any number it will take it as a default one so let's go and say hey I need a string column and this one is the title and I can just close this line and I can press Ctrl or command if you're on Mac and click on this string you can see it is giving length as null and this means it says that if you are not giving the length then I am going to get the length from this Builder Builder Builder default string length now go to the Builder Builder default string length is 255. okay so this is how you explore the level okay so once you get the title field what we need we need the next field as a description and it could be text okay now this is a text which is simple no need to do anything so table text and description okay that's once again done what next is the status so how about the status now status is always going to have the string so this is also going to be the string but now this status need or I can say only accept three possible values open resolved and rejected so there are various ways to achieve this either you can do that on the table label or the MySQL level or you can do that on controller laravel level what I prefer is to have the Restriction of these three field on laravel level why suppose later on in the future you're required to add another field then it would be really difficult to update the table structure instead of just updating the level code so isn't it really easy now this is going to have a default value so yes we can add a default value here default value has to be the open now so I can say the default here now once I have this I need to provide the default value for this what should be the default value yes we can say open but suppose later on someone says that hey it should be with a capital O how about that so it's going to be different so what we have to do we have to create a enum which will be for status so how this is going to work inside the app I'm going to create another directory called enums inside this I'm going to create ticket status Dot PHP okay and how do we create the enum so obviously if we need to first start a PHP tag provide the namespace so it's going to be the app enums that's it okay now it's going to be the enum enum is ticket status and this is going to have all the values so we need to Define different cases here so case open so open is equal to a string of open like this okay second we need uh another case or case what's that like this case is resolved so resolved like this and finally the case is rejected rejected okay so we have done with this so it says that okay so since these cases are resolving to a string we need to Define that hey this is enum is going to return some string okay that's it the enum is created so instead of directly hard coding this open here we can simply say ticket status and it's open okay like this that's it we need it and that's we done next is attachment obviously this is once again going to be the string so attachment and obviously this has to be like this string attachment but this could be nullable so I need to say nullable once again all the information is available in this documentation so you can search for the label so normal nullable is there and these kind of labels are there like this yeah you can see we can have the column as in the label cool so finally we need the user ID and status changed by ID this is extremely important so you need to take care of you need to understand this very carefully see we need to have a integer integer not interface in integer or I can say big int big increment no big integer and this could be the user ID but since this is going to be the relationship with other table with which is the user table we need to Define that hey it's going to have a foreign ID so we can do all these things but later will provide very nice way of adding a foreign key so we can search for foreign key constraint so you have to just say foreign key is user ID references like where ID on users table so on user table this you can do and it will going to work but you can do one more amazing thing so first you define the ID then you set up the relationship instead you can just say table for an ID is user ID and constrained now when you use the constrained method it will automatically fetch the table name from the column you have given so as I'd like user ID so it will say that okay you are talking about the table called users because you said the user's user ID so this is like from here so it will see checking for the first section of underscore and then pluralizing it and then making the table name okay so that's done what next the final status changed by ID this is once again going to be the same but status changed by ID now in this case this also going to be connected to the user but this is not going to get the username when we just say constraint because if this is going to try it out it will be like status changed by or simply statuses so you need to Define that here is the user user stable we are going to use but we have decided that this also going to be the label so we need to say that hey this is nullable like this okay so you can Define it and you can Define constrained a lot of things you can also Define the label like this and everything is in the documentation no you don't have to worry about this that's done so we have completed the migration how to write migration for complex things with the enum in this tutorial now let's run and see whether this is working or not so PHP Artisan migrate this is the command we know to run the migration so first let's open the table Plus and see there is no table called table tickets if I run it okay we get some problem now it says that hey the ticket status could not be converted to a string so when we use the enum we need to provide the value for this because at the end we need the string okay so one more time and yes it's done it's working that means if I now go and reload tickets table is here and if I check the status and check for status structure actually checking the structure and then check the status field it has the column default of open which we get from the enum wow that's really amazing so we have done that we understand how to create the table using the enum and let's now move forward foreign model controller and the migration that means the table we can start working on very simple thing which is a route which will be only accessible when user is logged in so first let's create a route to create new ticket so how it will be it will be like we need to go to the web.php and by the way web.php is inside the routes web.php and here at the bottom what you can do you can simply Say Hey I want to create a route and that route is going to be a get route it's not a post request and this will go to the ticket slash create now once you do that you can just return a function here which we're going to return a view and view is called ticket Dot create okay so that's very simple thing we have done but if I visit this route right now what's going to happen if I go and say slash ticket slash create it says that ticket dot create view is not available that means the blade file is not available inside your resources views and there is no ticket directory so let's create a new uh you can say blade file called ticket slash create Dot blade dot PHP okay so we have done that and you can see it has actually created the directory and the file now I'm going to extend this app layout so that we will get something cool so I'm going to extend this and like this and say hello for now if I reload it says that attempt to name property attempt to read property name on null that's happening because on our layout app we are trying to use some navigation and if I go on the navigation navigation need the user auth user name so since we are not logged in that's why it says that hey there is no authenticated user so how you can get the user name that means if I just remove this layout and then try yeah yes you can see hello is there but we want to use this layout because we only want authenticated user to create this ticket how do we do that we can take the example or we can take reference from the route for authentication we have we know all the routes are inside the authenticated uh PHP route so here if you see we have a middleware called auth we can use this middleware which is actually going to tell larval that hey to visit this URL user need to have the authentication okay so let's close this and we say that hey this is a get route but I just want to create a route with a middleware and this is going to be a group of route and inside this I'm going to have this route now what this mean this simply says that whatever this route is it only be accessible when user is authenticated now let's try this once again and you can see it's redirected me back to the login so let's log in with GitHub it's going to be quick and I don't have to say anything like username and password but now I will say ticket create and this time you can see hello is there wow that's really cool now since we are logged in that means if I now enable or add this layout thing it will going to have the header and the name is there everything is good and you can see the hello is there cool so we have done that why can't we have a text of white so class text white if I do that reload the page you can see hello is there wow so we have done that but remember we have everything for our ticket that means we also have a controller for this ticket so let's go and see on the app http controller we have a ticket controller in the ticket controller you can see there is a function called create because remember we have used the resource controller so if I once again say hey make model I think I need to write it make model and get the help it says that if you provide the hyphen R it will create a resource controller and what that resource controller mean resource controller will have all these function by default for you so now what we are doing on this create we need to return this View so get that paste it here now how do we call this create function so it's very easy when you do this route thing then you need to use a square bracket and then you say hey I have a ticket controller and on that this is going to be a class and make sure it is imported and then as a second parameter you can say hey I need a create method okay so that's it you are done with this now if I go reload the page and you can see still we are getting the hello here which means which proves that our controller is now working you know whenever you create any route you can get the information of all the route in your application by saying PHP artisan route colon list if you do this you can see you are getting all the routes you have for your application inside here so which route we are interested we are interested in the ticket related route so where is ticket related route so here we have ticket create which goes to that ticket controller create method now obviously when we want to store the ticket we will need another function so that function will be like a post request for same URL but this time it will go on the store method like this okay so store method is this one and when we submit the form it will go here again this is very simple very easy but once again if you go and check the route list now we have another route for creating the ticket but this time it's a post request and it will go to ticketcontroller at store now one more thing if you see some of the route has name given so like this password dot confirm password dot Avatar dot AI so we can give the name also how do we give the name we can simply say hey I need the name and the name convention will be like ticket dot create and we can give the name for this one is ticket dot store okay this time if we go and check the route list you can see we have the name and we can call these routes with their name instead of directly using the URL that's really amazing but as we know later on we will also need to show single ticket edit the ticket update the ticket and destroy this means we need all resource related routes yes we can easily create that but since we are on laravel we don't have to worry about that so I will go on the search for the controller on the documentation and here I will search for resource controller this is very nice and inside that we have seen that if we create the resource controller then it will have all this kind of routes all these kinds of function available but similar to Resource controller we also have a resource route we can provide resource route like this route resource give the name and the controller you want to connect with it so instead of doing these two things I'm going to say hey this is going to be a route of resource but it is going to be the ticket slash create no it's just going to give the ticket level resource will add create store whatever it need by default so then we just need ticket controller and make sure this time we don't need the square bracket once you are done with this you can see this is so simple and if you now go and check you have all the crud related thing related routes for the ticket ticket route ticket index to show all the tickets ticket store to show to store the ticket ticket create show update destroy and all these things are created with a proper method and with a proper uh you can say the ticket ID if you need wow so this is the this is called the resource route and since we have the resource controller everything is now directly connected but is this going to work let's see so we go here reload and yes you can see we are here that means everything is working absolutely fine so from now we don't have to worry about creating new route for our ticketing system now instead of going to the route we directly go to the controller do something and that will be reflected here one more thing you can do to make things more clean you can simply give like prefix and prefix is ticket now at this point you can just say hey this is a slash suppose you need something else ticket slash random something like that so then you will create another route called get route of Random then this route will actually be ticket slash random is this going to work once again go reload and yes it's working so cool amazing stuffs in laravel and now let's see how we can create a form here first thing is we need a button here which will be redirecting me to create new ticket and we will call it support ticket or open ticket something like that just go on the layout so for that we need to go to the resources views layout and navigation here we have the navigation and now we need a button so which kind of button we need we can use the button which will be like text input so there are some button here so danger button is there and I can use the x button which is inside our login so login is there X primary button so we can use that navigation links logo and then there's the drop down and maybe I can do something like this let's see how this is going to reflect it okay that's just really bad let's log in with GitHub so maybe I can push this inside a div so that it will not be full width yeah like that and now since we have this div we can give the class of flex and justify Center and Oops I did wrong I need to give Flex call also and yeah it's good now instead of login with GitHub I can say uh support ticket and this is actually going to redirect me so can I give href here like slash ticket slash create is this going to work so I can go to the dashboard click on this oops it's not working so I can check the primary button so primary button how this looks primary button could have the type is submit so it says that it can only add the type instead of this button I need an anchor tag so how about having a simple anchor tag like this and I need to then now design it so I can say text White or maybe instead of text white I can say BG White rounded large rounded large like this and something happened yeah it's good so padding of two okay so I need to reload it obviously yeah seems a little good and this is having an href of create ticket now if I click here you can see I'm redirected to the slash create ticket but instead of this I can use my routes so route is ticket Dot create now how do I know that ticket dot create is a route remember the route list for Ticket slash create we have a name of ticket dot create so now this just have the create because when we have created the route we have given the prefix of ticket and on the resource we don't have anything so you can also give the name so name is starting with the ticket and this solves our problem of having not having the ticket at the starting and seems like things are broken when we are using this so maybe we can just remove it and get back to ticket and okay so we are back with that sometime we need to change our logic and we are here so go to the dashboard click on support to get boom We are on the support ticket great so since we have this and now on this support ticket page we need a simple form would be like a normal form so I'm going to design it and I'm not going to waste your time on the designing and then I will come back so right now what I did is I just moved this as a normal text anchor tag and if I click here I have this nice form in this form I have used the title or the input field which is the X input basically I copied everything from the login page but you know larval provide this x text input component the blade component like here we have text input like this so this is good but we don't have any designing for text area and for the file input so how do we do that let's create a new blade component and see how we can customize and then use x text area so first we need to say PHP artisan and here you can find if you search for component component yeah like here this is that make component we're going to create a new component that's cool so let's say make component and we are going to call this text area or Simple Text area like this and I think that's it hit enter and it has created a new component inside the components directory that's really important so you can see it's having a text area Dot blade.php but at the same time you will also see that we have one more view file called text area now why we have this any component or blade component is combination of some View and some of the PHP file this PHP file is useful if you want to give some data to the component so suppose we have this app layout so you can see we have this app layout now if I see this app layout it actually rendering layouts dot app that's the only thing this app layout component is doing okay so this is how we can use the component PHP file to have something but what if I don't I don't want to do anything and I just say hey there is something here and what if I use here like X text area and that's it and let's go reload and you can see we have this ASDF ASDF which we have written here in our text area.play.php so what we can do we can cut this text area from here and go to that text area dot blade component paste it and it should be there like this reload and yeah we are back with the text area now we need to design this like this input field with having the black at the background and some Shadows some border like that so what we can do we can go to the component text input field and then we can copy some of the classes from here so let's start by having all these things actually we can get that and we can provide it here on the class of text area that's really great we are done with that and now if I go reload and yeah that's good one more thing we need to do is width of full so we can provide width of full so that it will take all the width like this great now let's create one more for this file or choose file let's first design this and see how we can do that so what about having all these classes so yes you can see it seems like it is doing the job and width of full we have given like that choose file that's good now only thing we need to do is move this into a component let's create another component called input file or actually the text input so it could be file input file input the component is created as file input and here we are so let's grab this input field from here paste it like this now one thing very important we have forgotten so first let's include this file input remember we need to provide the name and we are creating this component so that these will be reusable so we have to provide the name and right now the name and the ID are description which is not true for everyone so let's see how they have done here so what they are doing they are saying that first we need to say that attributes whatever we are passing will merge with the class give given so we need to copy everything and now paste it like this and the class value will be this paste it and now these two things the name and the ID will go wherever you are using the component in that way if we reload this page and inspect this text area you will find that we have the name and the ID for this which is why we have used this merge attribute thing okay so we need to do the same on our file input okay so let's do that like here type is obviously file these things we don't need but we will need that here on our file input let's reload check it and it should be available yeah name and ID is there that's great so this is how you create the component inside the blade inside lateral and making component reusable so remember we also have this component PHP files so these files are useful when you want to pass some data on the component like if you go on the create dot blade and suppose for this text area we want to provide the place holder now placeholder value should be like add description Now is it going to reflect so let's try that reload yeah it's there but this is the default HTML one what if we want to add something else suppose let's go to the text area and here we want to provide the default value and default value could be like uh default value is equal to hello world now how about having that here how we can do that so can we do something like this since we have passed that hello world and the name we have given is default value so let's say default and we are going to call it as let's say as a PHP variable and now let's convert it to just default not the default value okay now if I reload it's still now it says that hey undefined variable called default why is that because when we render this text area at that time level will first check on this text area.php that is there any variable called default and obviously it's not available so what we can do we can create a variable called public default and this one is going to be the string one so public string default so with that if I now go and reload you can see now it says that undef unresolved dependency resolver so basically it says that you are providing the default value which is hello world but this one is required this default value is required always so we can either provide some value as a default which is the default value is nothing so if I provide something it will be here but now let's go on the create and save this file and we are providing the default as hello world if I now go and reload you can see hello world is there and we can add anything and this is passing along to the component to the blade component via this PHP file so this is the real reason we have to create the PHP file or we need the PHD file for any component but in our case we don't need to pass anything so in that point we can just remove this text area we can remove this file input also and we are good to go because everything is working and we are not passing anything so we just need to get back with the normal text area and that's it so this is how we know that how we can create a new blade component and how to use that blade component let's now really store the ticket with title description and some file to install new ticket we first need to fill all this form and submit to a route but on which route we will going to submit it's very important to understand that for a form we need an action an action should be a route and since we are going to use the post request the route will be the post route for the ticket and we already know that this is going to be the store Route how do we know because we have used the resource route here and when we do the PHP Artisan route list you can see we have this store which is going to store our new ticket now let's open ticket controller because here we have the store method and the first thing we can see here is we have the store ticket request now this request is a form request file which is extending the basic form request and first to make this work for authenticated user we always say it is true we have no condition when we need to apply this request or this validations so on the rules I just need to say hey the title field must be required and it has to be a string okay second is description now description once again required and this has to be the string again third one is the attachment this is going to be a file so it is not required but it's going to be useful for sometimes and it has to be file and the file format should be some different so let's go to the documentation and search for validation and here on this validation part we will see that we have available validation rules here we should see we have the file validation now if I go there we can see we have this file so it says that it has to be a file to be a successful validation now which file we need so for that let's search for file maybe search for PDF do we have no we have jpg hmm so it says that it could be the Mi me type now what is Mimi type basically the type of the file we are going to accept so we can accept these rules okay so it says that the rule actually validate the Mi me type of the file okay so first we said that it has to be file now if it's a file then Mimi type could be jpg jpeg Maybe jpeg PNG or finally PDF because we are also accepting the PDF now let's done the the validation is done but still one thing is remaining if you open the ticket migration like this you can see we have given that string to be title title to be string off we know the length of this one is 255. so we also need to validate that the max length for this title should be 255 so max is 255. now what about the description so description is a text column and text column can have like many text or many character so we are not going to validate the length for this description that's good so let's now try to submit without filling anything in the form and we should see the validation you can say errors so here we have click on Create and it says that it has to be filled but what if we make it not required so we've made it not required reload the page submit and 419 that means csrf token reload create and now you can see title field is required description field is required and description field is required once again no it has to be file so attachment and attachment is sometime required so click click and it says the attachment must be a file and attachment field must be a type of this now the point here to notice is we are not selecting any file so why it is giving the error we said that it's not required some time needed because when we are dealing with the file it has to be the file input and the form has to be the ENC type of multi part form data okay like this so reload and now if I click create you can see it's not giving any error for the file but what if I choose a file which is not a PNG jpg jpeg or PDF so this time if I submit you can see it says that it has to be the format of this thing okay so we are good to go with the validation and now we need to store the ticket so how do we store the ticket so first we say hey there is a ticket variable and ticket model we will use and then we say create and inside that we say that hey title will be will be the request title description will be request description and attachment we cannot say like attachment to be like um request attachment because it's a file we need to store it so let's first see without storing the file and then we will see how we can do that so once the ticket is created we need to return return response response and back with a message that either we can reply return to the back or return response of ticket now let's say something something something click on Create and it says that the mass assignment issue so we know how to solve this on the ticket model we just need to say fillable is equal to title and description and also attachment if there is and it has to be protected okay that's done reload this and now it says user ID doesn't have default value so we can do various ways we can say hey user ID is going to be the authenticated user ID okay that's good we have done that now one more time reload and it says user ID doesn't have default value why is that we said that this is going to be the user auth maybe we need to fill this also user ID okay one more time reload and yeah you can see we have the ticket so this ticket is now created and we are really grateful with lateral things that it becomes so easy now there is many ways to refactor this but before refactoring I just want to show that what if we upload the file and we have to upload the file into app Storage Public and attachments directory and then on after that we will store the path okay so we know that there is a avatar controller we have created we can grab the code to store the attachment from here so this is the one and it is like this so we need to copy or import the storage now it says that you need a file name so now we need the file name how do we get the file name we get the file name from Avatar control so we have this file name and obviously the content also so copy that go here and paste it so here we need to import the Str so use Str and it has to be the eliminate support SDR and then we need the result and actually we don't need the result we basically need the file so we know we have the file which is request file and then attachment okay so we have everything but remember this is not always going to be the jpg so we need the extension of the uploaded file how do we get the extension so let's just to check for the extension so here we go and we say file attachment and then we simply say extension like this now let's go here and fill the form choose a file here so let me choose this one click on Create and it says result where's the result oh I forgot to save the file so you see this white dot here which represents this file is not saved yet so I save it reload and yes you can see now we get the jpg so this is the actual extension so what we can do we can say like EXT which stands for extension and then we can append that extension here so file name dot whatever the extension is but we will do all these things only if the file is there so file of attachment if it is there then only we will do this thing now here we see that Avatar file extension this is the path but basically this is not the Avatar this is attachments directory and this could be the exact path so why not create a path variable like this and then put it here like this and make sure all these things in the double quotes and we get the path and we just need to store this path only so we want to store this path so we say that there has to be the path but remember if there is no file then what will be the path so what we can do we can first create the ticket and if there is the file then we just update the ticket so we say ticket update attachment is equal to the path that's it so it is going to save and update the ticket all if there is an attachment only now see in the public directory we don't have the attachment directory so now let's go back create second ticket some description and now choose the file and let's choose this file click on Create and you can see attachment is there and it's inside the attachment some random file name dot jpg and now if I see yes you can see the file is there that's great and this means the ticket is created and attachment is also attached cool so this is how we do things but we don't want to redirect user here we want to redirect to the users ticket list so what next we just redirect response and then redirect to essay response redirect to a route and Route name will be ticket dot uh ticket dot show not show actually maybe ticket dot index where all the ticket will be available so ticket dot index is here okay so this should be the ticket redirected to the route and Route is this one and is it the route or it's not the route name it's the actual route so maybe we can just say redirect to a route like here good so this time if we check for this it's the name of the route cool we are done with this and now let's see how we can redirect and show all the ticket for this particular user now it's time to edit any ticket so if I click on the support ticket we have the tickets we can visit the ticket we can go back but what if I want to update something on it so if I visit this ticket so yeah I have to get a title the description and the created add date how about having a button which is going to edit this ticket or we also want another button to delete this ticket let's do that first we need to visit the single you can say ticket file so that is inside the resources views and then we have a ticket then we have a show dot blade here at the bottom we can show the ticket detail so here we can have one button called edit and another called delete so let's have X primary button and I call it edit and another delete nice and if I see yes edit and Lead button are here but when I click on this edit button it should redirect me to the edit page but before doing the edit I think delete is easy so let's do that so when I click on this button it should submit a form which will submit a delete request to our route of the delete so if I see the PHP Artisan route list you will find that we have a delete method where we have to give the ticket slash ticket ID and the route is ticket dot destroy which will go on ticket controller destroy method so how do we actually do that this is this seems like difficult thing okay so what we have to do we have to first create a form here and this is going to be a post request but we will make this post request as uh method and method is delete and make sure we also need csrf token and you know the route will be the route will be the ticket dot destroy now we remember this ticket destroy route need the ID so how do we get the ID we already have the ticket and then we can fetch the ID simple and now this button will come here okay so we are good to go and just try to click on delete and you can see it's actually submitting the form so if I now go to ticket controller and there is a destroy method inside this destroy I will going to just diadem the ticket we will get from here click and yeah we are getting this ticket so it's going to be easy to delete this so this is very easy ticket delete and once we are done with the delete we need to say return response or redirect redirect back I mean to do this redirect back like this or you can simply say like response uh return redirect back okay so this is done and you can also give some kind of uh message but redirect back is not going to work because it will try to redirect back to ticket slash one and ticket slash one is not available because the ticket with the idea of one is deleted so we need to actually redirect to a proper route of ticket index okay so that's good and let's see if this is working or not so reload this page click on delete and you can see that ticket is really deleted so how about having this ticket in the ticket delete button has to be on a single line so I will say div and this div will be having class of flex and see this great and space Space X two okay so that's not working so we can do one is here we say ticket left of margin left of two good so this seems like really great way of deleting any ticket click on take delete and it's just going to delete it that's so easy isn't it now once we are done with the delete it's time for the edit foreign to show all the tickets on the users page so here we have support ticket where we actually create the ticket but instead actually what we want to have slash ticket and when I go here it should give me all the ticket for that logged in user so first let's go to the web.php and we know there is a resource route that means if I just check for the resource route by Route list you can see okay I need to do this you can see we have a get request for Ticket only that will go to the ticket controller on the index method so let's go to the index method and here we are not doing anything so let's try to return a string here and see is this reflected yeah it's there that's great so first let's change the navigation and the route will be ticket dot index and if I now go reload click here yeah we are here great now here instead of this string we need to return a view which will be like ticket Dot index which is basically mean ticket dot list all the ticket so let's go here on the ticket let's create one for index so just copy and paste this file and we call it index okay that's great so in this index page we don't need this form what actually we need we need the list of the tickets so first we reload and here we have a title so title should be your support tickets support tickets and this is so this looks good but what next here we need to use a loop so how do we use a loop inside a blade file so go to the documentation search for Loop and we get this blade loop system and here we are so we can use the for each Loop we also have other Loops here but for each Loop is really handy so let's try this so for each Loop and here we are going to say tickets as ticket okay like this okay and now I will use a div and inside this div I will use a P tag inside this P tag I will show the ticket title okay that's great so let's try that and see what happened right now it says that hey you don't have the tickets variable so why we don't have this because we are returning this index dot blade dot PHP basically the view file from our controller and this view file doesn't have any data so we need to pass some data which is the tickets available in our database so first let's say that tickets is equal to we get the ticket for all the ticket from our database and it's very easy yes with eloquent you can say ticket all now we have this variable and how we can pass it to our view it's very easy you can use the width function and here it says first you need to provide the ticket or the key which you want and second is the value so if I now go reload and you can see we have this ticket now it has to be white colored so in this div I can say text of white yes this is good now we also have various other ways to pass this data to our view one is obviously this width second inside this you can simply say as a second parameter you can pass the key end value so it's a simple array going to be the tickets and the value is this tickets variable now if I now go reload yes you can see everything is working fine there is one more amazing way of passing any array which is using the compact method here inside the compact method you always provide the variable name as the string and it will convert the tickets and the tickets value to the variable or to the array something like this okay so I like this compact method and if I now go reload that's great it's working next is I want to show the created add date so here just after this P tag I will use another P tag and here I say tickets or simple ticket created at now this created at it has to be created this created ad is handled by laravel so whenever we create any data store anything or update it's just change the value of created ad and updated ad respectively okay so this has to be in the single line so I will use a flex justify between and yes it is good I also need to provide some padding so that it will look good padding of three is good for me but it's not working so maybe padding off 4 I can give yeah it's working great so we have it but I don't like this one because it's not readable you know every time stamp field on laravel is an instance of carbon PHP Library so I search for carbon date and here simple PHP API extension or a simple package Library whatever you want to call to manipulate the the date and the time so you can do a lot of things with this date and time thing and here we have very nice thing which is for diff for humans now what this diff for humans do diff for humans is basically going to basically going to give you the created at how many times before so what that mean is if I change a function called diff for humans if I do this and reload you can see it says one hour ago for a two minutes ago like that great so this is how we Show the ticket on the ticket list but obviously we need to see the single ticket so we need this link to be clickable nice so how about converting this to an anchor tag and this anchor tag will move to an href of a route route of obviously tickets ticket dot show because this time our task is to show the single ticket so if I do this reload okay now it says that hey you want to show the ticket but which ticket so now amazing thing comes when you go on the resource route and check for all the route list you can see when we want to show the ticket we also need to pass the ticket ID how do we pass the ticket ID here so whenever you use the route if you see the route so maybe I can show you by going here second is we need we can pass some parameters so what parameter we need here we need the ticket ID so ticket ID comes here now if I go back like here reload it says that ticket dot show one oops it has to be comma not the DOT like this okay so these links are now clickable and when I click here so you can see the route change to ticket slash one if I not click on second one it's now converted to ticket dot two and two and one is the actual ticket ID so this is how we change it now on our ticket show we don't have anything so what we need one more View and this time this is for Ticket Dot show and you can see I'm using the exact naming convention which laravel uses this is actually useful when you want to search things so if you want to search for show function yeah here's a show if you want to check for the route of show there will be available then route name ticket dot show the you can say the file or view name ticket dot show everything will be easy to find now let's now uh create it like this and this time I will say hey it is a show now instead of create maybe what I can do I can remove this one and I can copy this index instead of create one now show is here and this time you can see we already have this ticket how this come so let's now see what actually we have in this ticket then we will work on the you can say on our view so first when I click it actually fetch the user fetch the ticket hmm how that came we have not written any query to fetch the ticket so let me show you one amazing thing in laravel we have this route list and you can see the ID is not the name ID it's actually written as a ticket so what if I remove this ticket model you can say a reference From Here and Now go and reload it's giving me one which is the actual ID what is happening here so see when you are not uh like defining what this ticket is laravel will treat it as whatever you pass so if I am passing some string you can see it's giving me as it is but when we say that hey this ticket variable is actually a ticket model this is laravel called route model binding so if you go on blade file or on the documentation and search for route model binding here we have the route model binding so it says that when injecting a model ID to a route or controller action you will often query the database to retrieve the model but laravel route model binding provide a convenient way to automatically inject the model instance basically it says that it automatically fetch the model instance for that particular ID so whatever the name you have given here it has to be exactly same variable name if you are using ID here it should be ticket ID but since we are using resource controller and these things are given by laravel itself we don't have to do anything and that's how we get the full ticket when we try to fetch one now this one uh one ASDF it doesn't have anything so if you see uh it's a having here and now the powerful thing is that it's converting one ASDF into the ID so if I remove this one from here it will say hey not found because that ID is not available and it was working before because it converted to its number from this string so it has actually removed all these things and getting the one only and that's how we get this ticket that's great so since we have the ticket what we can do we can simply use the compact method and pass our ticket to the show blade file when we have these things now we don't need the looping system and we can actually uh convert this once again to A P tag so that it's it's having the title and now if I go reload and here we are so if I go to support ticket yeah we have the support ticket now if I click on ASDF here we are now instead of giving this title here I want to give the title here so it should be like ticket title reload great now here I want to give the description so comes the description like here here's the description one hour ago and obviously the file if there is okay so how do we do that so first we need to create a simple uh maybe I can say anchor tag yeah anchor tag will be good and this will going to have say attachment attachment and this will going to convert or have a link for Ticket attachment let's see what's going to happen and I want to open this in a new tab so underscore blank Target reload here's the attachment if I click okay so nothing is happening so what actually given so attachment is having an href of ticket attachment something is not good here so if I click why is giving the ticket one maybe I can just go and die dumb the ticket and see what uh attachment we have so attachment is null actually so that's why we are not giving it so we first need to say if condition like at if we have the attachment so ticket ticket attachment if it is there then show it otherwise not so endif that's once again great thing so go it doesn't have anything on the second ticket yes we have the attachment so click and it's not available we will find out how we can show it so basically we need to show from Storage also so I believe it should be like uh storage slash okay so that's not working so maybe I can search here like where is that so app public attachment and it's there and if I go from Public Storage attachments and that's the file name so public attachment how about the how we are showing the user image storage avatars so basically we just need to directly go and say storage slash attachments and yes we can see we have that file we have uploaded now so we need to convert this into a proper um proper you can say file name so it has to be um I can say I can wrap it and say public or I can say simply um use the storage so storage slash storage dot ticket attachment and yeah like this so once again click on attachment and I need to pass one forward slash click and yeah it's working great so this is how we show all the ticket and single ticket values with the attachment now let's work on the edit part very seriously we have to work on the edit but when I click on the edit button it should redirect me to uh route where we can have the form to edit so I'm going to have an href where I should have a route of ticket slash um edit okay now ticket slash ticket dot edit will take you to the edit method which is here and here we are going to return a view called ticket dot edit yeah it's not available but it's going to be the exactly similar as the create one but this will have the name of obviously edit dot blade and it will say update support ticket and then we need to have all the ticket information here but how do we have that remember we can pass the ticket detail from here and also we need to pass the ticket ID so that level route model binding will going to work so how do we do that it's very easy once again here we need to pass the ticket ID and once the ticket ID is there that means we can simply pass using the compact method of ticket now this name and this name has to be the same now since we have already passed the ticket that means on the edit dot plate we can have it now how do we edit it remember the edit one is this one actually update so we need to submit the form to an update method but what if we click on edit let's see so reload click on edit and you can see it is now loading the edit form but we need to give the title and the description here so here we need to give the value for this input will be value is ticket title and we know this ticket title is coming from the controller so it should be there but something is wrong so what happened why it's looking like this okay so we can see what wrong we have done so we need to use the bracket inside this double quotes and yes we can see we have this title same we have to do with the description for here go here and description now it should be the description but if I spell it right oh so this is not a text um input it's a text area which we have created remember so text area dot blade now it says that hey it doesn't need any uh you can say it's not having any value thing you have to provide it here so if I say like this you can see it is here but how do we make sure that whatever we pass as a value it will be available here in between this tag remember this is a text area and this is a component so we can actually use the text area component PHP file which we have deleted remember so what we can do we can say PHP artisan make component and component name is text area so what we are going to do we are going to create it but let's see is first help so it says that you can only create the view and you can use the force method let's see what's going to happen when I try to recreate it it says that view is already available and component is created that's we want so now we have a text area this means we need the public value field okay so value field should be available when we pass it on our uh you can say on our component as a prop so I say this value is equal to the value okay now let's see what if I say hey there has to be the value if provided otherwise value will be uh null okay so see what's going to happen and here we have some description that's cool we are done with all the data now that's okay and here we have the attachment now attachment we cannot show here or or we can just show us a little image above the attention uh not attention attachment so I can use the image tag if it is an image so one is like we need to maybe what we can do we can just have the same kind of um you can say view button so that user can see what attachment it has so if I click on attachment it will open it like that this could be the this could be another solution classes text white and I can say uh see attention why attention see attachment like that yes so if user is comfortable with this that's okay otherwise he can choose another one great so everything is done now what we need to do we need to submit this form and we need to say it's a update we need to submit to a post request but this actually a patch request so I say method is patch okay and this will actually submit to slash update with the ticket ID so that route model binding will happen on laravel level so here we have the update method and we have update ticket request also we can use the same store method from here copy everything and go here paste it make it true and it will going to work now what we need we just need to say hey take it update and request validated now what is validated validated means if everything is passing this value this rules then the past field so if ticket is passing then it will come inside the validated so that's the use case of validated okay so we need to just make sure we end it like this and then we say return redirect to a route of ticket index like here that's good and try to update it so second ticket updated and click on update and yeah you can see it's updated wow that's so easy and so amazing now what next next is we can try to update the description update description yes it's yeah updated final attachment now attachment is going to be little different why first is we have to check if there is an a new attachment or not so if there is an attachment then we are going to first remove the old file and then add the new file like this so it's going to be the similar process but before this we just need to say delete the file so we are done we are done this on Avatar so you can see we have this and we can delete it so obviously if there is a new attachment we want to remove the old one so we can say hey old Avatar which means ticket [Music] um ticket attachment so it's going to remove the ticket attachment and then it will going to create another one like this if we provide the attachment okay so right now if I try to select this one click on update so it seems like some everything is done and what if I check the attachment yes you can see attachment is now this fifth uh thumbnail now if I change it once again and check it's 13th great now one last thing we need to verify that if everything is deleted or not that means if I go on the attachment and you can see we are having all the files available there that means it's not deleting the old attachment file so why that happened so this is not deleting because when I send the attachment on the ticket it's actually updated on the ticket level so what we have to do we actually need not to actually you can say we don't want to update the attachment data when we say ticket update so what we can do here so we just need to remove the attachment thing from here or what we can do we can simply say that hey I need to give the title here as the array so title and similar to the title we can provide the description so here we are and simply we say description and we are not doing anything with the attachment and then we will say that hey I need to update the attachment also okay so let's try this now select the file and need one click on update yes it's updated that's cool but we should see we don't have we have it that's bad so one more time let's try this one so edit this time ninth one okay so it should have only one which is ninth yes you can see the 8th is deleted now this time try the 11th it should be only 11th one yes so this is how we do the update of not only just that Fields but also for the you can say for the files but here final thing you can see this part is exactly similar to this part on the update so why can't we just have on separate function here and that function has to be protected function store file or store attachment like this okay so what it need it needs the request break q u s t request and it need the ticket cool so we can use this function at this place so again this store attachment with request and ticket and same we have to do here because we are doing the exactly same thing so we minimize the code repetition and we are following the dry principle wow that's really amazing and this is how we work on the Crut part of our uh you can say of our ticketing system now everything is done the next important thing is we need to make sure uh some user has to be made as an admin and then admin can change the status that's it and we are done with our course of this module so it says that ticket here so user can ticket user can create new help ticket that's done user can give title description document like these three are done then admin can reply admin can reject and when admin update it will get notification so three important things are still remaining cool let's move let's start working on the admin section so in our user you can say table we don't have any field call is admin or how do we Define like someone is an admin for now what we can do we can create a simple accessor on our uh on our user model so let's open the user model and here I'm going to create one accessor for admin and then for now I'm going to return the email so let's create some protected function called is admin and this is going to return attribute and after that we simply return and say attribute attribute and make and this time I just need a getter and getter will be for will we have a function where I will say that if the current user that means this user email if that is including in the admin list so I can say admins email is first sarthak at bitfilms.com we can add any number of admin you want just by adding the email so I can say this email if this is included in the array so I can say array include or in Array actually in Array so this is first looking for the email and then for the array so first it will get the email and second the full array so if this is inside the array then it will return true and this will get written true and otherwise it will not return true okay so how do we check it and what this says okay so we don't need the semicolon we need semicolon here now how do we test it so let's open the Tinker so PHP Edition tinker and first I will get the user and user where email and you have seen something weird here and this is not actually weird it's really interesting whenever you want to look into any field you can just use where email this is a dynamic thing so this where email is not a function available it's a dynamic function it will create it on the fly it will check for the field after the where word so we should get the user and to get the user we just need to fix it like here and we get some user so let's say user user is not available because one more time we need to say here first yeah we get the user now we say is admin and we get true wow this is how we have created an is and win uh you can say getter okay accessor now since this user is an admin that means if an admin visit this ticket then he should have two button approve or reject simple so reject means this is an invalid ticket approve means whatever this ticket is asking for has done great let's do that so let's go here and first open the ticket to show so show ticket is here now we have edit and Lead button now we need two more button one is for accept second is for reject so let's do that but first I will move these two button into a flex and I can do like this and here I can simply paste the button two times but once again into a flex so that these two align one after another and I will say prove reject and then let's see how this looks okay so this is good but here I need to say justify between and this will make edit delete on the left approve reject on the right now this will also need a class of margin write-off two let's see and it's not working so what about having margin left off to either and try it yes this is working okay so these two buttons well just going to send a form request and that will change the status of this ticket but before that we need another user which will be acting as the creator of the ticket okay so I'm going to remove this ticket because the admin will not going to create the ticket so let's just open this in an incognito window register new user so I need to go to register and this time I will say bit fumes so bitfumes at gmail.com password is password click on register yeah logged in click on support ticket but we don't have the button to create the support ticket so if there is no support ticket we need to say uh you don't have any support ticket and then we need a button to create it that's really good so let's go to the index of the tickets and here we have this support ticket and we will move this into a div and once again provide a flex justify between like this and then inside the div I need to have the button which says actually an anchor tag anchor tag will be like this which will redirect me to the route of route will be the ticket create like this one and I say create new okay let's see how this looks okay so this is okay maybe I can give width of full oh no not that full so so maybe I can say this width like here anyways some issue on the width okay good so that's nice and finally we can create some text uh maybe BG white rounded large like this padding of two great so this is good and it will take me to the oops where is that in the text area okay so that is in the create so here we have create and we don't have the value defined here so value will be null or not null empty string okay so now click on Create and yeah we are here that's good so last thing is if there is no ticket so then we need to say hey we don't have you don't have any ticket so first the tag will be uh you don't have any support ticket yet and that's will be like this and obviously text of white cool but this will only happen when there is no tickets so yes we can say if tickets uh tickets account like this is zero then only we will do the stuff okay that's good but what if user create the ticket my first ticket this is my first ever ticket click on Create and now it says that redirect does not exist so I did some silly mistake ticket controller and when I store it should be on the store response Factory redirect okay so response is not there it's just the redirect and submit so there is two ticket so I need to remove the great so everything is good but you know if there is no ticket there is a for each Loop but if you open the level documentation and search for blade here let's search for for each Loop in the for each Loop we have one thing is I think empty is there for else this is for else and then empty and then we can use the forels okay so instead of for each we can say for else and then we can move this part at the empty level in that case we don't need that ticket and see everything is working great now this is good but if I go here see yes we have the ticket now user need to admin need to click on approve our reject so what we need to do here first we need to make sure we have two form which will submit and then these two form will update the status of the ticket but before that what if the ticket is neither approved nor rejected that means it's in open state okay so if I go to the ticket model remember we have created a ticket enum ticket status enum so open resolved and reject it so if it is nothing that means it's open so what we have to do we have to provide some kind of information like if it is rejected approved or open so here we can see that this approve and reject button are available for everyone but we just want this button to be available for the admins so this section will only be running if authenticated user is admin otherwise we are showing nothing like that so this bit fumes user is not an admin so you can see it's not there but what about here yes you can see it's there but this is the chance we can show the status here just below this timestamp now I can use the else on this if statement so else we can simply say the status so ticket status and here we can provide text of white and it's open how about saying status as open right that's really great now so let's create a form here and this form is having a method of patch and this include only one button which is called approve now what about the action how we will update the status so we will use the same ticket dot update method because if I go on ticket controller go to update method we are having a title description like that but we can also add another field called status here and then we can use all that so how do we do that thing so first thing I will do here is instead of providing the title and description every time whenever we are providing the detail what if I can just provide the fields which are available so suppose I am not giving anything so if I die dump request all let's see what's going to happen when I submit this approved form okay so make sure we have csrf and the method is patch let's go reload and it says hey you need to provide the ticket ID also so ticket ID reload click on approve and something bad happened I think we need to provide it method is post not the patch there so yes click on approve and it is redirected back why is that because we said that title and description are always required but that's not the case what if I don't want to update the title or description like that so it's not required if you are giving then it will update so let's go and click on approve and you can see we don't have any field which we have provided now this is a chance we can provide a hidden field input field is hidden name of this field is status and value is rejected and actually this is a proof approved and that's it so let's go here reload this page and try to click on approve and you can see we have the status approved now similar to this we have to do for the reject but first let's see is this going to accept the status no we need to add this on our requests so here I say it has to be the string and that's it now now what if I just say instead of accept remember we don't want to pass the attachment so I can simply say accept attachment Give Me Everything Okay click on approve and status is there so if we pass the the attachment that's not going to work so here get that like here delete and paste it great this is done and now if I click on approve and check here status okay status is not not updated why is that so if I go on the ticket you can see the fillable status is not available so I need to make sure the status is also fillable once again click on approve let's reload and yeah Status is approved wow that's really amazing so this is done but what if someone changed the value to anything else now let's see what's going to happen click on approve and that's really bad this is not we want so we need to validate that hey only the value from an array is acceptable so how do we make sure that we are accepting or we can say we are accepting some of the validation from array so if I go here provide the available validation and here we have in Array so here we provide the in Array so under the field must exist inside the inside this array so I say in array and this is the one which is going to provide here we have to provide the array so I think it's just in yes this is the one so we have here so rule in and then array that's the one we are looking for so rule in and now provide the array but how do we get that array yes we can provide open then reject like that but we also have the ticket enum so ticket status enum and this should give us the array so and then we can say cases so cases is the name of or values of this we provide okay so once again go here click on ticket and this time let's see if I have something else click on approve it's saying that object could not be converted to a string okay something is wrong here okay maybe I need to just remove it and now it says Str replace that's not good so here we can simply say array column and then for this case we just need the values okay now let's reload and you can see it's redirecting back because it's having some issue now let's fix this and make it approved reload click and it is giving still giving error so once again let's get and die dump here so when I this case so not values it just have to be value yes like that okay so let's fix this and it should be working wow this is done and now status is approved or actually resolved now same thing we have to do here on the reject part so this is going to be an hidden field like this but this time it's rejected and like this or I can say resolve and reload click on reject and approve is rejected wow so that's how an admin can change the status of a ticket now one thing we have to do is we have to send an email notification to the user who has created the ticket once the admin update the ticket that means change the status and then you will say sarthak we have decided that we will work on the reply for this tickets so this is actually an assignment for you so what you have to do you have to work on the reply part for each ticket where admin and user both can reply admin and user can reply on the help ticket that one you have to do and once you do that take a screenshot or create a gif of that and go to the Instagram tag bit fumes it's really important to tag bit fumes and then this is the way I will get to know that you have completed the assignment and you are learning very fast because if you are just following me you never going to learn things properly you have to create something on your own okay so final thing we have to do is just send one notification for the user who created the ticket so let's open the ticket controller and here when we update the status so here we are doing something we are updating the title description and status but only if the status is changed we need to trigger a notification so first let's see how we can do that we simply say if request has a status field so if there is a status field that means we are updating the status now we need to trigger the uh you can say trigger notification so how do we send notification so yeah spelling is wrong but we need to work on the notification so let's go to the documentation once again and search for notification if you go here level provide a seamless experience of notification sending the notification how do we do that we have to create a new notification class and we have to provide some name and then we will see how we can do that so let's open the Tinker another thing a terminal actually so PHP artisan make colon notification and what should be the name of the notification so name of the notification is ticket status changed notification yeah so take it a status changed or ticket updated ticket updated notification great now where this notification is available if you go on if you go on our app notification and ticket note updated notification is here okay so that's great how do we send it via email so there are various channels to send the notification so there is a channel for mail you can send an email you can send you can store it on the database you can broadcast you can send SMS slack lot of amazing thing you can do with that but we are interested in the mail notification so you have to use the two male function where you define the structure or you can say the design of the email and that's very easy you can simply do that okay so how do we design this so first you have to greet so here you go so here we have a two mil and we say greeting and I say hello and hello the user name so what we need we need the username inside this notification so when we send the notification we have to know that who is uh to whom we are sending notification so for that this is notifiable is the actual user which to whom we are sending the notification so you can simply use notifiable name so we can do that and we can use the double quotes and then say that notifiable email that's good and we need to say the line is ticket is updated and then we can redirect user to a particular ticket so we have to say route of ticket dot show and then we have to provide the ticket ID now how do we get the ticket so we need to accept the ticket so we have to say this ticket ID that means here we have to create a public ticket variable and we can use the simple Constructor way so public ticket it's done and this has to be a ticket model like this and that's it and this is the power of new construction or Constructor actually and that's good thank you for using our application that's great and the tickets ticket is updated and we can provide the text as check ticket and this is a action button okay too much of things on the notification I know this is confusing and if you don't want to send it to the database just remove any uh other function now how do we send the notification so go to the documentation at the top you can see we have a sending notification so we can use a very nice way of using the user and a notify function inside that we provide which notification we want to send now why this is happening because in user model we are using a trait called notifiable so let's open the user model at the top you can see we have the notify able so if I press come command and then click you can see it says has database notification and here we have all the things about notification and then route notification where we have the notify function and this notify function is actually used here in the user notify that's great once again okay so how do we actually do on our notification remember we have the ticket controller and inside ticket controller we have ticket user so how do we get the ticket user so we have the user ID so we can say user is equal to user find and finding with ticket user ID so we get the user from the ticket and then we say user and notify new ticket updated notification and remember we need to pass the ticket instance also this only happened when there is a change in status okay everything is done now let's try to send a notification by changing the Status so let's click on reject okay so now this time it says hey you are trying to send a notification which is a email notification but you don't have the email configuration okay so how do we do that so first if you go here it says that you have to configure the email so we can actually do one thing which is like if you scroll up and here we have preview mail notification so we can just preview the mail notification without actually sending the notification so here we have and we can simply create a route which is going to check for the notification and then it will return the full notification so so how do we do that so remember we are doing everything here so we can simply return it that's the thing so instead of that we need to just say new notification to mail and like that so instead of returning I can simply say hey just return and new ticket update notification passing ticket and then say hey this is going towards the user and like that is there anything wrong I did okay yeah I have to do it like this okay so that's done and once again I can try it so click on reject and you can see this will be the email preview so ticket is updated click on ticket it will take you to the ticket uh page and thank you for using application regards with film course great everything is done so this is how you send a notification but still I am not happy with that I need to see the actual email sending now in level if you really want to send a email then you have to do a little configuration on your dot EnV file so how do we do that simply you have to open the dot EnV file and then at the top you will find a mail configuration so mail is SMTP and the mail host mail Port username password everything now where these things will go remember we have the configuration for email so if you click on config you have a mail config and here the default mailer is SMTP as it's given and then there are some configurations so SMTP configuration need all these things you can also use the SES that means Amazon SES you can use mail gun postmark send great log everything is available but we are interested in SMTP configuration so you can Define your email clients configuration here but we don't have the client right now and we don't really want to send the email notification so we have a very nice uh you can say uh a website or tool called mail track or you have Beyond code hello so if you go and search for Beyond code hello this is a web this is a tool you can use to test your notification and same thing you can do with the mail trap I like to use the hello but for you I'm going to show you how you can use the mail trap which is easy to use so just log in with any Gmail account or you can use the git then just clear out everything now see here we have the integration so click and search for laravel and here we are we have all these things so copy that go to the dot EnV file and then just paste it and everything is done so that's the only thing we have to do this is so simple yes now if you have e server running whenever you change on dot EnV it will automatically restart it that's good and now next thing is we need to check if it's really sending the email or not so click on reject and it's taking time that means it's sending the email and you can see it's done that means the email will be here and you can see this test updated notification email is here and this is how it works okay so this is we understand everything is good but now you will see that we are doing one really not that good thing so we are finding the user with the ticket email but with the laravel provide some eloquent relationships so relation so here we have the eloquent relationship what that mean this means that we can connect the user table and the ticket table and in that case we don't have to say directly the user we can simply say ticket user and notify if I now try to do this thing it will not going to work so let's try to resolve it you can see it says notify or null because it's not available so how do we create the relationship and what is this relationship called so see how do we Define it so let's open the ticket and the ticket is a single thing which can be created by a user so in other word I can say a ticket can be created by user or ticket belongs to user that's good but a single user can create many tickets so when you say something about the relationship that's exactly the eloquent relationships are there so I say has many so here is one of many or one too many that means a single user of one user can has many tickets this is the way we can connect it so how do we set up the relationship you have to use this kind of function where you want to provide the plural form of the relationship so in our case user can have many tickets okay so let's do that so we need to go on the user model and at the bottom we can create a function and it will be like tickets and this will actually return has many and we simply say this has many and ticket this is the ticket class we have to provide and that's it that's for that's done from user site so if we want to get all the ticket for a single user we can get that and that actually we need to do because right now every one is getting all the tickets we don't want that similar we need to do the reverse part so what that mean that means from the ticket side how do we get the user which we really need to do so we need to create once again the relationship or a function which is for belongs to that means we can go to the ticket model and here we create uh once again a function which is called single user because it's just belongs to a single user belongs to and that's same we have to return belongs to user class okay so this is the simplest way of updating the ticket or creating the relationship this means if I now go and try to click on let's say resolve this time it's working see we have not done anything changes here but previously it was not working but now it is working and we get the result and it says that the ticket is updated check the ticket and it says it should say the resolve if I open this in a new tab or here actually yes you can see it it's resolved that's great this is how you set up a relationship but how this relationship automatically gets set up so to understand this thing you need to go here on the ticket and see ticket already have a user ID so suppose you don't have the user ID you can say it's a Creator ID okay so in that case you need to define the second field as the foreign key on the belongs to so in that case if this is not true we we need to say creator ID so this is called the custom field if this is not the regular field so if it is user it should be user ID but if it's not user ID you can create your own and pass it as a second argument same thing you have to do on the ticket side if this is not you want to have a ticket or you you see that this is something else you can do that here on the has many like for the foreign key okay if it is not connected to the ID of the user that's how you create the relationship now this is done for our relationship of status or notification sending but you know if user is an admin then I want to show all the ticket but if user is not an admin then I want to show the ticket created by that particular user so suppose admin create a new ticket so uh ticket from admin so this is the ticket created by by admin just for demo okay so I create the ticket that's okay but this user which is a normal user can also see the ticket from the admin this is not true so how do we fix this for that we need to go to the ticket controller and on the index we said that give me all the ticket this is not good we need to get the ticket for particular user only so we know we have a auth user and we can call it a simple user then we say hey give me the ticket for users so user tickets remember we just have created the relationship and this means we will only going to show the ticket for that user the ticket created by this user only okay that's really powerful thing this is the power of electron relationships now what about the admin section if I reload still it's the ticket from the admin only but admin can see all the tickets how do we do that so in that case you can simply have a check so check will be like if user is admin then I need to get all the ticket otherwise give me the user specific ticket only so if I reload okay so is admin so this should be is admin and yeah you can see if there is an admin admin can see all the ticket and if not you can see the ticket create by user one last thing and then we will wrap up this video which is you can see the latest one should be at the top so instead of all I can simply say hey give me the latest one and then get so when I say latest this basically mean I say where or not where it's like order by created at so if I do that you can see it's like this and then we need to say descending and yeah you can see like this so level com level combine all these things into a single uh you can say function called latest and that's how it's working wow this is really amazing and now here we complete the ticket section of our this course so I hope you like this and I'm sure that you will going to complete the reply section for this ticketing system and let me know on the Instagram by tagging the bit fumes or you can send me on the Twitter also that's up to you but make sure you complete this so that you will learn better that's really great see you soon now is the time to deploy our project to the server and how we are going to do that it's going to be easy with the meso Hub so measlehub is my product it's an alternative to forge but it's more than that not just an alternative and just not for level it will be available for various languages various back-end projects but we are going to use this for level now why I'm choosing this obviously this is my product but along with that I just want to give you one very important thing for using the forge or any other service you need to pay you need to add your card but to use miso Hub you don't have to put anything you just need to start registering yourself and start using you can create one server one project unlimited Cron job and supervisor database things available for you and the best part is you don't need a domain it will give you a sub domain for misohub right away so let's start by registering so first thing is I need to register so I will say hey my name is sarthak my email is going to be obviously bitfumes plus meso Herb At gmail.com why I am doing this because I have the bitfumes at gmail.com when I say Plus the system mizohub recognized this as a new email ID but all the emails going to send to the bitfumes at gmail.com okay so let's take the password as password and here confirm password now click on sign up and very soon it says yay registered please verify your email so for that I need to open my Gmail account and now you can see we have this little email for the confirmation click on this verify email address and you will land to the login page that's great now I will write the email which I have used bitfumes at mizohub at the rate gmail.com and then password is password and then click on sign in great so you can see I am signed in and the first thing I have to do is connect my GitHub or you can use gitlab or bitbucket but GitHub is very famous and obviously our project is on the GitHub so we have to use it so click on connect GitHub and then it will take you to a GitHub authentication page where you have to decide where you want to install this application so since our project is on the bit fumes so I will choose the bit View and obviously I need to verify and log in and once done I can choose to select only one repository from here or I can choose to select all the repository for now I will choose the all and click on Save okay so next it says that yes you have done the source control connection but now is the time for connecting your service provider so I'm going to use digitalocean and see how we can do that first I will open the digitalocean click on log in and obviously if you don't have any account check the description below to get a 100 free credit if you use the link which I have given so once you are here you need to go on the API section and then you have to generate new token so give the token name as miso or I can say level 10 course miso and like that okay so here I'm going to take it as a no expiration because I want this token to be used forever so that I don't have to change my token whenever I use it on misohub now it's very important to give the permission of read plus write so now generate the token and once the token is generated you have to click copy and go here and then paste on the API key section here and you can name it like level 10 . meso token or whatever you want to give it's up to you so I will say level 10 let's say course like that and now click on connect once you click on connect it says provider created and now is the time to create the server so just by doing these two steps like connecting the GitHub and connecting the provider now you don't have to worry about going into the digital ocean you don't have to worry about going into your GitHub you just need to do everything from the mizuhub dashboard so here we can create the new server so click on new server and you can see I have added one provider so it says digitalocean then it says that okay with digitalocean do you have more than one account or if you have any single account just select that once you select the account then it says that which version of Ubuntu you want I will say 20.004 and the name you can see it has randomly generated if you want you can change it like this but I will take the randomly generated now see it says that no database is selected why because four dollar doesn't provide a good support for the MySQL to run so I will choose the six dollar and when I choose a six dollar you can see it appear as do you want the MySQL I say yes and now which reason obviously I am close to Bangalore so I choose that and do you need node or not so let's take the node I don't know Okay now click on submit and this is going to provision your server wow this is going to start right creating the server on your digital ocean so now if I go on my digital ocean and check for my servers you will see that the server is right here which is creating white Airport and here is the white airport you can see there is a little li130 string added which is just for making it unique okay so this is creating and once this is created on the digital ocean you can see it has automatically updated here in real time so see it says that it's created now it's installing some of this stuffs some of the steps needed to run laravel first it's updating server then installing nginx MySQL node everything it's going to do now if you want to take a closer look what actually happening in your server so what you can do you can just click on this button which was the arrow button and go inside of the server and very soon the things will going to start here and now you can see this is whatever happening in your server is appearing here this is really mind-blowing thing for this Mizu Hub which is going to give you exact information what happening in your server so you can watch it if you want to enjoy it or you can just wait until it's going to finished update server then it will move to installing the nginx MySQL node and preparing your server it's usually going to take three to four minute Max and your server will be ready and now you can see everything is done and once everything is done you can see now we are ready to create new project and how much time it took to create the server only just five minutes so this is the real amazing thing we can do with mizuhub that you can create your server with all of these things like having your server ready having your nginx installed having your MySQL installed and node install and all other things in just five minutes okay so let's start by clicking on the new project to deploy it and now is the time to deploy the project so first let's click on new project then this model will give you a random name once again for your name and then you have to click on the selected database which is installed on your server and then what type of project you are going to create which is a level project now PHP version is this and this is a default deployment script and now since we have already connected our GitHub so that's appearing here if you have connected gitlab or bitbucket that will come up here and now I will search for the repository and repository name is laravel hyphen 10 for beginner remember this is the one which we already have here great so finally when you choose your repository it will going to fetch the default Branch for you which is main here and if you have any other Branch you can name it anything like that okay so if you have your project inside any directory like it's not on the root then you can provide the directory name but since our project is inside the root directory so that's we can go everything is setup now and finally we have to click on submit once you click on submit it will start the process and the very important thing to notice here it's going to first install the PHP composer clone the repository and set up in Gen X and after some time you can see these three things are done and it's just going to set up the nginx and very soon we will have our project and now you can see our project is deployed and it says that site is up which is having the uptime monitoring system and we have a link for the project and this link is really amazing because it's a sub domain given by miso Hub we don't have to care about the domain if you are just trying out or just checking up so our project is live and we can track anything like if you go to tickets which was our uh just ticket so now we have some issue it says that white manifest not found so you know white manifest not found is basically an error which comes because you haven't run the npm install and npm run depth so here is the composer or script for the deployment and here after this one I can just say npm install and then after say npm run build so these two things I have to do so that I will not going to have this kind of error after that I can save this script and once this is saved I can click on deploy and this is going to once again deploy our project but just for the cloning and creating fresh release of your project so this is a zero downtime deployment that means it's not going to down your website while switch the release so very soon once this is done you can see very very soon this is done and now if I reload it will be available wow this is really nice it's now working great but now what next we need to set up the EnV for logging with GitHub because you know I told you this is also having the registration system and to register what we need we need the database connection and mizohub provide the database connection remember when we were creating the new project we have selected that hey I need to select the database connection for MySQL and this means I can easily create a new user in my database like that and I can say password pass word and click on register and you can see it's done you don't have to do anything very amazing thing this mizohub is and you can see everything is there we can go on the profile it's we can choose the image for the user and we can choose it we can click on Save now it says four one request entity to large this is error which coming because of the PHP thing so we don't have to worry about that we can choose any smaller image if I have it okay so I can check if this is a small one 541 KB I don't know if this this is also acceptable or not iftar is updated so if I reload it should be there but it's not showing it so why this is this is because we do we need to do the storage link command on our server so we can do once again from here PHP artisan are the sun storage colon link and save this that's done and click on deploy so once again this is going to do all of these again but also going to have the storage link command so once that one is done you can see it's giving each and everything whatever happening in your server so once the composer install is done it will going to do the npm thing and after that it will going to have everything set up for us and you can see we are now having the Avatar great this is really mind-blowing thing and within few seconds we don't have to do anything everything is done by mizo Hub That's The Power of this tool okay so what next I told you we need to have the dot Envy thing for the login with GitHub plus generating uh AI Avatar let's do that foreign remember when you have to update your EnV what you have to do you go your to your server then you update your EnV and on that server if you messed up anything your whole project will be gone done so what you have to do you have to use the measure Hub environment tab to go and edit your environment settings so once you click on the environment it's going to the server and directly fetching all the environment variable for you it's not going to store anything so it's absolutely safe and now you can see it has already done the connection for the database that's how it has created this user when we were trying to register and now we need to fill up the information so we know that we have the information in our DOT EnV file so we need to pass all these things plus the open AI thing also so copy that and is there anything else we needed yeah need the ah we need the mail trap also if we required but right now I can just save paste these things and let's just have these also I don't know if we are going to show that here or not anyways so that's done and you can change the name of your application and remember the name has to be in uh without any space and if you want the space use your uh double quotes or single quotes here anyways you can name it anything but now right now what I'm going to do I click on update so once you update it this will going to update Dr the envs directly on your server and once again mizohub is not going to save your EnV so that's the power and that's the security level okay so here we are and what next we need to click on login with GitHub and now it says invalid state so uh what next what happened here so now click on login with GitHub and let's do a refresh login with GitHub now it says larval socialite 2 invalid State exception what this exception says so we are getting this error because of the mismatch in one environment variable thing remember when we were setting up the GitHub then we have decided to give a callback URL and it's for the localhost 8000 but what it is right now it's not localhost 8000. it's actually this URL which we have here okay so we need to grab that and change it here on the Callback part so callback is now going to be this one okay so now update the envies while EnV is updating let's go to the GitHub and settings and on the profile then go to the developer setting then go to the oauth app and here is our level 10 codes we have to update here also so that if they are matching then only they will going to work so once that is done we can go on our application do a little refer just for sanity and now click on login with GitHub and you can see it's now working wow that's really nice so now click on profile and generate an AI Avatar because we have given the AI a key also like open AI secret key okay so this is taking a little time to generate the AI and you can see it has generated the AI so AI Avatar actually wow that's so true so this is the power of mizuhub and this is how you deploy your project to the server without worrying about the different different things you have to do like tons of things you have to do it's all taken care by larval and you have seen that we have never touched our server we have never used our SSH key to login to our server amazing power of mizuhub of a deployment tool is this also you can get the logs like whatever happening on your server you can easily check what's actual log was generated if there is any error that will show up here okay so that's also good and now suppose you want to change your branch right now so instead of main you can change the branch right now and after the next deployment you want the branch to be let's say master so you can do that from here you can change the repository right away so everything will be staying same but repository will be changed okay so what next you can also add your own domain name but to add your domain name you have to upgrade so upgrade is available for 400 rupees if you are from India and if you are from outside India it will be five dollar and fifteen dollar for the teams one you can check out the details what this uh these plans offer and I know you are going to love it so we have seen that yes everything is good when we go on our Gmail you can see every time a server is created then you can have the details of the server plus the username plus the database password emailed to you so that's once again amazing thing by this miso hub not only this you have a site monitoring system that means if the site goes down this will tell you and notify you about that hey site is now down if you want to change if you want to deploy by using CI CD and you don't want to come up to the measlehub to click on deploy you can use this URL with your token and that token you can create from here so if I click here you can see I can create the token from here and then it will be deployed you don't have to come to mizuhub just to hit this deploy button on the server there are once again amazing things available suppose after some time you upgrade to PHP 8.2 you can install and run it there then you have database now you can choose the database you want to install and move your application to that database if required you can run the supervisor add SSH key and add the schedulers and obviously change the time zone of your server so right now it's India Asia Kolkata but you can update it and make it available for anywhere you can reboot directly from this UI and oh my God lot of amazing things we have and we have the notifications available we have the teams feature you can share your provider your server your project with other team member they don't have to subscribe you just need to subscribe upgrade for the professional plan so that you can have the team plan team plan so that you will have the teams feature enabled for you so we have successfully deployed it enjoy this on the mizuhub and if you figure out any problem any error on the Mizu Hub you can just email me on bitfumes.com or it's really important to join this Discord channel of mizuhub and and the link is here in this Discord icon if you can't find or figure out that Discord I Discord link is not working you can go to the Miso Hub Twitter account and join the telegram community group for the mizuhub I hope you are going to enjoy this videos and enjoy this course see you on the in-depth larval course which is the premium course I have for you which is going to include many amazing things like all these things with the projects and yes these will be all yours in just 49 so take this before the launch so that it will be at just 49 otherwise the price will increase and course will be available in May 2023 2023. great see you on interplanable course
Info
Channel: Bitfumes
Views: 10,853
Rating: undefined out of 5
Keywords:
Id: 7-twY6Sd69c
Channel Id: undefined
Length: 474min 25sec (28465 seconds)
Published: Mon Apr 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.