hey what's going on guys welcome back to our blog and welcome to this laravel for beginners tutorials and in this blog guys we're going to discuss how to work with controllers inside our novel project and as a sort of review a recap in the previous blog we work on how to use the basic routings so we have discussed basic routing in the previous tutorial and like I've said in this tutorial we're going to discuss controllers but firstly we need some configurations especially if you are or if you're using the atom code editor so basically we're going to install some packages required for us to continue working with our laravel project so one thing that we need is the terminal because by default terminal or the built-in terminal of atom is not currently installed so we need to install the atom terminal for this particular code editor so in order for us to do that we need to go to file and in settings and then under packages we can see all the packages installed here in our code editor and in order for us to install so let's go here in the installed section and then we need to search for atom terminal and then we're going to use this terminal for us to issue a command by using the artist sign for us to create controllers automatically so there are a lot of terminal available if we search for terminal inside the atom code editor but I'm using this one this is Adam - terminal 0.8.0 so accordingly it open terminal terminal the current files directory so whenever we activated this we'll be inside the current files directory so go ahead and try to install that so it is developed by Karen so as you can see here and this will be our basis and this will be we will be using this to issue commands by using the artisan 2 to create our controllers automatically so after installing the terminal we can finally issued artisan commands by using the built-in add-on terminal and in order for us to activate that we need to press alt shift e in our keyboard so ctrl or alt shift e and then this will be or this will open the current files directory which is the name of our project currently is M or PK project and then from here we can issue the artisan command to create the controller's of our project so let's try to issue command or others issue artisan command to create our controller so the key word for that is we need to use the PHP and then artisan and of course the key word make next to that is the controller keyword and of course the name of our controller which is pages so for example were using pages and then pages controller so you might want to use this code or I mean the naming notation so all the first letter of the word or any word is capitalized so example for this the P in the pages is capitalized and of course the C in controller is capitalized so every first letter of words in our controller must be like this like a naming convention for our controller so after that you just need to press ENTER and then wait for a few seconds and there you have it controller created successfully and then if we try to check our app directory inside here and there HTTP and then controllers and then there you can see the pages controller that pastry file has been generated with all the necessary terms and code included so we have here the name namespace up HTTP controllers and also it automatically added the illuminate HTTP request and then created the class pages controllers which extends the controller class and any controller that you created should extend the controller class and inside here we can create a function or method so a function inside the class is can be called a method also so public function and then index okay so public means that we can access this outside of this class so for now let's just say it will return a tax or word index and let's go back to our routes folder and web dot PHP so we have here the index setup like this so instead of using this so I'm just gonna go ahead and comment this out and then paste it here so instead of using this function to return our index so let's just try the pages controller or we'll try to use our pages controller here so first let's use the occultations pages controller and add symbol and of course the method or the function that we have defined which is the index and now let's try this in our browser so I'm just gonna save this web dot PHP and go back to our browser and try to refresh so as you can see we are on the root folder or the root directory of our file or our project and it says the index which is coming from our pages controller and index method so now we want to return the view index instead of this string index so let's go back to our code editor and in here let's go to pages controller and instead of returning the index we just need to return the view and of course it should be under the pages and then the file index so currently I think I think we don't have yet the index that page P file so let's just go ahead and create that so under resources so we have here the views so under pages let's just go ahead and create a new file so this should be index that blade that PHP and let's just try to copy all the HTML from welcome that way dot PHP to our index not late that PHP and just we're just going to delete this content from here and I think also the Styles all the stylings available here that's just it this and of course this font and for the title we're going to get back on this later on but for now let's just define a tag here each one and then welcome to larva for beginners right they're beginners from programming knowledge and then paragraphs there you go this is a larvan tutorial series okay so if you try to open up the dot env file it holds all the connection like the values for our database connection the database name the password username and all other values and also it holds the app name of our project so it kind it it says laravel it's instead of laudable I'm just going to rename the speak a project or programming knowledge project and save that and go back to our index that played at PHP so instead of using the laravel as title here let's just use the config file so config and then open closed parenthesis and app that name and if that is not available let's just use PK project okay and save that and let's go back to our browser and refresh our page so as you can see here we have the new HTML coming from our index that page B welcome to laravel for beginners from programming knowledge so this is a laravel tutorial series and this reflects all the content from our index dot PHP file so as you can see here the code or the HTML code behind this page okay so for now let's just do the same for our about page so let's just copy this and go to about that maybe that PHP file so instead of using the about so let's just face the HTML and let's just change this instead of welcome to level for beginners it should be about and let's just say here that this is the about page and while we're at it we're just going to do the same for our services so we need to add a new page so this will be services that laid that PHP and paste the HTML and of course change this into services right and this is the services page right so save that and I think I have misspelled the blade so I just named this in too late instead of needed and for our page controller pages controller we need to define functions as well two other functions for our services and about so instead of index this should be for about so pages that about and this will be for our services so services save that and in our route file stead of using this routing mechanism so let's just replace them with our newly updated functions from pages controllers so let's just copy this this will be for about and of course change this into the about method and this will be for our services and this will be services as well so save this and let's go back to our browser and try to check if all are working ok so try to refresh and then let's go to our about page so as you can see here we have updated our about page and of course if we try to go to our services page so services and there you have it this is the service page of our application so I think that's all there is to it for this tutorial and in the next blog we're going to discuss how to go about blade template nning because currently we are using or HTML for our about for our services and for our index that PHP file so we want to reuse and reduce the code for this particular file so we're going to look at how to go about by templating on the next blog thanks
hey what's going on guys welcome back to our blog and welcome to this laravel for beginners tutorials and in this blog guys we're going to discuss how to work with controllers inside our novel project and as a sort of review a recap in the previous blog we work on how to use the basic routings so we have discussed basic routing in the previous tutorial and like I've said in this tutorial we're going to discuss controllers but firstly we need some configurations especially if you are or if you're using the atom code editor so basically we're going to install some packages required for us to continue working with our laravel project so one thing that we need is the terminal because by default terminal or the built-in terminal of atom is not currently installed so we need to install the atom terminal for this particular code editor so in order for us to do that we need to go to file and in settings and then under packages we can see all the packages installed here in our code editor and in order for us to install so let's go here in the installed section and then we need to search for atom terminal and then we're going to use this terminal for us to issue a command by using the artist sign for us to create controllers automatically so there are a lot of terminal available if we search for terminal inside the atom code editor but I'm using this one this is Adam - terminal 0.8.0 so accordingly it open terminal terminal the current files directory so whenever we activated this we'll be inside the current files directory so go ahead and try to install that so it is developed by Karen so as you can see here and this will be our basis and this will be we will be using this to issue commands by using the artisan 2 to create our controllers automatically so after installing the terminal we can finally issued artisan commands by using the built-in add-on terminal and in order for us to activate that we need to press alt shift e in our keyboard so ctrl or alt shift e and then this will be or this will open the current files directory which is the name of our project currently is M or PK project and then from here we can issue the artisan command to create the controller's of our project so let's try to issue command or others issue artisan command to create our controller so the key word for that is we need to use the PHP and then artisan and of course the key word make next to that is the controller keyword and of course the name of our controller which is pages so for example were using pages and then pages controller so you might want to use this code or I mean the naming notation so all the first letter of the word or any word is capitalized so example for this the P in the pages is capitalized and of course the C in controller is capitalized so every first letter of words in our controller must be like this like a naming convention for our controller so after that you just need to press ENTER and then wait for a few seconds and there you have it controller created successfully and then if we try to check our app directory inside here and there HTTP and then controllers and then there you can see the pages controller that pastry file has been generated with all the necessary terms and code included so we have here the name namespace up HTTP controllers and also it automatically added the illuminate HTTP request and then created the class pages controllers which extends the controller class and any controller that you created should extend the controller class and inside here we can create a function or method so a function inside the class is can be called a method also so public function and then index okay so public means that we can access this outside of this class so for now let's just say it will return a tax or word index and let's go back to our routes folder and web dot PHP so we have here the index setup like this so instead of using this so I'm just gonna go ahead and comment this out and then paste it here so instead of using this function to return our index so let's just try the pages controller or we'll try to use our pages controller here so first let's use the occultations pages controller and add symbol and of course the method or the function that we have defined which is the index and now let's try this in our browser so I'm just gonna save this web dot PHP and go back to our browser and try to refresh so as you can see we are on the root folder or the root directory of our file or our project and it says the index which is coming from our pages controller and index method so now we want to return the view index instead of this string index so let's go back to our code editor and in here let's go to pages controller and instead of returning the index we just need to return the view and of course it should be under the pages and then the file index so currently I think I think we don't have yet the index that page P file so let's just go ahead and create that so under resources so we have here the views so under pages let's just go ahead and create a new file so this should be index that blade that PHP and let's just try to copy all the HTML from welcome that way dot PHP to our index not late that PHP and just we're just going to delete this content from here and I think also the Styles all the stylings available here that's just it this and of course this font and for the title we're going to get back on this later on but for now let's just define a tag here each one and then welcome to larva for beginners right they're beginners from programming knowledge and then paragraphs there you go this is a larvan tutorial series okay so if you try to open up the dot env file it holds all the connection like the values for our database connection the database name the password username and all other values and also it holds the app name of our project so it kind it it says laravel it's instead of laudable I'm just going to rename the speak a project or programming knowledge project and save that and go back to our index that played at PHP so instead of using the laravel as title here let's just use the config file so config and then open closed parenthesis and app that name and if that is not available let's just use PK project okay and save that and let's go back to our browser and refresh our page so as you can see here we have the new HTML coming from our index that page B welcome to laravel for beginners from programming knowledge so this is a laravel tutorial series and this reflects all the content from our index dot PHP file so as you can see here the code or the HTML code behind this page okay so for now let's just do the same for our about page so let's just copy this and go to about that maybe that PHP file so instead of using the about so let's just face the HTML and let's just change this instead of welcome to level for beginners it should be about and let's just say here that this is the about page and while we're at it we're just going to do the same for our services so we need to add a new page so this will be services that laid that PHP and paste the HTML and of course change this into services right and this is the services page right so save that and I think I have misspelled the blade so I just named this in too late instead of needed and for our page controller pages controller we need to define functions as well two other functions for our services and about so instead of index this should be for about so pages that about and this will be for our services so services save that and in our route file stead of using this routing mechanism so let's just replace them with our newly updated functions from pages controllers so let's just copy this this will be for about and of course change this into the about method and this will be for our services and this will be services as well so save this and let's go back to our browser and try to check if all are working ok so try to refresh and then let's go to our about page so as you can see here we have updated our about page and of course if we try to go to our services page so services and there you have it this is the service page of our application so I think that's all there is to it for this tutorial and in the next blog we're going to discuss how to go about blade template nning because currently we are using or HTML for our about for our services and for our index that PHP file so we want to reuse and reduce the code for this particular file so we're going to look at how to go about by templating on the next blog thanks
Post a Comment