Header Ads

ad

Setup a Laravel 5.6 project with Authentication






Hello everyone, in this blog I am going to show you how to setup a Laravel 5.6 project initially. First of all we need to know a basic introduction about Laravel.

Laravel is a free, open-source PHP web framework,  intended for the development of web applications by following the MVC (model–view–controller) architectural pattern and based on Symfony.



Basic requirements to install this Laravel application :
  • PHP >= 5.0
  • Composer (As Laravel utilizes composer to manege its dependencies)
  • Artisan Command Line Interface (Eg. Command prompt for Windows users, Terminal for Ubuntu users)

First we have to install Composer in our machines. How would you do that? Here is the way.


Step 1

Open Command Prompt (optional by typing “cmd”).


Step 2

Type => composer global require "laravel/installer" 


Thats all. After a few minutes it will install Composer globally to your machine. Now we can create our first Laravel Application through composer.

Step 3

Go to any location where you want to create your Laravel project through CLI (Command Line Interface). In my case, I have a laravel folder. (Type => cd laravel), Next

Type  =>  composer create-project --prefer-dist laravel/laravel demo


The above line means “Demo” will be the foldername/Laravel project name, which will also be the distributive (dist/build) folder.
Keep patience. It will take some times to create a new Laravel Project. And after completing the installation it will look like the following :


Make sure that .env file have created along with an Application Key, as this key is the main requirement for a Laravel Project.
How will you check?
Open your folder from computer. You will find a .env file.

Now open .env file in any code editor software, you will find APP_KEY



:) All are okay then. You can skip to step 4 directly now.


But if you don’t find any .env file but the .env.example file, don’t worry. Just copy paste the .env.example file in the same location and rename it as .env and next go to the newly created folder using command prompt (cd demo) and 
type => php artisan key:generate
This will generate an APP_KEY to that newly created .env file

Step 4

Go to the newly created folder through the command prompt.
Type => cd demo
Now you would like to use PHP's built-in development server to serve your application, you may use the serve Artisan command. This command will start a development server at http://localhost:8000
Type => php artisan serve  (this will run/serve the project on http://localhost:8000)
OR
Go to public folder using command prompt (cd public) and
Type => php –S 0.0.0.0:8080  (this will run/serve the project on http://localhost:8080, in this process the PORT will be as per your need and choice)
Open the url in any browser. (In my case my project url is http://localhost:8080)
Tada! Your first Laravel app setup is completed.

Step 5

We will create an Authentication (Login / Register / Home) in our application. Larevel provides us a secure Auth control system built-in. How will we get that. Here we go.

Note: we will stop our application by typing CTRL+C in command prompt, and if your current folder is “public” then you have come to dist project folder (demo).

Type => cd ..



Step 6

In the command prompt type the following to create Auth.
Type => php artisan make:auth
This will create authentication routes and files to our project.

Now run the project by the same process mentioned at Step 4,
you will probably have a Login, a Register, a Forget password and a Home page.

That’s it. A basic Authentication of Laravel have set up successfully!
Hope you like it! Please don't forget to share.

No comments