简体   繁体   English

Laravel Route获取没有方法的控制器构造

[英]Laravel Route get controller's construct without method

Route::get('customer/{id}', 'Customer@method'); <-- want to call construct not method

class Customer extends Controller
{
    public function __construct(){
        echo 123456;
    }

I'm new in laravel 我是Laravel新手

I try to call __construct from my controller without method, but I got error, is anyone know how to do it? 我尝试从没有方法的控制器中调用__construct,但是出现错误,有人知道该怎么做吗?

Try to do like this 尝试这样做

  1. Define route 定义路线

Route::resource('customer/{id}', 'Customer'); 路线:: resource('customer / {id}','Customer');

  1. In your Customer Controller 在您的客户控制器中
 use Route; public function __construct() { $id = Route::current()->getParameter('id'); dd($id); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM