douqie1852 2016-10-24 09:06
浏览 56
已采纳

用于路由到控制器的通配符

I am absolutely novice with Laravel and I am currently learning the routes feature of the Framework.

I want to know if it is possible to do like we can do with ASP.NET that is to redirect to a Controller written in the URL.

Actually, to do something like:

<?php

Route::get('/{CustomController}/{Action}', function ($controller, $action) {
    return controller($controller, $action);
});

Where CustomController is the controller which will run the request to the view Action

With ASP.NET Core, it is something like:

routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Index}");
});
  • 写回答

1条回答 默认 最新

  • dongxie2749 2016-10-24 09:11
    关注

    Yes, with routes in laravel the format is this:

    Route::get('/custom-controller', 'CustomController@index');
    

    If you are using the standard method names in your controller such as index(), store() etc

    you can use resource instead and it will automatically build up all your routes:

    Route::resource('/my-route', 'CustomController');
    

    If you then do php artisan route:list you will see laravel has automatically added all the standard routes for your controller.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求