Laravel 5.2 - App/Http/routes.php
More than that Laravel 5.3 or higher - routes/web.php
You're the name of your 'application/contact' that has to do with your routes.
'edit/1 that has to do with your routes.
Route::group() - Everything secure. Everything in a kind of a container.
Route::group(['middleware' => ['web']], function (){
});
'middleware' this is a security for laravel. Every time you see middleware is because you are securing something there.
Route::group() available for 'web'.
Every time:
(routes.php)
The route is a class. get() is a static method of Route class. also, know as to getting requests.
Route::get();
Route::get('/', function (){
return view('welcome');
});
Route::get() - This have couple of parameter. we first have a parameter here to actually what we have to type URL able to get somewhere. So right now we type when we go to the root directory of this application. This going to give us a view. views are representation HTML over application or where our contact pages will be index.php whatever. everything that you see in the browser would be of view.
eg: cms.test file open 'Laravel 5' text that is welcome view. (if you go the root directory, you can see welcome view)
example:
Route::get('/example', function () {
return view('welcome');
});
'welcome view' views by 'cms.test/example'
second parameter many different things and even haster parameters. that a clouser function or controller.
----------------------------------
code:
Route::get('/example', function () {
return view('welcome');
});
// http://cms.test/example
Route::get('/', function () {
//return view('welcome');
return 'HI You..';
});
Route::get('/admin/posts', function () {
return "admin is here";
});
Route::get('/', function () {
return view('welcome');
});
// http://cms.test
Route::get('/about', function () {
return 'Hi About Page';
});
// http://cms.test/about
Route::get('/contact', function () {
return 'Hi Conatct Page';
});
// http://cms.test/contact
Route::get('/post/{id}', function ($id) {
return "This is post number ".$id;
});
// http://cms.test/post/2
// http://cms.test/post/1000
Route::get('/post/{id}/{name}', function ($id, $name) {
return "This is post number ".$id. " ".$name;
});
// http://cms.test/post/2/najathi
// http://cms.test/post/1000/naharni
/* So You can pass multiple parameters */
-------------------------------------
Naming Routes:
-------------------------------------
Route::get('admin/post/example', array('as'=>'admin.home' ,function () {
// helper function
$url = route('admin.home');
// route() - Generate a URL to a named route.
return 'this url is '.$url;
}));
how to find the route and naming of the route?
1. open cmd or open terminal in any IDE
2. type command:
PHP artisan route: list
No comments:
Post a Comment