Laravel取决于子段的单个路由点指向不同的控制器 [英] Laravel single route point to different controller depending on slugs

查看:133
本文介绍了Laravel取决于子段的单个路由点指向不同的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是laravel的新手,我已经搜索了很多关于我的问题的答案,但是要么不适用,要么我没有得到.

I'm new to laravel and I have searched a lot for an answer to my problem but either it's not applicable or I'm not getting it.

我为处理客户和事件的客户端提供了FileMaker解决方案.我客户的每个客户都有自己的活动网站,这些网站都通过解决方案进行管理.一厘米.每个客户都会获得一个网址,该网址的网址类似于clientsite.com/event.

I have a FileMaker solution for a client that handle customers and events. Each customer to my client have their own event websites that is managed via the solution. A cms simply. Each customer get a site with a url like clientsite.com/event.

事件中的每个页面都有页面类型,我想根据类型来寻址不同的控制器.

Each page in the event has a page-type and I would like to address different controllers depending on the type.

在routes.php中,我有:

In routes.php i have:

Route::group(['middleware' => ['sal', 'menu']], function () {

    Route::get('/{event}/{page}', function($event, $page) {
        // Query page for page-type and use controller depending on type
    });
});

页面类型很多(标准文本/图像,特殊形式等),因此,我想介绍不同的控制器.

There are many page types (standard text/image, specialized forms etc) and therefor I would like to address different controllers.

事件名称始终是唯一的,但页面并非唯一.

Event names are always unique but pages are not.

推荐答案

您可以在路由闭包内手动调用控制器.尽管我建议在辅助文件中进行验证,以使路由文件清晰易读.

You could call a controller manually inside the route closure. Though I would suggest doing the validation in a helper file to make the route file clean and readable.

Route::group(['middleware' => ['sal', 'menu']], function () {

    Route::get('/{event}/{page}', function($event, $page) {
        // you could do something like
        $user_type = Auth::user()->user_type;
        if($user_type == "organizer")
        {   

            $controller = $app->make('OrganizerController');  
            return $controller->callAction('controllerFunc', $parameters = array());          
        }
        else
        {
           $controller = $app->make('ClientController');  
           return $controller->callAction('controllerFunc', $parameters = array());          
        }        

    });
});

这篇关于Laravel取决于子段的单个路由点指向不同的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆