Passing multiple parameters to controller in Laravel 5(将多个参数传递给 Laravel 5 中的控制器)
问题描述
在我的应用程序中,用户可以提醒另一个用户有关活动邀请的信息.为此,我需要传递事件 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 中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将多个参数传递给 Laravel 5 中的控制器
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01