Laravel is a web application framework with expressive, elegant syntax. It aims to make the development process a pleasing one for the developer without sacrificing application functionality. Happy developers make the best code.

Laravel focuses on the end user first, which means its focus is on simplicity, clarity, and getting work done. People and companies are using it to build everything from simple hobby projects all the way to Fortune 500 companies.

My goal with this Laravel tutorial to create a guide for those just learning the framework. This guide will take you from the very beginning of an idea into a real deployable application.

Here, I am going to dived this tutorials into parts so that you can easily follow things and do some practices.

Below are the list which you will need to follow along :

  • A local PHP environment (Homestead, Lamp, MAMP, etc.).
  • A database. I’ll be using MySQL.
  • PHPUnit installed.
  • Node installed. (optional)

Planning :

Every project has to start from somewhere, either assigned to you by your work or just an idea in your head. No matter where it originates, thoroughly planning out all the features before you start coding is paramount in completing a project.

How you plan is dependent on how your mind works. As a visual person, I like to plan on paper, drawing out the way I picture the screens looking and then working backward into how I would code it.

For this guide, we are going to be building a tags directory. Here is a list of fundamental goals for this tags app:

  1. Display a simple list of tags.
  2. Create a form where people can submit new tags.
  3. Validate the form.
  4. Insert the data into the database.

So, Let’s get started!

Note : I am using LAMP

Step 1: Install Laravel

With simple plan, Time to get new empty project up and running.

For laravel installation you can refer THIS blog post.

After complete the installation part time to scaffold out the authentication system by running :

Even though this tutorial will not dive into authentication by running this command, it will modify our views and routes. So by doing it early, we don’t have to worry about it messing with any of our code.

With the basics set up and working, it’s time to start doing some coding.

Step 2: Building a List of Tags

The best way to complete whole project is to dived into small task. So, Let’s start with showing a list of tags.

For showing a tags we need to create migration file, So our first step is to create migration file for tags.

For creating migration file Laravel Artisan command line tool can help us.

Now, open the file this command created. It will be located at database/migrations/{{datetime}}_create_tags_table.php.

Inside the up method add our new columns:

Save the file and run the migration:

While you are working with test data, you can quickly apply the schema:

Next, we need some data and a model to work with our database table. Laravel provides two features which help with this: the first is a database seeder, which populates the database with data, and second, the model factory files that allow us to generate fake model data that we can use to fill our development database and tests:

The --factory flag will generate a new factory file in the database/factoriespath, in our case a new TagFactory file will include an empty factory definition for our Tag model.

Open the TagFactory.php file and fill in the following:

We use the $faker->sentence() method to generate a title, and substr to remove the period at the end of the sentence.

Next, create the tag seeder, so we can easily add demo data to the table:

The make:seeder command generates a new database seeder class to seed our tags table. Open the database/seeds/TagsTableSeeder.php file and add the following:

In order to “activate” the TagsTableSeeder, we need to call it from the main database/seeds/DatabaseSeeder.php run method:

You can now run the migrations and seeds to add data to the table automatically. Using the migrate:fresh command, we can get a clean schema that applies all migrations and then seeds the database:

That’s it for this part we can see more on next post till then play with it.

In the next part will see Laravel Tinker and Routing & Views and much more.

Happy Codding!!!

What Others Are Reading

One thought on “Laravel Tutorial : Building Your First Laravel Application – Part 1”

Leave a Reply

Your email address will not be published. Required fields are marked *