Play Drag View

vividreal | January 22, 2021

Step by Step tutorial to building your first Laravel application

The ones acquainted with the world of coding might be aware of the sores it can give you. Continuously laying them out one by one can be very tiring as well as complicated. It is times like these when you can make use of effective PHP frameworks

Laravel is one such framework that helps web developers in creating remarkable web designs using PHP. What makes it stand apart from other similar frameworks is that its compatibility and convenience to use. It also has a number of available features that will help one in developing a rapid web application. 

In this article, we will guide you through the steps in which you can set up your Laravel Application. Sit back and get ready for this beginner’s guide. 

Laravel: Beginners Note

Ever since its initial launch in 2011, Laravel experienced exponential growth. By the year 2015 Laravel became one of the most noted PHP frameworks on GitHub and evolved to be the go-to-go at the global level. The fact that Laravel is focused on the end-user firstly denotes its level of simplicity and clarity on getting the required work accomplished. Brands, as well as individuals, use it to build several projects.

Steps to set up Laravel

First things first, Laravel is a framework that requires certain system requirements. It is recommended to use the Laravel Homestead virtual machine as your local development environment. In case you are not using Homestead, just make sure that your server possesses the following requirements: PHP >= 7.3, Fileinfo PHP Extension, Tokenizer PHP Extension, PDO PHP Extension, XML PHP Extension, JSON PHP Extension, Ctype PHP Extension, Mbstring PHP Extension, OpenSSL PHP Extension, BCMath PHP Extension. Now let’s look at the steps in installing and setting up Laravel.

Step 1

Laravel uses a composer to manage its dependencies. Therefore before you install Laravel to your system make sure you have a composer installed in it. You can download the composer from the link given below and then install it on your system.  

Download Composer

 Step 2

Once the composer gets installed, try and check its installation by typing the Composer command in the command prompt.

Step 3

Create a new directory somewhere on your computer for the Laravel project that you are going to create. Then, move on to the path where you created the new directory and type the command given below in order to install Laravel. 

composer create-project laravel/laravel –-prefer-dist

Step 4

You can also install the Laravel framework directly with the develop branch in which the latest frameworks are included. The command to install the complete framework is given below.

composer create-project laravel/laravel test dev-develop

Step 5

This command will enable the installation of Laravel in the current directory. By executing the command given below you can start the Laravel services in your system. 

php artisan serve

Step 6

Once you are done executing the given command you will get to see this window –

Step 7

Now copy the URL given in grey underline ( from the above screenshot ) and open that URL in your browser. 

If this screen is displayed, the installation of laravel has been completed on your system.

Always keep in mind that Laravel has to be served out of the root of the “web directory” that has been configured for your web server. Never attempt to serve the application out of any subdirectory of “web directory”. Doing this could cause serious issues and could even expose sensitive contents that are in your application. 

Important Steps in Doing Laravel Project 

Once you have downloaded and installed the application, let’s get started with a project. If you haven’t created your 1st project during the installation segment, you can create one by executing this command. 

laravel new todo 

1. Database Configuration

A database is required for our application. Therefore it is best if you can configure the database before attempting anything. You can avail of 4 databases that Laravel supports. They are MySQL, Postgres, SQLite, SQL Server. You can use the .env file to save different credentials and data. 

Laravel has a default .env file at the root where you will find a set of codes. 

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

What you need to do is replace the above commands with a single one. 

DB_CONNECTION=sqlite

Now create a file – database.sqlite in your directory

2. Authentication

Laravel provides authentication scaffolding, and that means everything that is related to authentication, for example, forget the password, user login registration, two-factor authentication, etc. These things will be pre-built according to your needs and are called Laravel Jetstream. The command to install Jetstream is –

composer require laravel/jetstream

3. Migrations 

Laravel is best in providing you with great ways in designing tables, database schema, tables and to migrate it over different systems. In Laravel, one can conveniently rebuild database structures by using the migration files on production or some other system. For that, you have to execute the given command. 

php artisan make:migration create_tasks_table --create=tasks

By doing this, you will find your new migration in – database/migration folder. Try adding columns to the tasks table editing the new one. 

public function up()
  {
     Schema::create('tasks', function (Blueprint $table) {
  $table->bigIncrements('id');
  $table->string('description');
  $table->integer('user_id')->unsigned()->index();
  $table->timestamps();
     });

The migrate command will now update the changes that you’ve made to the database. 

4. Controllers 

These are used in directing the traffic between models and views. They group multiple request handling logic into one class. They receive a logic-based request which is redirected or return the respective data. The given command creates a controller for tasks.

 php artisan make:controller TasksController

This creates a Task Controller. You can locate them in app/Http/Controllers directory.

Endnote

For beginners and ones without any further experience on web framework might have a slight starting trouble with it. But once you start using it, you are going to love it and probably become addicted to Laravel as it always aims at developing its creative sphere. The word ‘Web Artisan’ is used by Laravel to point out the hidden creativity in a developer’s mind. 

The competition, as well as hype to be on the top of business, is in an accelerating motion these days. Therefore, compromises can never suffice in the case of quality. If you wish to give a mind-blowing face to your website, we can help you craft a stunning website.

Back to Blog


Latest Blogs