• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

多个参数传递把 Laravel 5 的控制器

用户头像
it1352
帮助1

问题说明

在我的应用程序中,用户可以提醒另一个用户有关活动邀请的信息.为此,我需要传递事件 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?

正确答案

#1

当你定义这个路由时:

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]);

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangibgge
系列文章
更多 icon
同类精品
更多 icon
继续加载