Getting started with Laravel

0
7347

PHP is regarded as one of the most popular and versatile scripting language. It is really easy to get hands on with PHP. Almost exclusively used in web development, it has gained far reaching recognition. PHP frameworks are popularly known as functional platform. It helps developers to make complex applications quickly and easily. There are numerous PHP frameworks which are there in the market, out of which Laravel is popular due its elegancy and stability.

What is Laravel?
Laravel is a framework created by Taylor Otwell. It is an advanced form of CodeIgniter framework. Laravel is an expressive framework viable for large scale work.  

• It is following MVC (Model – View – Controller) architectural pattern.

Laravel is designed to facilitate the users, helping them to work in standardized, elegant and quick manner. 

Standardization:
Laravel has a strict Model-View-Controller (MVC) structure.  It uses object oriented programming concept and allows easy sharing of the project with the developers.  The style and methodology followed in Laravel Applications is almost similar which gives freedom to the developers to easily come in and work instantly with familiar mindset. 

Elegance
Documentation of Laravel is neatly structured.  It can easily match various versions of Laravel. It is very flexible and one can do same things in a number of different ways. The whole framework provides simple characteristics to help developers write the code in organized and self-documenting manner.

Speed 
The speed of building an application is quite fast. Laravel works really well with various third party packages.  This indicates that full support for Facebook API, MailChimp API, Loggers, Profilers and other tools can be added easily within strike of few keystrokes.

The Composer
Composer is a dependency manager for PHP, which allows users to manage libraries in a meaningful manner. By dependency, it means the libraries that are required to make a page work. The composer will download all the libraries required in a particular project. Before starting with Laravel, one has to install composer in the system. You can look for the steps to install a composer here. 

Installation of Laravel

You can install Laravel in the following three ways:

  • Laravel Installer
  • Via Composer Create Project
  • Download code from Github

We will be using composer to set up Laravel.

1. Open the command prompt. 
2. Go to the path in your machine where you wish to install Laravel.
     For instance, D:\projects

3. Run the command from the command window D:\projects path:

composer create-project --prefer-dist laravel/laravel <project-name>

We are keeping the project name: laravel-demo. Once you run the above command it will like the following:

Above command will create a new laravel setup on this path:  

D:\projects\ laravel-demo

4. Database Connection
Once installation process will be completed successfully, open .env file from your root directory and setup database configurations in this file as per below mentioned screenshot.

Now, database connection is successful.

5. Run new setup

Here we assume that you have installed PHP on your local server to run our new setup. 
Now run the below command from the following:

D:\projects\laravel-demo>php artisan serve

see the screenshot below:

Once you run the command in command prompt, it will show the message like Laravel development server started, as shown in the above screenshot.

Now you can run your new Laravel Application on Browser using the following:

http://127.0.0.1:8000

The default page of Laravel will be displayed after successful completion of the above steps.

Laravel is successfully setup. 

Key features of Laravel 5.6
The latest version of Laravel is 5.6, which is out now. Let us explore, what is new in this version

1. Single server Scheduling:
If you have a task scheduler running on multiple servers, a particular task will run on each server. With the help of onOneServer() method you can indicate that a task should run on any one of those servers. 

$schedule->command('report:generate')

   ->fridays()

   ->at( '17:00')

   ->onOneServer();

You must use memcached or redis cache driver as the default application, so that you can take advantage of single server task scheduling. 

2. Limit rate dynamically:
This function in Laravel 5.6 provides flexibility to its users and allows to easily rate limit on a per user basis. 

Route::middleware('auth:api', 'throttle:rate_limit,1')
    ->group(function () {
        Route::get('/user', function () {
            //
        });
    });

In this example, the rate limit is an attribute of App\User model. It is used to determine the number of requests that are allowed in the given time limit.

3. Broadcast the Channel Classes
The channel classes can be used in routes/channels.php file in place of using closures.
make:channel command is introduced in Laravel 5.6. It can be used for generating a new channel class.

php artisan make:channel OrderChannel

Also, you can register your channel in the routes/channels.php file like the following:

use App\Broadcasting\OrderChannel;

Broadcast::channel('order.{order}', OrderChannel::class);

4. API Controller Generation 
You can now generate a resource controller for APIs, where unnecessary create and edit actions are avoided. This is applicable to resource controllers returning HTML.  Use –api flag to generate a resource controller. 

php artisan make:controller API/PhotoController --api

5. Aliases for Blade Component
With Laravel 5.6, we can make alias for blade components in order to have more convenient access. 

For instance, suppose a component is stored at resources/views/components/alert.blade.php. In order to make a shorter name, you can use the component() method to alias it.

Blade::component('components.alert', 'alert');

Now you can easily render it with the aliases defined:

@component('alert')
    <p>This is an alert component</p>
@endcomponent

6. Argon Password Hashing
A new password hashing algorithm is supported by Laravel 5.6. One can even control which hashng driver to be used by default in the new configuration file 

– config/hashing .php

7. Method for UUID (Universal Unique Identifiers)
For generating Universal Unique Identifiers, two new methods are available in the Illuminate\Support\Str Class.

//<em> The methods return a Ramsey\Uuid\Uuid object
</em>
return (string) Str::uuid();

return (string) Str::orderedUuid();

The orderedUuid()method will generate the first UUID. This will be time-stamped for efficient and simple indexing of database.

8. Bootstrap 4
Laravel 5.6 has covered Bootstrap 4 functionalities to provide better frontend development functions. 

The upgrade from version 5.5 to 5.6 will hardly take 30 minutes. I hope you will now be able to easily install the latest version of Laravel.  If you have any new thing to say about Laravel, your views are welcomed in the comments below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here