user9492428
user9492428

Reputation: 633

Argument 2 passed to Controller method must be in instance of Request, none given

I'm trying to pass 2 dates from one view to another, in my controller, but I get the following error: Argument 2 passed to App\Http\Controllers\GuestController::reservationToGuest() must be an instance of Illuminate\Http\Request, none given

This is my first view (the view having the date):

<form action="{{ route('create_guest') }}">                                            
    {{ csrf_field() }}
    <input type="hidden" value="2016-08-26" name="dateOne">
    <input type="hidden" value="2016-08-28" name="dateTwo">
    <button class="btn btn-block btn-success">Proceed To Check In</button>
</form>

(dateOne and dateTwo are the dates which I want in the second view)

routes.php

Route::get('/guest_page/create/{idreservation?}',[
    'uses' => 'GuestController@reservationToGuest',
    'as' => 'create_guest'
]);

reservationToGuest in GuestController

public function reservationToGuest($idreservation = null, Request $request){
    if($idreservation === null){
        return view('guest_page_create', ['idreservation' => 0, 'page_title' => 'Guest Check In', 'check_in_date' => $request['dateOne']]);

    } else{ //else clause works just fine and the dates from the database are inserted into the view
        $details = DB::table('reservation')
            ->where('idreservation', $idreservation)
            ->get();

        return view('guest_page_create', ['idreservation' => $idreservation, 'details' => $details, 'page_title' => 'Guest Check In']);
    }
}

And in view 'guest_page_create'

<label for="datemask">Check In Date</label>
<input type="date" class="form-control" id="datemask" name="datemask" value="{{ $check_in_date }}">

Upvotes: 3

Views: 3729

Answers (1)

Skysplit
Skysplit

Reputation: 1943

You shouldn't pass optional parameters before required ones. Try this:

public function reservationToGuest(Request $request, $idreservation = null)
{
    // ...
}

Upvotes: 6

Related Questions