Laravel Tutorial Day 1

Learning Objectives: To understand the fundamental about PHP Laravel, Installation and Hello World Example.

Install LAMP into Ubuntu


Reference Website to Install Composer in Ubuntu

sudo apt update

sudo apt install php-cli unzip

cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php

sudo php composer-setup.php –install-dir=/usr/local/bin –filename=composer

composer


Install Composer

https://getcomposer.org/download/

Install Laravel

https://laravel.com/docs/9.x#getting-started-on-windows


Create Hello World Project (First Project using Laravel)

Goto Command Prompt (use cmd command)

goto specific folder (eg. c:\laravelproject)

c:

md laravelproject

cd laravelproject


Now Create project (Laravel Project Create Command)

composer create-project laravel/laravel myapp1

cd myapp1

php artisan serve


Now Test Hello World in your Browser

Open Chrome Browser (Or Firefox Browser / other)

Open URL: http://127.0.0.1:8000

Laravel Tutorial Day 2

Learning Objectives: To understand URL to Access and Management of Laravel Routes. Routes are the way to setup some view/controller for the specific URL.

When user opens the home page we would like to display some content from the view (view name for this example is welcome)

So first create view name: welcome with the following code:

Welcome to Laravel Training Home Page


Now we need to setup the route into route file. Here ‘/’ means home page url, sample code will be as follow:

Route::get(‘/’, function () {
return view(‘welcome’);
});


Now if user wants to open http://127.0.0.1/about then we would like to fetch content from about view then route will be as follow:

Route::get(‘/about’, function () {
return view(‘about’);
});

Make sure to create about view before writing this route information.


When you wish to collect parameter information from the URL, and wish to transfer this information to view, then sample code will be as follow:

Route::get(‘/service/{name}’, function ($name) {
$data = compact(‘name’);
return view(‘service’)->with($data);
});

{{ $name }} Services

Now you can able to Create various Views & Routes to setup different content for different URLs.

Practice Examples:

Create Simple Website with following Pages:

  1. Home Page (URL: http://127.0.0.1:8000 )
  2. About Us (URL: http://127.0.0.1:8000/about )
  3. Services List (URL: http://127.0.0.1:8000/services )
  4. Service Detail (URL: http://127.0.0.1:8000/services/training )
  5. Contact Us (URL: http://127.0.0.1:8000/contactus )

Laravel Tutorial Day 3

Learning Objectives: Till now you have learned the basics about the laravel to create pages and setup urls of the website. Now its time to learn the core element structures like loop, conditions, and so on.

PHP Laravel if elseif endif Examples:

@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don’t have any records!
@endif


PHP Laravel switch Examples:

@switch($i)
@case(1)
First case…
@break
@case(2)
Second case…
@break
@default
Default case…
@endswitch


PHP Laravel for loop Examples:

@for ($i = 0; $i < 10; $i++)
{{ $i }}
@endfor


PHP Laravel foreach loop Examples:

@foreach ($items as $item)
{{ $item->name }}
@endforeach


PHP Laravel while loop Examples:

@while ($i < 10)
{{ $i }}
$i++
@endwhile


For more fundamental syntax have a look @ Official Laravel Docs