Laravel 5 Cashier Middleware Routing Error
Ad
I've implemented the cashier / billing feature from Laravel 5 and I'm trying to protect a group of routes using middleware which checks for a subscription.
I'm getting the following error:
Argument 2 passed to App\Http\Middleware\HasSubscription::handle() must be an instance of App\Http\Middleware\Closure, instance of Closure given
Heres my Middleware
<?php
namespace App\Http\Middleware;
class HasSubscription
{
public function handle($request, Closure $next)
{
if ($request->user() && ! $request->user()->subscribed()) {
// This user is not a paying customer...
return redirect('subscription');
}
return $next($request);
}
}
Heres my protected route
Route::get('home', '[email protected]')->middleware('subscription');
Heres my applications route declaration
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'subscription' => \App\Http\Middleware\HasSubscription::class,
];
Any idea why I get the error at the top?
Ad
Answer
Ad
Just add
use Closure;
to the top of your middleware, just before class definition:
namespace App\Http\Middleware;
use Closure;
class HasSubscription
{
...
Take a look on the the example in manual: http://laravel.com/docs/5.1/middleware#defining-middleware
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad