Laravel 4 Basics


To install Laravel first you need to download and set up Composer. If you are using Windows you can grab the .exe file and run it which will set Composer up automatically.

For other operating systems, you should follow the instructions at:
To set up your first Laravel project you browse to the folder where composer has been installed (with something like cd E:\Programs\XAMPP\php in your terminal/command prompt and then you enter:

php composer create-project laravel/laravel E:\LaravelBasics\ –prefer-dist

This particular command is telling composer to create a template of a project using the Laravel framework and set it up in the Laravel Basics folder of E: drive.


This will create all necessary files for a Laravel application.


Creating a Basic Application using Laravel

Users will see the public folder.

We have moved the LaravelBasics folder but you can see the path to access the application:


The first thing that you have to do when starting to develop a Laravel application from scratch is to set Laravel to show errors. If you do not set this up you will always get “Whoops, looks like something went wrong” when there is something wrong with your code.

To do this, open app/config/app.php and set ‘debug’ to true.

Now open app/routes.php

Routes basically tell the application which controller should take a particular URL request or process it themselves by interacting with the model and the view (the view is what is going to be displayed to the user)

Add this route to the routes.php

This basically says that if the URL is



http://localhost:8079/current/articles/Laravel%20Basics/LaravelBasics/public/guess/16 the file called guess.php/guess.blade.php has to be shown to the user (you do not have to write the file extension in the View::make()’s argument. A text in {} (curly brackets) means that a random input may follow the request (guess/) in the URL and ? means that it is optional for the URL request to have the random input for which the ? applies. Thus, if we open the URL without providing a number like that:

http://localhost:8079/current/articles/Laravel%20Basics/LaravelBasics/public/guess the view will load with the default number that we have given (6).

If we write Route::get(‘guess/numbers/’)… then onlyhttp://localhost:8079/current/articles/Laravel%20Basics/LaravelBasics/public/guess/number/ would lead to displaying the ‘guess’ view.

withNumbers($number); is a magic method, it is the same as with(‘numbers’, $number) meaning that the View ‘guess’ would be able to use the $numbers variable from the route/URL whenever it wants to use it. It could be explained as with(‘variable name in the view’, ‘variable to pass to the view’).

Then in app/views we create a file called guess.blade.php to make use of the Blade Templating Engine.

In the Blade’s templating engine {{ }} (double curly brackets) work just like PHP’s echo or print statements and {{{ }}} (triple curly brackets works the same way but they also sanitize the input).

You can see a quick demo in the code above of how to use if/else statements and foreach loops using Blade.

Now if we type an URL like:

http://localhost:8079/current/articles/Laravel%20Basics/LaravelBasics/public/guess/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 only our first 5 could-be-lucky numbers will be compared against the real lucky number.

laravel basics demo

To download the code associated with this article, visit the original place where the article was published:

Be First to Comment

Leave a Reply

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

− one = 4