Learn Laravel Basics for Absolute Beginners - How Much Laravel Can You Learn in 1 Hour?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
thanks to hostinger for sponsoring this video hostinger is an incredible web hosting provider where you can set up shared hosting Cloud hosting BPS hosting email hosting and SSL certificates hostinger has made a name for itself due to its fast low time Simplicity free domains and Powerful servers you can find my affiliate Link in the description down below for 10% discount of your next order what's up developers says Dory here and welcome back to a new video where we will learn the basics of larl in 1 hour are you new to larel or did you just learn PHP and are you ready for the next step to learn a PHP framework but don't know which one you just clicked on the Right video in this video we will cover the basics of the lwell framework keep in mind that we won't cover every single topic that lwell has to offer in depth if you do want that I have a six and a 5H hour LEL for beginner course which I will link in the description down below quick note we won't go over the installation tools since that can take up to 30 minutes I want to straight dive into installing a LEL project to waste no time now for the developers here that are completely new to larel let's start with the most important question what is larel larel is an open- Source PHP framework which in my opinion is very easy to understand once you get a good base of procedural and objectoriented PHP it follows one of the most known design patterns which is the model view controller framework so MVC Frameworks like larell Symphony and coding nighter are built on loads of packages that are developed by other developers but most importantly they are maintained by other developers as well with the use of a framework you don't need to think about configuration files service providers or prescribed directory structures if you haven't learned PHP before this video isn't for you because I'm not going to set up PP my SQL and so on I'm going to straight dive into installing and setting up a larel project through composer now larvo offers two ways to create a new project both ways require the use of the command line interface which I will refer to from now on as the CLI the first method is to globally install the larvo installer tool with the help of composer so inside the CLI you need to run the composer Global require larel for/ installer this installs the larvo installer tool but doesn't create a new directory for you where a larvo project has been added this needs to be done through the larvo installer where we can write down a larel new followed with the project name which will also be your directory name so let's name our project larel app now what this command will do right here is simply creating a new directory structure where you are located inside the CLI with the name of larell app and a skeleton lell project now the second method is used in composer to install a larell project so let's run the composer create Das project-- prefer DD larel for/ larvel and let's name our project larel app now the prefer DD option tells composer to download and install the distribution so zip files of the packages instead of cloning their git repository so once we hit enter right now you'll see that our La project is being installed now there are multiple ways of how you can run your lell project inside the browser for beginners I recommend navigating into the project directory that we have just created by saying CD of change directory into our larl app directory where right here we have the option to use an artisan command and I will cover artisen in a bit so let's for now run the PHP Artisan serve command now what this command will do is spinning up the Local Host right here with the port of 8,000 now if we copy this entire route navigate to the browser and replace our URL with the URL that we just copied hit enter you will see that we have spinned up our first laral project for now I want to open my project inside PHP storm I recommend you to do the same so we could dive into setting up our database credentials inside our project now I don't want to cover all directories and files that you will see right here as a separate chapter but we will cover them along the way whenever I spin up a new larel application I usually make sure that I set up my database credential first because I don't want to create a static web application in 99% of the cases I need to interact with a database to pull in data larvel makes use of environment variables which are variables that are expected to be different in each environment because it's different in each environment larvel has created a hidden EMV file in their root of our project where the dot make sure that the file is hidden and it won't be push to Version Control there are tons of environment variables right here that I won't cover but the ones we need to be able to connect with our database are the environment variables starting with DB uncore right here right here you will see that the default connection is a mySQL database the host is the host that we have opened inside the browser the port is 3306 the database name right here has been set equal to larel but for now let's change it to larel app now the following two should be equal to your MySQL credentials the username and password are the two credentials you use to interact with your local database in my case my username is root and my password is Dar 1 2 3 4 if you have added the correct credentials you most likely haven't created your database you could either create your database through my SQL CLI or an external database client but ever since the release of larva 9 larva added an option through the CLI where you could create a database through artisen as well now let's cover artisen real quick because I said that we ad do an artisen is a command line interface included with a framework that provides a number of helpful commands for developers such as creating controllers generating boiler plate codes and running database migrations it basically makes your job so much easier because you don't need to Define classes and files from scratch now let's test it out or let's navigate with the CLI where right here we can write down PHP artisan and that's how you make use of artisan once we enter you'll find a complete list of commands that you can perform and let me actually zoom out a little bit all right some of these you will use within any application you can see that they have tons of commands and some of these you will probably never use now one build-in command that Artisan has to offer is the PHP Artisan migrate command and let me zoom in again all right which is a command that larvo offers to run your database tables now once we enter you will see that Lael is prompting us with a message saying that the database does not exist inside our MySQL connection that we have to finded right here because it's looking for a database with the name of larel app so let's navigate back and let's say that we want to create our database Artisan has responded back with some kind of message it's first telling us that it has created our migration tables and it has migrated four tables right here well we haven't created those migration ations and these migrations right here are created by the framework itself and are added in any default project so let's talk about migrations for a bit in MVC you usually want to start with defining the models which will pull data from the database but before we could use any model we obviously need to make sure that we have our tables ready with larel you don't create your databased tables manually as you do with PHP which you are most likely familiar with you have probably worked with a database client or PHP my admin before where you had to click on buttons to create tables in LEL we Define something which is called migrations and a migration is essentially a single file where you define your database tables through code if we navigate back to our project you'll see that any larel project has a directory named database once we open it you'll find a couple subdirectories the factory subdirectory migration subdirectory and the C subdirectory now once we open our migrations table and let me make the sidebar a little bit bigger right here you will find four migrations and if we look at the names so create us table password reset tokens fails jobs navigate back to iter you'll find the same exact names so whenever you run the PHP artist and migrate command it will look inside the migration directory in the database directory now there are a couple rules that you have to follow when it comes to m ations they are always run in order by date and they allow you to create modify and delete database tables and columns as well as defining indexes and foreign key constraints as you can see right here all files start with a year so 2014 and 2019 followed with a month so the 10th 8th and 12th and a timestamp then you can see that they all start with a keyword of create right here followed with a table name so users password reset tokens fills jobs and personal access token and they all end with an underscore table keep in mind that everything will be stripped off once you run your migrations so your table will only be named users only be named password reset tokens and so on now the first migration for the users table creates the users table with the necessary columns for user authentication the second table is the password reset table which is used for password reset functionality then we have the failed jobs table which is used to store failed Q jobs and we have the personal access tokens table which is used for API token authentication now let's open one let's open the user table and let me make the Side Bar a little bit smaller again all right every migration has two methods inside of it as you can see it has an up method and at the bottom you will find a down method now the up method right here will be run once you migrate your migration through the PHP Artisan migrate command the down method right at the bottom allows you to roll back the most recent set of migrations where you will see that it uses a schema object right here where it is making a call to the drop if exist method where it will drop the user's table now inside the up method you will see that it's using the scheme of facade again and a facade is something you will hear and see tons in larel so let's talk about in frame moment facade is essentially a class that provides a static interface to a service provided by the application it acts as a proxy for accessing the underlying object allowing developers to use a simple and intuitive syntax to interact with complex functionalities right here you will see that the schema facade is using the create method now through the table object of the blueprint Crest you'll see that you can build up a lot of tables now let's create a new migration instead of doing that manually let's navigate to the CLI and since Artisan has a command for pretty much every action you could run the PHP artisan make Command followed with a colon because we're going to say what we're going to make and in our case we're going to create a new migration then we should name it as create uncore articles uncore table but before we hit enter let's hit backspace for a moment to the PHP Artisan command because we do need to have a model which we can use inside our controller to do something with the data in most cases I recommend using the PHP artison make colon model command in larel it is recommended to name your model singular so let's name it article and then we're going to add something which is used quite a lot in lville and that's the use of flags in larva Artisan flags are additional options that you could add to artisen commands to modify their behavior or perform specific actions they are usually represented by a hyphen followed with a letter or a word in our current example we're going to add the dash m flag which is used to generate a migration file along with the model file quick note flags are specific to each artisen command and can vary depending on the command being executed now let's hit enter and right here you can see that it has created a new model for us in inside the app models directory and it has created a new migration for us named created articles table we won't cover the model yet so let's navigate back to PHP storm and let's open the latest migration which is for the Articles table as you could see right here now let's define The Columns for our articles table every table has a unique primary key which has been added through the table object right here where it has access to the ID method a primary key is necessary in a database table to uniquely identify each record it ensures that each record in the table can be accessed and manipulated individually now the table object also uses the timestamps method right here which will add a created underscore at and an updated underscore at timestep column to your table now let's build up other columns every article has been created by a user so we need to add a column where we store the user ID of the user that has created the article which we need to do through a foreign key constraint the two methods that you will see right here so ID and timestamps basically shows you how you can Define other columns this needs to be done through method chaining a method chaining in LEL is a technique where multiple methods are called in a single line of codes with each method returning an object or instance that allows the next method to be called on this allows for more concise and readable code structure so let's use our table object and for now I want to create a foreign ID now inside our foreign ID method we can pass in a string which will name the column so let's say user ID then we're going to chain a method to it so metha chaining and usually for code readability I'll try to do that on the line below with the name of constraints this will ensure that the value in the foreign key column matches the value in the prime primary key column of the reference table then I'm going to add another method to it on the line below named Cascade on delete which means that if a reference record is deleted all Associated records in the child table will also be deleted automatically this helps to maintain referential integrity and ensures that the data remains consistent now let's add a couple other tables let's say table we're going to define a string which will eventually convert it to a far chart in my SQL where we're going to name it the title of our article we're going to use our table object the method name of long text which will convert it to text it's going to be an excerpt and we're going to chain the nullable method to it now the nullable method has a default of true but we're going to pass in false right here because we're going to give our exer the option to be nullable then we're going to add our table object we're going to create another long text which will be for our description so if you don't add the nullable method to it it has a default of required and then I'm going to use my table object because I want to create an integer column as well with the name of minutes to read now we have run the PHP artison migrate command once right let's navigate back to iterm now let's perform a clear right here all right now the four default migrations have been migrated but our article stable has not been migrated yet so how does this work well let's run the PHP Artisan migrate colon State this command for a moment when you run the PHP artisen migrate command olara creates a migration table in your database to keep track of the migrations that have been executed the migrate callon status command queries the table to determine the status of each migration the output right here typically includes the migration name right here the batch and the status which is running or pending this helps you to identify which migrations have been run and which ones are pending or have been ruled back right here you will see that the first four have been run but the article stable right here is panding so what we could do right here is simply running the PHP artisen migrant and as you could see it has not run all the other migrations but only depending migration and if we run PHP artisen migrate colon status again you will see that they all have been set equal to run now let's navigate back to PHP storm for a moment and I do got to mention that there are tons of other fields of data types that we could Define I try to define the most important ones but keep in mind that these will all be converted to data types in my SQL Lara recently added a pretty cool command which we can perform inside the CLI so let's navig get back back to it for a moment before it clear and let's run the PHP artison model command call in show followed with a model name so let's say article now we do need doen dball for this so let's install it real quick all right perform it clear let's hit the arrow up twice and let's run the command that we just mentioned and this command displays a Toral overview of any eloquent model in your application where it includes its available attributes and the relationships right here you will see that our ID is autoincrement and it should be unique we have a user ID which has been converted to an unsigned big integer an excerpt which has been set equal to text and so on pretty cool now let's dive a little bit deeper into our model in LL models are stored inside the app directory where you will find a models directory now let me close off my migration all right now right here you will find a default user model and an article model that we have created now every Lara model extends the model class and this model class offers tons of methods and properties that you can Define to customize your model models are an integral part of the framework's object relational mapper system called eloquent models represent database tables and Define the interaction with those tables they allow you to perform database operations such as querying inserting updating and deleting records the use of models has quite a lot of benefits compared to any other framework it provides a structured way to interact with the database making it easy to organize and manage data in most NBC projects you don't have a migration and all that is defined inside model by using migrations and models together you can easily Define and manage the database structure and the corresponding logic of manipulating the data now if we take a look at a naming Convention of our model real quick you will see that it has created an articles table for us and the model it has generated is a singular form of it named article in larel the model knows which table to use based on this naming convention larvel assumes that the table name is the plural form of the model's name with the first letter of the model name being capitalized since we have a model named article Lael will assume that the corresponding table is named articles so we don't need to Define anything to say which table it needs to interact with however if your table name does not follow this convention which I'm highly against you can overwrite a property to pretty much tell larvel that the article model need to interact with another table to overwrite properties we need to write down protected followed with the property name which in our case will be table which we need to set equal to a string which will be the new name so let's say newscore articles now we don't need this so let's remove it and since we're limited on time I want to define a couple important properties where the first property is the protected fillable property which we need to set equal to an array now the fillable property in LEL is used to specify which attributes are mass assignable mass assignment is a feature that allows you to create or update multiple model attributes At Once by default allaro protects against Mass assignment by requiring you to explicitly Define which attributes can be Mass assigned this is a security measure to prevent unintended changes to sensitive data the fillable property should contain an array of attribute names that are allowed to be Mass assigned while any other attribute will be ignored so what field should be Mass assigned well the user uncore ID the title The excerpt the description and the minutes to read we have kept the time stamps method it inside our migration which created a updated underscore at and a created underscore at column in your Lara model you can cast this to a different format through the cast property so let's say Protect it casts is also equal to an array now the cast property in larva model is used to specify the data type of certain attributes it allows you to Define attributes as specific data types such as booleans integers dates arrays and Json so let's say that our updated uncore at should be a date time and our created underscore at should also be a DAT time now the final thing I would like to Define inside our model is a relationship now Lara has tons of relationship that you could use but I want to stick to one relationship which is the relationship between the Articles and users table let's think about it one article is created by one user while one user can create multiple articles tools does that make sense when defining relationships I always advise developers to say it out loud as a sentence this allows you to see whether it makes sense or not now for this we need to define a onet Toom many relationship in a oneto many relationship a single record in the first table which in our case is the article table can be associated with multiple records in the second table however each record in the second table can be associated with at most one record in the first table and when defining relationships you can follow lel's name in convention you first need to define a new method inside the article model so let's say public function now the naming convention for the oneto many relationship is to use the plural or singular form of the related model followed with an S but this depends on the typ of relationship since one article is associated to one user we should use a singular form of user then inside our relationship we need to add the return keyword where we need to return this belongs to the belongs to is a method in lel's eloquent omm that defines a belongs to relationship between two modeles it does accept an argument because we need to pass in the model's class name as an argument in our case it should be the user model don't forget to pull it in and add the class to it now ever since larvel 10 we need to type into it so what we could do is saying well colon belongs to pull it in and the warning is gone now this only defines the relationship from the article to the user meaning that you can only access the user from the article and not the Articles from the user to do so we need to define a relationship the other way around as well so let's open our user model scroll to the bottom and right here we we can use the same methodology so let's say public function and one user has multiple articles right so we're not going to define a singular method named article but a plural method named articles now with my previous sentence I kind of spoiled what we should return right here because we're going to return this has many and it has many article models and that's it now let's move on to the next chapter where we're going to focus on controllers and routing in MVC the controller is responsible for handling user request processing input and interacting with the model to retrieve or modify data it basically receives input from the user such as a form submission or URL parameters and decides how to respond based on the requested action just like we have generated our migration with a model file we could do the same thing to generate the controller with it let me show you how that works let's navigate to it for a moment so let's say PHP artisan make me a new model let's name it article we have added the- F flag ourselves and let's add A- C flag to it as well which will basically generate a controller for you now this won't work right now because we have already an article model IM migration so let's remove it and let's use the make colon controller command to generate a single controller file in larel the naming convention for controller names is to use the singular form of the Associated model followed with controller since our model is named article the corresponding controller should be article controller if we hit enter right now you will see that a controller has been generated if we navigate back to PHP storm for a moment look inside of our app directory you will find an htttp directory the HTTP directory is a directory within the larvo application structure that contains classes related to handling HTTP requests and responses it is named like this so HTTP because it specifically deals with the HTTP layer of the application you will find classes such as controllers middlewares form requests and other classes related to handling HTTP related tasks so as you could see it has a controller directory inside of it and if we open it you will find a skeleton controller class which is the default controller all controllers will extend but if we open the article controller you will find our skeleton controller that we have generated through artisen now Lara uses Nam spaces for everything and Nam spaces are used extensively to organize and structure the applications code by using namespaces classes and other code elements can be grouped together and easily referenced from other parts of your application it obviously has its own class which has been set equal to the name of the file which you should always have equal to then you'll see that it's extending the base controller which allows you to easily customize and override methods as needed if you do that you will basically use code reusability modularity and maintainability by providing a consistent structure and behavior across controllers now this is pretty cool but larvo has even a way cooler function which is defining resource controllers and resource controllers in larel are a feature that allows you to define a single controller class to handle multiple related HTTP actions for a particular resource by using resource controllers you can group common Crut operations so create read update and delete for a resource into a single controller class this is very helpful for code organization because it reduces duplication and makes it easier to maintain and update your codes let's delete our article controller for a moment all right let's navigate back to the CLI and let's hit the arrow up because we're going to perform the last command we have performed but we're going to add a D- resource flag to it once we put perform our Command navigate back to PHP storm you'll see that it has generated the article controller for us you will see that this has generated a controller class with the necessary methods to handle CR operations for the article resource and it has already defin the parameters as you could see right here right here and well a couple other methods now usually I recommend working your way down with these methods because it does have a logical flow on web applications you usually start with a homepage of a resource and let's think about a Blog for a moment you start with a Blog overview right which is the index method of a resource controller now here comes some magic because we need to use our model this time to retrieve all the articles that we have well we currently have zero but that doesn't matter let's define a new variable inside our index method named posts and here comes some larva magic because we need we need to use our model this time to retrieve all the articles that we have and then send it back to the view let's set it equal to the article model and don't forget to hit enter to import the use statement of the app back SL models class so once we do that and scroll up you will see that it has been imported into our class you will see that PHP storm will automatically add a double set of columns and this is called the scope resolution operator it is used to static methods constants and properties of a class without needing to create an instance of the class itself now one static method that I want to use is the all method the all method is a method provided by lel's eloquent omm that retrieves all the records from the specified table now quick note the all method is not the best method to use when working with large number of Records because it will retrieve all the records at once what I recommend right here is replace replacing the all method with the paginate method and quick note it's impossible to cover all eloquent methods in one video not even if the video was hours long Lara offers so many functionalities so I'm only going to cover a couple important ones now pagination helps in breaking down the results into smaller more manageable chunks called pages each page contains a specific number of Records known as the page size the paginate method takes one optional AR ument inside the opening and closing parentheses which determines the number of Records to be displayed per page if you want to display 10 records per page you simply need to add 10 right here quick note the pagate method has a default value of 15 which I'm completely fine with it so let's get rid of it now this is all cool but how do we show something to the user now in LEL you need to return something which is called The View method which is used to render a view and return it as a response to the user request the view method takes the view file name as its argument as a string and it will return an instance of the illuminate view class which represents the rendered view views and larvel are not stored next to your controller but inside the root of your project you will find a directory named resources and once we open it you will find a subdirectory named views and if we open this one you will find one view named welcome. blade. PHP which is the default page that you will see right here now what I want to do is creating a new subdirectory named articles and I recommend naming the view the same as the method so what I recommend right here is creating a new file named index. blade. PHP now we haven't talked about blade and blade is a templating engine used by larvo for rendering views it provides an easy and expressive Syntax for writing Dynamic and reusable HTML templates blade has its own syntax and way to perform logic which we won't cover in this video but you can basically say well at if which will create an if statement for you add four which will create a for Loop for you and you have tons of other features such as ADD empty now let's open our article controller because we need to tell our view which view it needs to render and since we got it stored inside a subdirectory we need to add the subdirectory as well so let's say articles and in larel you don't use slashes right here to define the file but you use dots and dots are used to indicate nesset hierarchal routes now the route that we want to show is the index but we're not going to add the blade. PHP right here larvel automatically assumes that The View files are blade templates and adds the blade. PHP extension for you this is a convenient feature provided by larel to simplify the syntax when rendering views let's actually rename my post variable to articles I'm not really sure why I named it posts now right now we need to make sure that we send our articles variable back to the view right now Lara offers two methods well multiple but I recommend two the first method is adding a second argument to the view method which is a method named compact the compact method is pretty cool because it will automatically detect the variable based on their names so we could pass in a string right here of Articles which LEL will automatically link to the variable articles that we have right above now the second method is removing the compact method pass in an array where we need to pass in a key value pair the key will be accessed in the view so let's say articles while the value is the actual ual value that you want to Output so let's say variable articles now personally I'm a bit more fan of passing in an array and mostly because you can optimize your codes you don't need to Define a variable of Articles right here if you're only going to use it to send it back to the view what you can do is copying the actual value replace the variable articles inside the array and we can get rid of our variable declaration now we haven't defined the routes right so we can't magically navigate to Google Chrome at for/ articles to the endpoint and expect A View to open to do so we need to register the route and if we navigate back to PHP storm you'll find a routes directory inside the root of your project once you open it you'll find four files but the one that we need in this episode is the web.php file now Lille defines one route by default which is the welcome page which is is once again this page right here now let me say directly this is not the way that you will be using so don't look at it and let's define a new route we're going to use the same route class colon conon and if you want to Define your routes individually you can use a post right here a get a put a delete or whatever you need for your resource controller but since we have defined a resource controller we can use the res Source method right here what larvo will do right here is automatically generating the necessary routes for common CR operations then we need to pass in two arguments inside the resource methods the first argument is a string of the URI segment so basically what we just try to do where is it right here the Articles part so let's say articles and then we need to pass in a second argument which which will be the name of the controller so let's say article controller and just like in the controller don't forget to import the controller class now what we have done right here is saying that all methods inside the article controller can only be accessed through the for/ Articles endpoint pretty cool right let's navigate to the CLI for a moment because larel has a pretty cool tool for us let's run the PHP Artisan rout call an list command which will show you all the routes available in your application and right here you will find a total of seven routes which all have an URI prefix of Articles before we actually continue on let's delete the Articles directory for a moment because lell recently added something pretty cool let's navigate back to iterm let's run the PHP artisen command for a moment and if we scroll up to the make section where is it right here you'll see well you probably don't know that larel recently added the make colon view command which will create a new view for you so what you can do right here is basically saying PHP artisen make colum view you can name it index but this will not create a subdirectory for you so let's say articles for/ index once we perform enter you will see that it has created a new view for us inside an article subdirectory where the file name is index.pl PHP if we then navigate back to PHP storm open our articles directory index. blade. PHP file you'll see that it has added a simple div but right here I'm simply going to add articles on the line below I'm going to add a add for each if we hit enter you will see that it has created an opening for each tag and a closing for each tag now I won't cover all these but what I want to do right here is Loop over the variable articles as one single article then inside the loop I'm going to use a double curly brace syntax as you can see right here this is used for outputting data or variables in their rendered view it is basically a echo or print syntax so what we can do right here is say well print out the article and the article's variable We're looping over is coming from the article controller because we've sent back a variable named articles now if we navigate to the browser refresh it you will see that it is only printing out the keyword articles and that's because the value of our articles is empty because we have not created rows inside our database we can do that real quick because I have an external database client let me create it real quick the user is root password is D 1234 the database is larel app I'm going to click on okay I need to refresh it for a moment I'm going to create a user real quick so let's say add a row the ID is one the name is code with dii my email verified password is password type po updated at created at perform it it has been inserted I'm going to create one article right now and this is necessary because we need the user ID so the ID is one the user ID is one the title is post one the excerpt is test description is test mini read is one and to time stamps now let's navigate back to the browser refresh it where right here you will see that it has outputed our entire post now you can say that it only needs some output let's say the title inside the index ofl PHP file you need to use the arrow notation so a dash and a greater than sign where we're going to print out the title of the article if you refresh it you will see that post one has been added right here for now I want to leave the controller chapter even though we haven't finished the controller file and move on to something which I personally enjoy when it comes to larvel and that's the pack packages they have to offer and the coolest package in my opinion is larel Breeze larel Breeze is part of lel's incredible echo system which extends beyond the framework itself with the help of composer if we navigate to the browser for a moment and navigate to the official website of larl which is ll.com you will find a menu item in the top bar named echosystem and once you click on it you will see how big lel's ecosystem actually is these items right here are all packages Library lies and tools that you can add to your project these packages can provide additional functionalities such as user authentication API integration payment processing and way more some popular packages in lel's ecosystem include larel Nova which is an adment panel for larva applications that allow developers to easily manage and visualize their applications data we've got larva Horizon which is a dashboard and Q manager for larva's Q system which allows developers to Monitor and manage back jobs we've got larel Forge which is a server management where you can host your larel application and the one that we're going to install is the first one which is called larel Breeze which is a minimalistic and lightweight authentication system that provides features such as user registration login password reset and email verification out of the box one advantage that people don't talk about enough is that LEL Breeze automatically installs Tailwind CSS so you don't need to do that separately now marel Breeze needs to be installed through composer so let's navigate to the CLI for a moment and let's run the composer require a package from larvo itself forward slash it's named Breeze and we're going to add a Das dasde flag to it which ensures that larvel breeze is installed as a Dev dependency and not as a regular dependency now keep in mind that this does not install the breeze package out of the box to do so you need to run a newly created Artis and command that breeze has has added for us which is the PHP artisen Bree scullin install command this command will publish the authentication views routes controllers and other resources to your application now one pretty cool thing about larel Breeze is that it allows you to use different Stacks you can use blade lifewire react few or the API only in our case we're simply going to stick to blades with Aline JS now once we hit enter you'll see that it's prompting us with a message asking if we want to add dark mode let's say yes then it's asking us about a testing framework which we prefer is the newly framework named pest now we have already run the phb artisen migrate command and Breeze uses the user table so we don't need to run that command again it has already built our front end assets as well but if you want to recompile it you simply need to run mpm run Dev all right now let's run the PHP Artisan route called in list command for a moment because right here you will see that larva Breeze has added a couple routes for us we have the login endpoint we have the logout endpoint we have the password update we have a profile endpoint register reset password and verify email let's navigate to the browser and let's have a look at the changes if we open our local host and change our forward SL articles endpoint to forward slash you will see that in the top right corner the this has added two new menu items for us a login and register let's click on register and right here you will see that LEL Breeze has installed a fully working registration form so let's test it out my name is Dari my email is info star.com it needs to be a different email than the one that I have added manually my password is something very unique and the confirm password as well now once we click on register and close off this popup box you will see that we have been redirected to the for/ dashboard endpoint which is only accessible by authenticated users it even offers a my profile page let's click on our name in the top right corner where you will find profile and once you click on it you will see that you have a new form where you can change your name and email you can update your password and you can even delete your account now let's quickly log out for a moment and let's change the endpoint in the browser to forward SL dashboard again and right here you will see that we have been redirected to the login endpoint and that's because only authenticated users have access to the dashboard endpoint wonder how this works well larva Bree has added a ton of routes for us so let's see how this works let's navigate back to PHP stor for a moment let's open our web.php file and it's sign the views directory you can see tons of new directories the art directory components layouts profile dashboard and way more what I want to focus on right now is this part right here you will see the route that you might notice because it is a simple request to the for/ dashboard endpoint it's returning the view method right here and not in the controller but it has something attached to it which is new and that's the middleware method right here a middleware in LEL acts as a a bridge between a request and a response it provides a convenient mechanism to filter HTTP request entering your application middleware can provide various tests such as validating input authenticating users and way more now larel Breeze uses the a middleware to protect certain routes that require authentication the a middleware verifies that the user is authenticated before allowing to access the protected routes if a user is not authenticated they will be redirected to the login page now as you could see the middleware method is accepting an array so you could pass in multiple middlewares and this endpoint actually does because it has a second middleware named verified because verified basically means that the user should be verified to access the dashboard endpoint and that is actually true but it's a little bit difference since every migration let's open the users uncore table for a moment ships with an email verified column pre has basically added the functionality but it's up to the developer to enable it and this needs to be done right inside of the user model where right at the top you need to implement right after the authenticatable we need to add the keyword Implements of must verify email the must verify email is a built-in interface in larl and by implementing the must verify email interface larel automatically adds email verification functionalities to the user authentication system this means that when a new user registers they will receive an email with a verification link now this only works if you have a email delivery platform setup in your EMV file where you will find where is it right here your mailing credentials now I usually use mail trap and I don't want to set it up right now but what I can do is copying my credentials from my second file replacing it with the credentials in the EMV file navigate to the website of mail trap all right as you can see I'm logged in and if you want to do the same thing as what I just did you basically need to change the integration to larl and copy your credentials right here but what I want to show right now is going back to our Local Host click on forgot your password add an email of info@ code with.com click on email password reset link and as you can see we have been prompted with this message saying we have emailed your password reset link we then open mail trap you'll see a new email right here which says that we can reset our password through this button and once we click on it we can add a new password now we don't got that much time left so let me quickly show you how you could easily deploy a Lara application on VPS hosting using hosting error and VPS stands for virtual private server which is a type of Hosting that uses virtualization technology to create several virtual servers on a single physical server now if we open a new tab and open the official website of hostinger which is hostinger.com where you have a menual item in the top right named hosting and once you click on it you will find an option named VPS hosting where if you scroll down a little bit you will find a different VPS hosting packages now as you could see right here they're offering different types of discounts starting at 57% going up to 63% looking at the prices I got to say that the prices are pretty affordable when it comes to hosting if you host a larel project on cloud hosting you most likely pay a little bit less or even maybe the same depending on what you're going to host your project if we look at the features that all the packages have to offer you will see that the bottom five are featured on all packages it's AI assistant full access route a dedicated IP address and it has a weekly backup now based on the price and type type of plan a lot of feature will vary personally I would always recommend using a 2v CPU core because it improves the performance it is scalable and it has efficient resource allocation so for now let's choose the KV M2 package where right here you could either choose to pay for a month which makes the price more expensive since it will be $118.99 or you could pay for 12 months which will bring the price down quite a lot now quick note hostinger offers a 30-day money back guarantee which allows you to test it out and see whether any type of Hosting suit your requirements for now we're going to choose the 12-month deal and if we scroll down you will see that we have the Second Step where we have to add our payment credentials so I am already logged in if you're not step number two will be creating an account and step number three will be selecting your payment now right here you will find a overview of the total price which is $116 we have a plan discount of $58 % which is quite awesome right under our total you can see that we can add a coupon code and once we click on it add the coupon code of code with Dory click on apply you will see that a discount of 10% has been applied and you will receive another discount of let's say $12 because the price has now been decreased to $14 and in my opinion paying $14 for a 12mon VPS hosting is a great price for now add your payment credentials right here and I'll see you back once you have created your account in the dashboard of Hosting ER now right there you can see that we can set up our VPS hosting so let's click on start now where we need to choose the location of our VPS now the location of a VPO server can and will have an impact on website loading speed and overall performance this is because the physical distance between the server and the user can affect the amount of time it takes for data to travel back and forth since I'm currently located in the Netherland I'm going to choose the Netherland and I'm going to continue on because for the next step we need to choose our operating system there are three options right here and one of them is an option that we're not going to use which is the applications option because it's for WordPress and I want to get my hands dirty so I'm going to click on Plain operating system now the next step is the type of control panel we would like to use I have pretty much always been using ubun tube so that's pretty much my choice right here so let's click on it let's click on continue now for the next step we need to set up our control panel password so let's add a password right here let's click on Save and continue right here you will find an overview of the VPS location the operating system and the host name and once you're satisfied just click on finish setup now this will take a moment or two so pause the video and I will see you back once that's done all all right as you could see we're located on our H panel where you will see an overview of the server on the VPS information tab you will find your dedicated IP address right here the status of your VPS which is running which has not been set because our VPS has just been created the current operating system the location and the node in the SSH access tab you will find information on how you can access your application through SSH you will find your i p address the user the password the port the IPv6 and the terminal command to access your SSH now on the final tab which is plan details you will find some information that we have covered before but one pretty cool feature about VPS that I want to show you is the manage VPS section right at the bottom where you can upgrade your VPS on the go in other words is scalable meaning that you can upgrade your plan without having any trouble in case you want to do to do that you simply need to click on upgrade VPS now I don't want to cover all the tabs to the left right here because we do need to continue on with the installation part which needs to be done through a VPS manager a VPS manager is a tool that allows you to manage your virtual private server through a graphical interface it provides an easy way to perform tasks such as installing software configuring settings and managing files now the VPS manager that I recommend is named server Avatar I'm not going to cover the setup part because it is pretty straightforward I'm simply going to log into my server Avatar and continue from there so pause the video and continue on when you're ready as you can see I'm currently logged into my server Avatar account where I can connect to a new VPS hosting so let's click on Create and let's say server all right like I've just mentioned server Avatar is a VPS manager tool that allows you to manage your virtual private server through a graphical interface and I think that the screen right here should make a lot of sense for most developers you can connect to a custom server but you can also choose between Amazon Digital ocean and a couple other options what we need to do is selecting the custom server because we have our hosting provider which is hostinger then we need to add the server name which we can find in our overview VPS information right at the top which is the server name that has been autocreated for us so let's paste it right here then we need to add our IP address which we could also find inside our panel right here so let's copy it and paste it right here then we need to add our root password which we have created but in case you have forgot your password already you can navigate to SSH access and change it right here this will take up to 60 minutes so I'm not going to perform that I'm simply going to add the password that I have created the SSH board is 22 by default and if we navigate to our overview you will see that the default SS hpard is 22 then we need to select our text Tack and I want to use Apache so I'm simply going to use the lamp option I want a database of my SQL and I want to install node.js makes sense right the typical setup when you want to deploy a larvo application but this time on a VPS server let's click on connect now all right as you could see we're connected to our VPS and the installation part right here might take a bit so once again pause the video and I will see you back once this is done all right as you could see right here our environment has been set up and there are so many configurations you could see and configure right here from databases to server loads to memory usage to disk usage and even to application users I can't cover these all so I want to continue on by setting up our project I want to deploy my project through git so let's quickly click on the Integrations tab in the sidebar where you can see that you can link your bit bucket GitHub and gitlab account I want to choose a link my GitHub account so give me a moment and as you can see my GitHub account has successfully been linked to my server Avatar so let's click on the servers tab now let's click on the server that we have created now the next step is creating an application so inside the sidebar you will see applications or let's click on it or let's create a new application and I'm going to make a test project so I'm going to enter a basic application name let's say hostinger filament PHP it will be on a test domain and the test domain will also be hostinger filament PHP now let let's click on Next Step well apparently my subdomain has already been created so let's say hosting or filament Next Step all right for the second step we need to select a method on how we want to deploy our project into our application I have added my project into a GitHub repository which you will find right here so what I can do right here is click on get select the service provider which will be GitHub where you will see a couple options that we could add and here comes the tricky part whenever you are working with a private repository you need to add a deploy key to your project right now my repository right here is where is it private but once this video goes live I will change the visibility to public and if we navigate back to server Avatar and click on public you will see that we don't need to add the deploy key and you can simply use the htps URL that you can find right here to clone this project now this is the easiest method but in 99% of the cases your repository will be private so let's set that up before we continue on in GitHub let's click on the settings tab where in the left sidebar right under security you will find a deploy Keys option and once you click on it you'll see a new option where you can add your deploy key right here we need to create a new title and add the deploy key through server Avatar so let's navigate back to server Avatar click on private say generate SSH key or let's copy it let's navigate back to GitHub or let's name it server Avatar let's paste our SSH key inside the key text area there's no need to add server Avatar right access so let's add our key all right as you can see it has been added all right as you could see right here our deploy key has been successfully added so let's navigate back to server Avatar because we need to select our account which will be info@ codari decom let's select the repository which will be hostinger Das filament and we need to select a branch which will be the master branch and then you have the option to add a deploy script now whenever you open my GitHub repository which I have Linked In the description down below you will find the deploy key as well but I will keep the steps right here relatively easily so let's add a couple commands right here let's say gpol after the git poool we need to clone the env. example file so let's say cp. env. example to a file name. EMV we're going to run the PHP Artisan key call and generate command we're going to install or update composer so let's say composer install D- no DDE D- optimize d autol loader we're then going to run PHP Artisan route cache PHP Artisan cach clear and finally PHP Artisan migrate now let's click on Next Step then we need to choose our system user I don't recommend using admin right here so let's choose new user let's name it code with Dory and the password will be very secret click on next Next Step then we need to select our PHP version for larvo 10 plus I'm always going to use PHP 8.2 let's click on next step and let's review it for a moment and everything seems fine so let's say create application now there's one more setting that I want to update real quick so let's navigate to servers let's open our server now let's click on settings right here because I want to update the PHP CLI version to 8.2 to as well now if we think about it for a moment there are some steps that we have missed right we haven't created a database and we most definitely haven't set it up inside our EMV file so let's click on databases and right here we're going to create a new database we're going to name it hostinger filament we're going to set up a custom username and password where the username will be code with Ari and you will see my password in a bit which will be test 1 2 3 4 explanation mark we're not going to add the remote IP so let's click on create a database and as you can see we have been prompted with a message saying that our database has been created successfully so what we could do right now is navigating to our applications open our hosting or filament PHP app where we have an option in the sidebar which says file manager once we open it you'll see a familiar structure so open the public. HTML file where we need to show hidden files and right here you will see the EMB file and once you open it you can edit it right here so I'm going to keep it simple right here I'm going to change the database name to hostinger filament the user is code vidari and the password is test 1 2 3 4 explanation mark let's click on save it takes 5 seconds so give it a moment click on yes I'm sure all right now if we navigate back to our application you'll see that somewhere if it shows up we'll open our project first it has a primary domain and once we click on it you'll see a forbidden which means that the error code is 403 this is happening because Lille doesn't really understand our project structure and we can create a new hidden file named HD access so let's navigate back and let's open our file manager again the public HTML let's say create a new file let's name it HD access let's tick the show hidden files checkbox let's open our HD access file and I'll just add a piece of code right here as a comment since it's very easy to make mistakes right here so just follow along or copy the comments or from my Repository so I'm going to paste it right here I'm going to click on Save changes I'm going to wait five more seconds all right yes I'm sure if I navigate back to my local host and refresh it you will see the second error which is a 500 error and this is happening because our deploy script couldn't be performed since we had no database connection so what we can do is two options change it in server Avatar or we could open open our VPS copy our terminal command navigate to a terminal paste it right here and hit enter I do want to use a fingerprint so let's say yes my password is a password that I have added myself and as you can see I have it connected so what I need to do right here is change directories into my home directory if I perform an LS you will see a code with di directory so let's say CD code with Ari if we perform another LS you will find the directory that we have created ourselves so let's say CD hostinger another LS open the public directory perform another LS where you will see a larel project so pretty straightforward right here let's say composer update all right it's installing all packages that are required then we need to run the PHP Artisan key colon generate command finally we can run the PHP artison optimized colon clear command once we navigate back to the browser open our local host and refresh it you will see that our larel project is visible in the browser all right this was it for this video where we covered the basics of a la application in just 1 hour don't forget to use my discount code to get 10% off on your next hosting or order and if you do like my content and you want to see more leave this video a thumbs up and if you're new to this Channel please hit that subscribe button
Info
Channel: Code With Dary
Views: 8,793
Rating: undefined out of 5
Keywords: laravel framework complete tutorial for beginners, learn laravel in 1 hour for beginners, laravel 10 full course for beginner - intro to routes, learn laravel in 1 hour - laravel introduction and setup, how to use controller in laravel, why use laravel for web development, multi user authentication in laravel 10, building restful apis with laravel, preparing your laravel application for production, laravel for beginners, how to learn laravel 10, laravel tutorial
Id: saNZnJuLkDU
Channel Id: undefined
Length: 67min 37sec (4057 seconds)
Published: Wed Oct 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.