Search code examples
laravel-5ckfinder

How to integrate CKFinder with Laravel 5.2?


Since Laravel 5.2 shares it's session only with routes enclosed in "web" middleware group, I no more can run Auth::check() in CKFinder config. Does someone know how to solve this?

update: I used to share laravel's 5 session with CKFinder in order to give access permissions for authorized users. Like this:

require __DIR__.'/../../bootstrap/autoload.php';
$app = require_once __DIR__.'/../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel')
->handle(Illuminate\Http\Request::capture());

function CheckAuthentication()
{    
    return Auth::check() && auth()->user()->isAdmin();
}

But now since all routes should be wrapped in group with 'web' middleware, routes outside that group just wouldn't let to use Auth::user()

Route::group(['middleware' => 'web'], function () {
});

How to put CKFinder routes to 'web' middleware to be able to use Laravel's session?


Solution

  • Very easy. just modify the Kernel.php

     protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Session\Middleware\StartSession::class,
    ];
    
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],
    
        'api' => [
            'throttle:60,1',
        ],
    ];
    

    then try again。