0
votes

The scenario is, a user must be logged in to be able to 'book an event'. My ideal process is:

  1. User wishes to attend an event, clicks the attend button.
  2. Auth filter realises user isn't logged in and so redirects to the login page
  3. Once user is authenticated, the event ID and user ID is passed to the 'PostCreate' function within the 'Events' controller to book them on.

Currently, the user is redirected if not logged in, to the login page. Once the user is logged in, it attempts to call the 'events/create' controller method which is postCreate, but an error message is presented.

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Controller method not found.

However, as I am now authenticated, I can go back to the event, click attend, and it will process the booking. I am a little stumped as to why this won't work! Any help would be appreciated.

Is it down to the event ID not being passed with the login data? If so, it still should be able to find the controller method?

Event Controller:

<?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.' !');

    }

Users Controller

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>

Routes

/* 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');
1

1 Answers

0
votes

All Redirect responses will create a GET request. Your route and controller setup would then be looking for getCreate() instead of postCreate(), hence the error.