Reputation: 14578
I am trying to debug a Laravel 5.o code. I have learnt from here.
But what I am facing, is not like that. What I am trying to debug is something like this -
<?php
get("/test",function(){
return $webinar = \App\Webinar::with('subscribers')->find(1);
});
Route::controllers([
'auth' => 'Auth\GTWAuthController',
'members' => 'MembersController',
'customers' => 'CustomersController'
]);
resource('users', 'Resources\UsersController');
resource('users.subscribers-lists', 'Resources\SubscribersListController');
resource('users.subscribers-lists.subscribers', 'Resources\SubscribersController');
resource('users.webinars', 'Resources\WebinarsController');
resource('users.panelists', 'Resources\PanelistsController');
resource('qas', 'Resources\QAController');
Route::group(array('prefix' => '/'), function() {
Route::get('/webinar/{webinar_id}/{subscriber}',
array('as' => 'site.webinar', 'uses' => 'WebinarController@index'));
////////////////////////////////////////////////////Testing
Route::get('test','CustomersController@getTest');
Route::post('add_question','CustomersController@add_question');
///////////////////////////////////////////////////////////
Route::get('/webinar/{webinar_id}/panelist', array('middleware' => 'user.panelist', 'as' => 'site.panelist.webinar', 'uses' => 'WebinarController@index'));
});
So, I can't understand how routs are working, can anyone help meplahow this outs are working?
Thanks for helping.
Upvotes: 0
Views: 57
Reputation: 1853
Well, I don't know if your question will be downvoted for not being specific, but I will assume you want to know more about advanced routing, like resources and prefixes.
A resource creates automatically the route names for all the possible methods to interact with a resource or model.
For example:
resource('client', 'ClientController');
With that single line of code inside your routes.php file, laravel 5.0 you now have the equivalent to:
//Uses show method, where you can return a view with a single client information
Route::get('client/{client}', [
'as'=>'client.show'
'uses'=>'ClientController@show'
]);
//Uses the index method, where you can return a view with a list of all the clients
Route::get('client', [
'as'=>'client.index'
'uses'=>'ClientController@index'
]);
//Uses the edit method, where you can return a view with an edit form for that specific client
Route::get('client/{client}/edit', [
'as'=>'client.index'
'uses'=>'ClientController@edit'
]);
AND SO ON It creates the destroy, update, create and all the possible methods, and also the proper route methods like PATCH, PUT, DELETE, POST, GET so you don't have to code it all.
A group is simply a group of routes that share a common feature. In the example you provided, the routes have a common prefix '/' I don't understand why, but it is most commonly seen with a prefix like:
Route::group(array('prefix' => 'academy'), function() {
Route::get('/webinar/{webinar_id}/{subscriber}',
array('as' => 'site.webinar', 'uses' => 'WebinarController@index'));
So, everytime you enter an url like www.myapp.com/academy/whatever
it will use the routes inside that group.
Any other question? remember to visit Laracasts.com and you will learn a bunch of it in 5 minutes
Upvotes: 2