Application Structure

Basic understanding of how application is build up and along with this you will get to know the ins and outs of every little file inside the directory. Actually there isn’t a clear model view controller directory where you could create small components and use them within classes. There is still MVC based framework is followed by default. Actually there are different folders where different respective files are stored in directory by default. Let’s start with models and controllers.

– Model files are stored inside the “app” directory. Inside model file you will always find user.php by default. Laravel will auto add a usage.php file.

– Later on when working with databases and modules you will understand better. Databases and modules are used in the controller to interact with the databases.

– All files including controllers need to be in the same directory but instead of modules directories.

– There is another ‘http’ folder in app, let’s open it and you find controllers directory in http folder.

Let’s click on controller directory, inside it organize the behavior of your application. So, you are basically going to create some kind of model that you are going to use inside a controller in order to retrieve information from the database and then you are going to pull that data in the right location of the view which you are running in the controller.

If you open your controller.php inside controllers. If you open controller.php file, you can see the class is extending the base controller and your base controller is basically an abstract class called controller.

You can use command click so let’s click on it and right here you can see the base controller that you are using. Let’s open the main controller and this controller that is extending base controller is basically the file that your new files are going to extend, so if you are going to make a usage controller you need to extend the controller file.

Now let’s know about more files-:

– In order to see the views you need to open the resource directory here where you will find the css, javascript and views.

– Let’s open the views directory and there you will see a welcome.blade.php file.

– More important files here are well directories like database etc.

– With this you have root directory which has abi.php, channels.php, console.php and web.php.

  1. Api file is basically a location where you register api retours for your application the channels file is where you register all the events broadcasting channels

– The console.php is the location where you define console commands.

– Most important one is the web.php. In web.php is a place where routes are registered.

If you want to import products you need to place them in storage directory.

Now move to some file knowledge- ‘.emv file’

-emv stands for environment and this is the place where you put all of your environment setups. To create this, basically you need to create an environment variable and set it to equal to value.

As there may lot of predefined environment variables as well as it also include a module for database connection with everything about server that is running in project.

As you will see in above file image, drivers, host are also defined.

Thing which is shown is how you could use the environment variables further this

Let’s open the routes and open web.php.

Web.php file is as-:

Here you can see referring is done to a specific view called ‘welcome’. What you could do to start the project is-:

– Change the return value, instead of writing return view, delete it and return emv ().

So with this you are referring to your emv file and by including variable, return statement is written as-:

Now save the web.php file and open the firstproject.test-:

Which is the main project under which all files are written. And you will see the database name is printed out on the screen.

Now return to visual studio there is also a emv.example file in the root directory which is the example of .emv file.

Now move to composer and know about composer installation process-:

Let’s open cd desktop/workspace/firstproject

After go to this give command “rm-rf space composer.lock” to remove your composer lock file.

Now to check write down ‘ls’that is list and you will found that composer lock file will be deleted but composer json file you ever created will be still there.

Now to recreate it you can give command ‘composer install’. It will check if there is a composer lock exist or not then it will perform a composer update and create one if you perform composer update. It will check the composer.json file then it will determine the last version. It will install it and update the log file.

So composer install will take few seconds. While installation the dependencies will update and write the log file and composer.lock file will be generated again.

Last or another thing relates to composer is adding libraries into composer.lock file with single command, If you will wonder how to add api’s like payment, authentication resources or any type of library, it’s true composer as well.

You can also get modules from github or would get api packages from google by copy the package statement such as from packagist

and paste to terminal and hit enter and you can see that it’s pulling in all the necessary libraries. To check go back to visual studio and in vendor directory search for molly. So, open composer.lock file and search for molly and can see a package with name “mollie/mollie-api-php” with respective version pulled out from github repository.

If there will no immediate import of libraries, then go to terminal write down ‘composer update’.

– If you delete some code from directory then you can recover it easily from composer.lock file.

– So with this you come to know that Laravel uses alott of libraries that are required through composer, so it’s good to realize that the core framework of the Laravel application is located inside the vendor directory that means if you somehow mess the file up or delete it you can’t run Laravel project anymore.

– If you look in the vendor directory you will see a lot of folders inside of it which you have been never seen before, this is all the Laravel automatically pulls.

– In last you can try another command i.e. “composer show –tree”. By which you will see the dependencies tree of your project or a framework of itself. 30% of code of Laravel comes from symphony itself.

“composer dump autoload” regenerates the list of all classes that needs to be included in the autoload.

Copyright 1999- Ducat Creative, All rights reserved.