2015-04-02 107 views
-1

在routes.php文件我有以下途径缺少laravel控制器参数1

Route:: get('/crm/hotel/occupant/{id}', array('uses'=>'[email protected]','as'=>'crm.hotel.occupant')); 

为上述路线...如果我把这个样子的工作控制器......但如果我删除$ ROOM_ID在模型调用如

$ hotel = new Occupant();

..我得到一个错误缺少参数1 ....

public function occupant($room_id) 
    { 
     $hotel = new Occupant($room_id); 
     // manage page 
     return $hotel->occupant($room_id); 
    } 

该如何解决呢?

+1

请编辑您的问题...乘员构造的 – Rajesh 2015-04-02 05:08:32

+0

显示代码,请。 – 2015-04-02 07:15:04

回答

0

可以使{ID}可选。

它是由该实现:

Route:: get('/crm/hotel/occupant/{id?}',  array('uses'=>'[email protected]', 'as'=>'crm.hotel.occupant')); 
0

通过@vinweb作为解释你有一个问号?添加到您的id参数, Route:: get('/crm/hotel/occupant/{id?}', array('uses'=>'[email protected]','as'=>'crm.hotel.occupant'));

,但你也必须设置你可变为默认值(取自official doc的示例):

Route::get('user/{id}', function ($id) { 
    return 'User '.$id; 
}); 

所以,在你的情况下,将可能是这样的:

public function occupant($room_id = null) 
{ 
    $hotel = new Occupant($room_id); 
    // manage page 
    return $hotel->occupant($room_id); 
}