2

I use Laravel 5.

I try,

 "use Illuminate\Contracts\Routing\Middleware;"

to implement "Middleware" as,

class Language implements Middleware {
       // Some Functions 
  }

I Get Error as,

Interface 'Illuminate\Contracts\Routing\Middleware' not found

Is actually that interface is Missing ?

(OR) Mistake in defining ?

(OR) Need to Create | Download ?

Thank Q !

8
  • did you put the correct namespace on top of the file " namespace App\Http\Middleware; " ? Commented Feb 17, 2016 at 6:42
  • Yep...Actually i create threw "php artisan"... So every thing fine.. This Middleware not found exception only i get... Commented Feb 17, 2016 at 6:43
  • can you please share the full class code? Commented Feb 17, 2016 at 6:44
  • Sure...See at Answer portion... Commented Feb 17, 2016 at 6:47
  • Did you upgrade your Laravel 5.1 version to 5.2 ? Commented Feb 17, 2016 at 6:50

3 Answers 3

6

The Illuminate\Contracts\Routing\Middleware contract has been deprecated in 5.2, remove it. And dont use it in class definition.

Like this

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Routing\Redirector;
use Illuminate\Http\Request;
use Illuminate\Foundation\Applicaion;

class Language{
    //..... YOUR CODE
}
Sign up to request clarification or add additional context in comments.

1 Comment

I see the changes since 5.2. Still i get this error Interface 'App\Http\Middleware\Middleware' not found
1

I dont know if you realy placed those double quote, but here is a working example:

<?php

use Illuminate\Contracts\Routing\Middleware;

class Language implements Middleware {
   // Some Functions 
}

Comments

0

My Class :

namespace App\Http\Middleware;

use Closure;

use Illuminate\Routing\Redirector;
use Illuminate\Http\Request;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Routing\Middleware;

class Language implements Middleware {

public function __construct(Application $app, Redirector $redirector, Request $request) {
    $this->app = $app;
    $this->redirector = $redirector;
    $this->request = $request;
}

/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle(Closure $next, $request)
{
    // Make sure current locale exists.
    $locale = $request->segment(1);

    if ( ! array_key_exists($locale, $this->app->config->get('app.locales'))) {
        $segments = $request->segments();
        $segments[0] = $this->app->config->get('app.fallback_locale');

        return $this->redirector->to(implode('/', $segments));
    }

    $this->app->setLocale($locale);

    return $next($request);
}

 }

LOC : App/Http/Middleware/Language.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.