Getting started with Laravel | Laravel Part - I
WHAT IS LARAVEL ?
Laravel is a PHP framework. It is an MVC framework that is designed to ease your backend efforts and to minimize the keystrokes and maximize the output.
With Laravel, you don't have to write several lines of codes just to achieve a simple task as you do in Vanilla PHP.
For example, in PHP if one wants to fetch all the results from the database, they have to write code similar to one below
With just that, we fetch all the content of our "Table". The table keywork in the above snippet is the Model reference.
You can read more about Models here
GETTING STARTED WITH LARAVEL
Setting up Laravel is pretty simple, but for that, you need to have Composer installed on your computer.
After installing composer, you need to make sure that you have a local server setup installed on your machine. Although a simple Laravel application dont require the Apache local server but the local server installation sets up PHP for you without any hassle and that saves a lot of time.
There are many different local server softwares available but I personally like using XAMPP
Now with both Composer and XAMPP installed, we can go ahead and install Laravel.
Although you can use composer to setup a new Laravel application, but installing Laravel installer would prove beneficial
We can get Laravel installer using composer and for that, open your command prompt and type in the below
Now open command prompt and navigate to a folder where you want your new Laravel application to get created and type in the below
This will create a new Laravel project named "FirstProject". It will take few minutes depending on your system. Once done, you can start making your very frst Laravel application.
AUTH IN LARAVEL
Authentication is something that comes out of the box with Laravel (The user login and registration).
To generate auth scaffoldings, we need a package called Laravel UI.
To install the package, navigate inside our newly created "FirstProject" and type
This command will edit your composer file and will install the new Laravel UI package that can be used in our project.
With that installed we can now use UI to scaffold auth as below
This will create auth scaffolding in our project and now we can use several different auth based features like User Login and Registrations.
- Laravel supports Vue and Bootstrap out of the box. To setup an application using Bootstrap stylings, we can use Laravel UI as below
This will bring in the Bootstrap CSS and JS into your projects package to be used but before using this, we need to compile our assets using inbuilt laravel mix feature. To compile all the assets, run the below command on command line
- Use NPM INSTALL to install new packages which were added using the Laravel UI. In your command line, type
npm install
and this will install everything that is required from the package.json file. - After that we need to complie all the assets installed with the npm install command. To compile them, we use
npm run dev
. This will take few seconds and will compile our assets including bootstrap and our application will then be ready for production.
Comments
Post a Comment