問題描述
在我的應用程序中,用戶可以提醒另一個用戶有關活動邀請的信息.為此,我需要傳遞事件 ID 和要邀請的用戶的 ID.
In my application, a user has the ability to remind another user about an event invitation. To do that, I need to pass both the IDs of the event, and of the user to be invited.
在我的路由文件中,我有:
In my route file, I have:
Route::get('events/{id}/remind', [
'as' => 'remindHelper', 'uses' => 'EventsController@remindHelper']);
在我看來,我有:
{!!link_to_route('remindHelper', 'Remind User', $parameters = array($eventid = $event->id, $userid = $invitee->id) )!!}
在我的控制器中,我有:
In my controller, I have:
public function remindHelper($eventid, $userid)
{
$event = Events::findOrFail($eventid);
$user = User::findOrFail($userid);
$invitees = $this->user->friendsOfMine;
$invited = $event->helpers;
$groups = $this->user->groupOwner()->get();
return view('events.invite_groups', compact('event', 'invitees', 'invited', 'groups'));
}
但是,當我到達該路線時,收到以下錯誤:
However, when I hit that route, I receive the following error:
Missing argument 2 for AppHttpControllersEventsController::remindHelper()
我確定我的視圖中存在格式錯誤,但我一直無法對其進行診斷.有沒有更有效的方法將多個參數傳遞給控制器???
I'm sure I have a formatting error in my view, but I've been unable to diagnose it. Is there a more efficient way to pass multiple arguments to a controller?
推薦答案
當你定義這個路由時:
Route::get('events/{id}/remind', [
'as' => 'remindHelper', 'uses' => 'EventsController@remindHelper']);
您是說將向該方法傳遞單個 URI 參數.
You are saying that a single URI argument will be passed to the method.
嘗試傳遞兩個參數,例如:
Try passing the two arguments, like:
Route::get('events/{event}/remind/{user}', [
'as' => 'remindHelper', 'uses' => 'EventsController@remindHelper']);
查看:
route('remindHelper',['event'=>$eventId,'user'=>$userId]);
這篇關于將多個參數傳遞給 Laravel 5 中的控制器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!