Application structure in Laravel 8 | Learn Laravel From Scratch | Laravel 8 For Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right then guys now that we have reached a new section of this course i want to go through some important files inside the directory because every single file in here is actually pretty important but before we continue on i forgot to activate our visual studio code create icons so let's do that real quick because i want to see my folder icons right in front of the greater than sign if you're on windows go to file preferences or if you're on a mac hit shift command p now right here let's write down file icon theme let's open it and instead of disabling our file icons let's choose vs code great icons all right this is what i'm looking for if it actually if it does not work for you you could also go to the help navigation item right down file icon team and look this is where you could find it all right we're ready to kick off if we look at our application you might wonder where the model view and controller folders are and to be honest i was wondering the same exact thing when i started working with laravel i want to show you on a basic level how this application is built up and during this course you'll get to know the ins and outs of every little file inside of our directory to be honest there isn't a clear model view controller directory where we could create small components and use them within classes the folder names are a little bit different but don't get me wrong it's still an mvc-based framework by default the model classes are stored inside the app directory right here where you can find a models directory so let's click on it and by default there's always a user.php so let's open it you might wonder what the user.php file is because we've never created it and you're right because laravel will auto add a usage.php file later on when working with databases and modules you get a better understanding of this the models that we create right here can be used in our controllers to interact with the database now for the controllers you need to be in the same directory but instead of the modules directory let's open http and right here you can find the controllers directory let's click on it you can see this as the place where you are going to organize the behavior of your application so we're basically going to create some kind of model that we're going to use inside a controller in order to retrieve information from the database and then we're going to pull that data in the right location of the view which we're running in the controller if we open our controller.php file you can see that our class is extending the base controller and our base controller is basically an abstract class called controller which we honestly won't touch but we can use command click so let's click on it and right here you can see the base controller that we're using one thing is good to keep in mind is that well let actually close off the controller let's open our main controller and this controller that is extending the base controller is basically the file that our new files are going to extend so if we're going to make a usage controller we need to extend this controller file and instead of saying controller let's say class user controller extends the default controller but let me go back for now because we won't do it in this video now in order to see your views you need to open the resource directory right here where you will find the css javascript and views now let's open the views directory and in here you'll see a welcome.blade.php file what are other important files in here well directories we have our database which i actually don't want to talk about right now because i want to make an entire section dedicated to the database we have our routes directory so let's see right here which has an api.php channels.php console and web now the api file is basically the location where you register api retours for our application the channels file is where we register all the events broadcasting channels the console.php is the location where we define console commands well the most important one is the web.php so let's open it and while this is the place where we are going to register routes which we will do in the next section now if you want to import products you basically need to place them inside the storage directory so let's say that you have a dot csv file well you basically need to stir them right here you can also find your logs back here right now it's empty because we haven't done anything but i'll cover this later on as well i want to talk about the emv file since it's a pretty important file now emv stands for environment and this is the place where you put all of our environment setups how this works is well you basically need to create an environment variable what we have right here so app underscore name and we need to set it equal to a value and as you can see there are lots of predefined environment variables in here even if we scroll down you can see a lot of them you have your database connection your drivers you have to read this host and way more the apple url the app key the app env and the app name everything about the server that is running in the project and many different values for different servers are set up right here and in some kind of way you can see these as constants a constant represents unique memory locations and an environment variable is a variable that is set outside of the program what i would like to show you right now is how we could use the environment variables just bear with me and follow along now if we scroll up let me close off the vendor directory let's open our routes and let's open the web.php right here you can see that we're referring to a specific view called welcome what we could do is change the return value so instead of saying return view let's delete that and right here let's say that we want to return emv parentheses semicolon so right now we're referring to our emv file so inside the parentheses let's add a set of single quotes and what we could do right here is to write down our environment variable so let's say db underscore database database now let's save it let's go open a new view let's go to firstproject.test and you can see that our database name has been printed out on the screen now let's return to visual studio code what i want to do is to do it one more time but instead of using a variable that is already defined for us let's create our own so let's open the emv file again and right above app name let's write down creator underscore name is equal to your own name so let's say dari let's save it let's go back to our web.php file and instead of saying db name let's change it to creator underscore name let's save it let's hop back to google chrome refresh it and you can see that our variable that we created has been printed out on the screen and to be honest i don't recommend you to use environment variables all the time but mostly for domain names urls authentication mail addresses or service account names you also may have noticed that there is an emv.example file inside our root directory so let's open it up let me close off the marketplace let's see what the difference is with the emv file well the variable names are all the same as you could see and what this dot emv dot example file does is simply an example of what might be in the emv file so if you delete your emv file or make changes that you don't need you can easily rename the env.example.erv and you can get started once again or let me give you another example what if you're working on a large project with multiple colleagues where you are using git does every single person needs to push the emv file to the master well no because everyone has his own database credentials and you want to keep the emv file for yourself what you could do is to send the example file to the master so you know what key and value pairs you need for the project there are two pretty important files which are the composer json and the composer log file that we have in our root directory a couple videos back i've talked about composer and i've said that it's a dependency manager for php that allows us the developers to specify project dependencies now this needs to be done inside the composer json if the structure of this file is new to you no worries this is a dot json file let's have a look and see what is happening over here we have pulled a project in with the name of laravel the type is equal to a project it has a description so the laravel framework and it has keywords it has a license of mit which is a permissive free software license well actually the next part is the most important part of composer and that's the requirement part what you see right here is the vendor name so php file eloper fruitcake dozel http laravel and laravel they are all separated with a forward slash so let's see what's going on over here let's open our vendor directory and let's write down or search for guzzle http let's open it and in here you can see another guzzle file so it's searching for the directory inside the vendor called guzzle http so it's requiring this specific file over here whatever is in the vendor directory is a library and composer makes it easier to keep vendor libraries out of the repo you might be confused right now but you'll get a better understanding of it if we move deeper in the course let's rewind for a one second the libraries that are added right here have weird numbers attached to it and basically this is the version control with a specific format so let's take the version number with three the first number stands for the patch the second number stands for the alpha and the third number stands for the beta you could also see that almost every version has a carrot right in front of it and the carrot stands for the version range so as you can see right here we have version 4.2 with a carrot which is equivalent to let's say greater than or equal to 4.2 but the version is less than 5. so if fidel opera comes out with a new update and it updates it to 4.3 it's still compatible because it will look for a version that is 4.2 and it's less than 5. let me undo it all right so basically none of the releases until version 5.0 should break backwards compatibility alright right below the require section you can see a required dev right here and these are packages that are not necessary for your project to work you also don't need to add them in project version so if we delete anything inside the require our application will crash but if we delete something inside the required dev we're still able to run our project the convic and the extra options are not very necessary but the auto load might actually be right here some libraries that we add require autoload so if we go to our vendor now we scroll down to a file called autoload let's open it and you can see that it's basically requiring our composer let's go back to our composer file where you can see that we're requiring three things we have our app so well basically the entire app directory we have our database factories and we have our database seeders if you want to autoload a specific file or a specific directory you can easily add it while on the line below and it will always be autoloaded now to be honest the rest of this stuff is not very important as you can see in our root directory there's also a composer.lock i won't go too in depth about it because it's pretty much the same exact thing as the composer json file but the point of the log file is that it basically specifies the exact version that we have installed so they can be reinstalled if we go back to our json file you can see like i just said that there is a carrot right in front of the version if we go to our composer lock you can see that there is a v you can see that the arid has been replaced with a v so a definite version if you have any type of issue on the log file or you want to update some dependencies or libraries you've got you basically need to go to the terminal so let's do that let's cd into our workspace so desktop first workspace first project all right and in here we need to do a rm-rf space composer.log to remove our composer log file alright let's write down ls and you can see that our composer json file is still here but our composer lock file is gone now to recreate it you can perform either composer install or you could perform composer update there isn't a right or wrong here if you run the composer install it will check if the composer lock exists if not it will perform a composer update and create one if you perform the composer update it will check the composer.json file then it will determine the last version and it will install it and update the log file so let's do a composer install pause the video because this might take a second as you could see right here it's updating the dependencies and it's writing the log file that's ls and right here you can see that our composer.log file has been generated again the last thing that i want to show you related to composer is how we could add libraries into our composer log file with a single command if you have ever wondered how you could add apis like payment methods authentication resources or any type of library it's true composer as well whether you have worked on a training app or real life project most of the time you go to google so let's do that let's go to google chrome let's open a new tab let's go to google.com what i want to do right now is to show you how you could quickly and i mean a lot quicker than the manual installation is to install packages through composer the way people usually do it without the framework is while going to google search for let's say mali api php let's open the github repository if we scroll down to the installation process you can see that we have a composer installation right here and a manual installation part which is basically saying that we need to download it and include the vendor forward slash autoload that's not what i want to do what i want to do is to add the true composer this can be done by copying and pasting the command right here but what i would like to do is to show you a pretty cool website instead of using the github let's go to packages let's click on packages.org you can see packages as the main composer package repository you can easily search for packages and use composer to manage your projects or libraries right here you can see a button browse let's click on it or you could well browse to all the packages that are available and there are a lot of packages available what i want to do is to search for molly it's the second option created by mali forward slash molly api php right here you can see a composer so let's copy it let's go back to our terminal and paste it right inside our first project directory let's hit enter and you can see that it's pulling in all the necessary libraries for molly when the installation is done you can see that it has been pulled in so what we could do is to go back to our visual studio code and in our vendor directory let's search for molly so right here and inside the composer lot let's command f and let's search for molly all right then you can see that a package with the name molly forward slash molly api php with a version of 2.24 has been pulled in from this specific github repository and the last thing i want to say is that sometimes when i do this it won't import the libraries immediately whenever i have that i basically go to the terminal and i write down composer update composer update to update the dependencies but usually it works when you install the library through composer like i said in the last video if we delete anything inside our vendor we could get it back very easy because we are requiring that specific file inside our composer lock so let's remove molly inside our vendor directory alright by doing that we cannot use mali anymore because it does not exist in the vendor directory if we go back to iteram and run a composer update one more time this might take a second all right let's hop to visual studio code where you can see that molly has been added once again we've touched on the vendor directory a little bit in the previous videos and specifically on the auto load file that's inside our vendor right here what this auto file does is basically including the composer dependencies and by now we all know that laravel uses a lot of libraries that are required through composer so it's good to realize that the core framework of our laravel application is located inside the vendor directory that also means that if we somehow mess the file up or delete it we can't run our larva project anymore which i also said in the last video if we take a look at our vendor directory you'll find a lot of folders inside of it which you've probably never seen before or heard of these are all features that laravel automatically pulls in for us so it's not that you need to add them whenever you need them but they are already here when we need it if we hop back to our terminal we can perform a command called composer show dash dash tree all right right here you can see the dependency tree of our project with inversion numbers so let me scroll up because this is quite a lot as you could see all right take your time and see what kind of dependencies are in here and well you might see a lot of symphony dependencies and you might think well isn't symphony a framework of itself and yes you are partially right laravel uses a lot of third-party libraries which are mostly symphony components and to be precise thirty percent of the code inside our laravel project comes from symfony itself before we wrap up this part of the course i would like to show you the composer dump autoload and this command won't download anything but it regenerates the list of all classes that needs to be included in the autoload so let's click on enter oh my bad we need to add a dash so it's dump dash autoload and you can see that it's generating optimized autoload files as you can see right here these are the files that are required in our requirements let's go back to visual studio code let's open our composer.json right here alright that was it so if the laravel vendor folder is missing or you're getting an error you just need to run composer install and everything should work fine
Info
Channel: Code With Dary
Views: 8,165
Rating: undefined out of 5
Keywords: laravel, laravel 8, laravel php framework tutorial - full course for beginners 2020, laravel 8 tutorial for beginners, laravel php framework tutorial full course for beginners, learn laravel for beginners, learn laravel step by step, laravel full course, php laravel youtube, laravel tutorial youtube, how to learn laravel, laravel tutorial 2020 - the complete developer course, laravel tutorials from scratch to advanced, application structure laravel 8
Id: FEPMAFS7zQM
Channel Id: undefined
Length: 21min 42sec (1302 seconds)
Published: Fri Nov 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.