mercredi 16 mars 2016

Migrating laravel 5 and get Class does not exists

I created a Middleware on app/Http/Middleware/ called CorsMiddleware.php. It's rather simple and it already working on my offline homestead box. The problem happens on my remote machine:

ReflectionException in Container.php line 738:
Class App\Http\MiddleWare\CorsMiddleware does not exist

My file structure:

Middleware:
total 20
-rwxr-xr-x 1 CasatoroWeb CasatoroWeb  676 Mar 16 12:53 Authenticate.php
-rwxr-xr-x 1 CasatoroWeb CasatoroWeb 1570 Mar 16 12:53 CorsMiddleware.php
-rwxr-xr-x 1 CasatoroWeb CasatoroWeb  300 Mar 16 12:53 EncryptCookies.php
-rwxr-xr-x 1 CasatoroWeb CasatoroWeb  519 Mar 16 12:53 RedirectIfAuthenticated.php
-rwxr-xr-x 1 CasatoroWeb CasatoroWeb  311 Mar 16 12:53 VerifyCsrfToken.php

My class:

<?php namespace App\Http\Middleware;

use Closure;

class CorsMiddleware {

    /**
     * Run the request filter.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        /*
         * Get the response like normal.
         * When laravel cannot find the exact route it will try to find the same route for different methods
         * If the method is OPTION and there are other methods for the uri,
         * it will then return a 200 response with an Allow header
         *
         * Else it will throw an exception in which case the user is trying to do something it should not do.
         */
        $response = $next($request);

        // We only want the headers set for the api requests
        if ($request->segment(1) == 'api') {

            // Set the default headers for cors If you only want this for OPTION method put this in the if below
            $response->headers->set('Access-Control-Allow-Origin','*');
            $response->headers->set('Access-Control-Allow-Headers','Content-Type, X-Auth-Token, Origin, Authorization');

            // Set the allowed methods for the specific uri if the request method is OPTION
            if ($request->isMethod('options')) {

                $response->headers->set(
                    'Access-Control-Allow-Methods',
                    $response->headers->get('Allow')
                );
            }

        }

        return $response;        
    }

}

My kernel.php

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \App\Http\MiddleWare\CorsMiddleware::class,
];

I tried solving it by solutions like the ones posted here - http://ift.tt/1LqXw97:

composer dump-autoload
php artisan clear-compiled
php artisan optimize

And also by running

php artisan cache:clear

I don't know where else to look. Can anyone point me into the right direction?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire