0

The concerning route:

Route::patch('admin/track/practice/{practice_id}/close-practice-session/{session_id}/{new?}', array(
                'as' => 'close-practice-session',
                'uses' => 'AdminController@closePracticeSession'
));

new is an optional route parameter.

The Controller method:

public function closePracticeSession($club, $practice_id, $session_id, $new = null) 
    {
        $clubDetails = new ClubDetails();       
        $club_id = $clubDetails->getClubID($club);

        date_default_timezone_set(config('app.timezone'));        
        $CurrentTime = date("Y-m-d H:i:s");

        try
        {
            DB::table('practice_sessions')
                ->where('id', $session_id)
                ->where('club_id', $club_id)
                ->update(['is_current' => 0, 'updated_at' => $CurrentTime]);

            if ($new == 'Y')
            {
                return redirect()->action('AdminController@getTrackPracticeSession', [$club, $practice_id]);
            }
            else
            {
                return redirect()->action('AdminController@getTrackPracticeSession', [$club, $practice_id, $session_id])
                                 ->with(array('success'=>'Practice was successfully closed.'));
            }
        }
        catch(\Exception $e)
        {
            return view('errors.500')->with(self::getRequiredData($club))->with('error', $e->getMessage());
        }
    }

I have two forms on my view, one has the optional parameter, one doesn't.

When I click on the button on the form which has the optional parameter, I am getting a BLANK screen.

Here are some strange things:

  1. No error message. Checked the laravel.log
  2. Even if I remove all the logic from the controller method and do a simple var_dump, I still get a blank screen
  3. When I click on the button without the optional parameter, it behaves as expected

I have been trying for the last two days to resolve this without any luck. I have even tried to make the {new} parameter mandatory. Anytime I am passing the last parameter, I am getting a blank screen.

Any idea? I am sure I am doing something silly. Just can't see it.

Update (the two forms on the view) - the csrf token is in the header.

{!! Form::open([
    'method' => 'PATCH',
    'route' => ['close-practice-session', $alias, $practiceDetails[0]->practice_id, $practiceDetails[0]->id]
]) !!}
    {!! Form::submit('Close Session', ['class' => 'btn btn-primary btn-sm', 'style' => 'width: 160px;margin-left: 0px!important']) !!}
{!! Form::close() !!}

<!-- #2 -->
{!! Form::open([
    'method' => 'PATCH',
    'route' => ['close-practice-session', $alias, $practiceDetails[0]->practice_id, $practiceDetails[0]->id, "Y"]
]) !!}
    {!! Form::submit('Close + Create New', ['class' => 'btn btn-secondary btn-sm', 'style' => 'width: 160px;margin-left: 0px!important']) !!}
{!! Form::close() !!}
KalC
  • 1,530
  • 3
  • 22
  • 33

2 Answers2

0

As per your route

Route::patch('admin/track/practice/{practice_id}/close-practice-session/{session_id}/{new?}', array(
                'as' => 'close-practice-session',
                'uses' => 'AdminController@closePracticeSession'
));

Your controller function should be like this

public function closePracticeSession(Request $request, $practice_id, $session_id, $new = null) 
    {
        $clubDetails = new ClubDetails();       
        $club_id = $clubDetails->getClubID($club);

        date_default_timezone_set(config('app.timezone'));        
        $CurrentTime = date("Y-m-d H:i:s");

        try
        {
            DB::table('practice_sessions')
                ->where('id', $session_id)
                ->where('club_id', $club_id)
                ->update(['is_current' => 0, 'updated_at' => $CurrentTime]);

            if ($new == 'Y')
            {
                return redirect()->action('AdminController@getTrackPracticeSession', [$club, $practice_id]);
            }
            else
            {
                return redirect()->action('AdminController@getTrackPracticeSession', [$club, $practice_id, $session_id])
                                 ->with(array('success'=>'Practice was successfully closed.'));
            }
        }
        catch(\Exception $e)
        {
            return view('errors.500')->with(self::getRequiredData($club))->with('error', $e->getMessage());
        }
    }
Nirali
  • 1,776
  • 2
  • 12
  • 23
  • You only added a Request object. Didn't help :( ... same outcome. I get a blank page and no errors. – KalC Apr 07 '18 at 04:20
  • Is your request coming in controller? – Nirali Apr 07 '18 at 04:32
  • It is ... but then I saw this post on SO -->https://stackoverflow.com/questions/40451599/laravel-returning-a-blank-page-only-on-certain-routes?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa ... This was my problem. I had a GET route in my routes file with the same path. – KalC Apr 07 '18 at 04:37
0

Please take a look at this SO post. This gave me a hint to solve my problem. I had an identical GET route in my routes.php file. Once I modified my PATCH route to the following, everything is working as expected.

Route::patch('admin/close-practice-session/{practice_id}/{session_id}/{new?}', array(
    'as' => 'close-practice-session',
    'uses' => 'AdminController@closePracticeSession'
)); 
KalC
  • 1,530
  • 3
  • 22
  • 33