I have routes laravel like this :
Route::prefix('member')->middleware('auth')->group(function(){
Route::prefix('purchase')->group(function(){
Route::get('/', 'Member\PurchaseController@index')->name('member.purchase.index');
Route::get('order', 'Member\PurchaseController@order')->name('member.purchase.order');
Route::get('transaction', 'Member\PurchaseController@transaction')->name('member.purchase.transaction');
});
});
My controller like this :
<?php
...
class PurchaseController extends Controller
{
...
public function index()
{
...
}
public function order()
{
...
}
public function transaction()
{
...
}
}
I want to change it to Resource Controllers(https://laravel.com/docs/5.6/controllers#resource-controllers)
So I only use 1 routes
From my case, my routes to be like this :
Route::prefix('member')->middleware('auth')->group(function(){
Route::resource('purchase', 'Member\PurchaseController');
});
If I using resouce controller, I only can data in the index method or show method
How can I get data in order method and transaction method?
You could try like this, Just put your resource controller custom method up resource route.
For the resource controller, it is pre-defined by the Laravel, which contain only the 7 method.
Shown at below table.
So, if you want any other method, you have to definde by youself.
You can use this to check all the route you defined.
The other answers on here are pretty much correct.
From my other answer you linked this question in from, here that way based on what MD Iyasin Arafat has suggested, if you are using laravel 5.5+:
Grouping Methods ( ->group() ) :
Controller Namespace ( ->namespace('Member') )
Route Name (->name('member.'))
URI Request (->prefix('member'))
As you can see, using the methods above with group() reduces repetition of prefix declarations.
Hint
Example to use if you have a lot of custom routes for Purchase Controller and how a second controller looks for member group: