Support the ongoing development of Laravel.io →
posted 11 years ago
Requests

Hi Ive create a Route filter to check is the user is on a subscription. Im not trying to change the route I just place a session var eg:

Route::filter('sbuscribed', function(){
        try {
            $user = Auth::getUser();
            if ($user->subscribed()) {
                Session::put('stripe_id', $user->getStripeId());
                Session::put('stripeSubscribed', true);
            } else {
                Session::put('stripeSubscribed', false);

            }
        } catch (Exception $e) {
            Log::error($e->getMessage());

            // Throw Error Page
            return Response::json(array(
                    'status' => 500,
                    'error' => 'internal_server_error',
                    'error_message' => 'Internal Server Error',
                ), 500);
        }
    });

now if I return a new route to return anything like a string the filter works but if I don't return anything and only set the session it dose not work but I have other filters I use for OAuth -2 server that dont return anything and the filters work its this filter that will return error "ErrorException call_user_func_array() expects parameter 1 to be a valid callback, no array or string given"

Last updated 2 years ago.
0

Print something inside Try or Catch block...just to make sure where's the error coming

Last updated 2 years ago.
0

I did . I tried either side of the if block. I can var_dump or dd() in the try , catch and in the if block , If I return a redirect from the if block it works if I return a string it shows on the page but If I just set the session values weather the person is subscribed or not it fails yet I've written another package for OAuth2-server and I have filters that don't return any thing and they work fine so Im really stuck as to me I can not see a error in the code above. if I add a return to the IF block to return a string i can run the filter with a subscribed user and unsubscribed user and it works Ive never triggered the catch block unless I put a error into the try block then it return the response from the catch block .

Thanks :)

Last updated 2 years ago.
0

Found the issue it was my route eg:

Route::get('my/',['before'=>'sbuscribed'], function(){
        return View::make('hello');
    });

now that what fails so I now tried

Route::get('myy',['before' => 'sbuscribed', 'uses'=> 'HomeController@showWelcome']);

where i route to controller it it works

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

apps4u apps4u Joined 7 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.