本文介绍了如果我使用许多“get",我如何实现资源控制器?在 Laravel 上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的路线laravel:

I have routes laravel like this :

Route::prefix('member')->middleware('auth')->group(function(){
    Route::prefix('purchase')->group(function(){
        Route::get('/', 'MemberPurchaseController@index')->name('member.purchase.index');
        Route::get('order', 'MemberPurchaseController@order')->name('member.purchase.order');
        Route::get('transaction', 'MemberPurchaseController@transaction')->name('member.purchase.transaction');
    });
});

我的控制器是这样的:

<?php
...
class PurchaseController extends Controller
{
    ...
    public function index()
    {
        ...
    }
    public function order()
    {
        ...
    }
    public function transaction()
    {
        ...
    }
}

我想把它改成资源控制器(https://laravel.com/docs/5.6/controllers#resource-controllers)

I want to change it to Resource Controllers(https://laravel.com/docs/5.6/controllers#resource-controllers)

所以我只使用 1 条路线

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', 'MemberPurchaseController');
});

如果我使用资源控制器,我只能在index方法或show方法中获取数据

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.

Route::prefix('member')->middleware('auth')->group(function(){
    Route::get('order', 'MemberPurchaseController@order')->name('member.purchase.order');
    Route::get('transaction', 'MemberPurchaseController@transaction')->name('member.purchase.transaction')
    Route::resource('purchase', 'MemberPurchaseController');
});

这篇关于如果我使用许多“get",我如何实现资源控制器?在 Laravel 上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 11:16