方案是,用户必须登录才能“预订活动”。我理想的过程是:
目前,如果用户未登录,则会将用户重定向到登录页面。用户登录后,会尝试调用postCreate的'events / create'控制器方法,但会显示错误消息。
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 未找到控制器方法。
但是,由于我现在已通过身份验证,我可以返回活动,点击参加,然后它将处理预订。我有点难过为什么这不起作用!任何帮助将不胜感激。
是否由于没有使用登录数据传递事件ID?如果是这样,它仍然应该能够找到控制器方法吗?
事件控制器:
<?php
class EventsController extends BaseController {
protected $layout = "layouts.main";
public function __construct(){
$this->beforeFilter('csrf', array('on'=>'post'));
$this->beforeFilter('auth', array('only'=>array('postCreate')));
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function postCreate(){
$user_id = Auth::user()->id;
$user = myApp\User::find($user_id);
$event_id = Input::get('event_id');
$event_name = myApp\Event::find($event_id)->title;
$user->event()->attach($event_id);
return Redirect::back()->with('message-success', 'You are now attending '.$event_name.' !');
}
用户控制器
public function postSignin(){
if (Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password')))) {
$title = Auth::user()->title;
$surname = Auth::user()->surname;
return Redirect::intended('users/dashboard')->with('message-success', 'You are now logged in, '.$title.' '.$surname.'. ');
} else {
return Redirect::to('users/login')
->with('message-danger', 'Your username/password combination was incorrect')
->withInput();
}
}
Show.blade.php
<div class="col-md-3">
@if (Auth::user())
<br>
@if (!in_array($events->id, $attending))
{{ Form::open(array('url'=>'events/create', 'class'=>'form-signup', 'role'=>'form')) }}
{{ Form::hidden('event_id', $events->id) }}
{{ Form::submit('Attend Event', array('class'=>'btn btn-success'))}}
{{ Form::close() }}
@else
{{ Form::open(array('url'=>'events/cancel', 'class'=>'form-cancel', 'role'=>'form')) }}
{{ Form::hidden('event_id', $events->id) }}
{{ Form::submit('Cancel Booking', array('class'=>'btn btn-warning'))}}
{{ Form::close() }}
@endif
@else
{{ Form::open(array('url'=>'events/create', 'class'=>'form-signup', 'role'=>'form')) }}
{{ Form::hidden('event_id', $events->id) }}
{{ Form::submit('Attend Event', array('class'=>'btn btn-success'))}}
{{ Form::close() }}
@endif
</div>
路线
/* Event Route */
Route::get('events/{id}/{slug}', 'EventsController@show');
Route::controller('events', 'EventsController');
/* User Route */
Route::controller('users', 'UsersController');
/* Home Route */
Route::get('/', 'HomeController@getHome');
Route::controller('/', 'HomeController');
答案 0 :(得分:0)
所有Redirect
个响应都会创建一个GET请求。然后,您的路由和控制器设置将寻找getCreate()
而不是postCreate()
,因此会出错。