Laravel 5 tutorial for beginners : how to basic routing in Laravel Artisan framework? Basic routing is meant to route your request to an appropriate controller.
Laravel 5 Tutorial - How to Routing in Laravel Artisan framework? in the Laravel PHP Framework we can make a route to an appropriate controller, So, the Basic of routing in Laravel meant how to route our request to a controller, the controller will send any request to the View. The routes of any application in laravel can be defined in app/Http/routes.php file.
Please read :
Here is the general route syntax for each of the possible request :
Routes.php
So, at the Controller folder app/Http/controllers/ we can create a homeController.php
homeController.php
now, homeController.php have a view method that will read 'welcome.blade.php' file in Views folder resources\views , lets create welcome.blade.php file.
welcome.blade.php
Some Routes Method in routes.php
See you next lessons ..
references : http://www.tutorialspoint.com/laravel/laravel_routing.htm
Please read :
Here is the general route syntax for each of the possible request :
Route::get('/', function () {
return 'Hello World!';
});
Route::post('foo/bar', function () {
return 'Hello World!';
});
Route::put('foo/bar', function () {
//
});
Route::delete('foo/bar', function () {
//
});
Routing Basic in Laravel
In Routes.php file app\Http\routes.php we can create new route.
Routes.php
// Call homeController using Index Method
Route::get('/', 'homeController@index');
So, at the Controller folder app/Http/controllers/ we can create a homeController.php
homeController.php
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequests;
class homeController extends Controller
{
// index functions have a view method that will read welcome.blade.php file in View folder
public function index(){
return view('welcome');
}
}
now, homeController.php have a view method that will read 'welcome.blade.php' file in Views folder resources\views , lets create welcome.blade.php file.
welcome.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Laravel</title>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
<style>
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
width: 100%;
display: table;
font-weight: 100;
font-family: 'Lato';
}
.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}
.content {
text-align: center;
display: inline-block;
}
.title {
font-size: 96px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Laravel 5</div>
</div>
</div>
</body>
</html>
Execute on your Browser :
Please execute the root url in your browser, http://localhost:8080/ you will see the wellcome.blade.php that "Laravel 5" message.How it work's?
- First, we will execute the root URL of the Laravel application is http://localhost:8080/.
- After executed the URL, our routes.php file will run the functions.In our case, it will match to get the method and the root ('/') URL. Then will read 'homeController.php' file that at the index function.
- at the 'homeController.php' we have the index function that will call the template file resources/views/welcome.blade.php. he function later calls the view() function with argument 'welcome' without using the blade.php. It will produce the following HTML output.
Some Routes Method in routes.php
<?php
// First Route method – Root URL will match this method
Route::get('/', function () {
return view('welcome');
});
// Second Route method – Root URL with ID will match this method
Route::get('ID/{id}',function($id){
echo 'ID: '.$id;
});
// Third Route method – Root URL with or without name will match this method
Route::get('/user/{name?}',function($name = 'www.hc-kr.com'){
echo "Name: ".$name;
});
Video tutorial Basic Routing in Laravel
See you next lessons ..
references : http://www.tutorialspoint.com/laravel/laravel_routing.htm
COMMENTS