Skip to content

Commit

Permalink
Add compatibility to laravel <7 and laravel >=7 in same package
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorarnau committed Dec 17, 2020
1 parent fea4af4 commit d7dfd14
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Admin/Exceptions/CustomExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class CustomExceptionHandler extends ExceptionHandler
{
/**
* Render an exception into an HTTP response.
*
*compo
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @param \Throwable $exception
* @return \Illuminate\Http\Response
*/
public function render($request, \Exception $exception)
public function render($request, \Throwable $exception)
{

if ($exception instanceof TokenMismatchException) {
Expand Down
26 changes: 26 additions & 0 deletions src/Admin/Exceptions/CustomExceptionHandlerOld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Omatech\Editora\Admin\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Session\TokenMismatchException;

class CustomExceptionHandlerOld extends ExceptionHandler
{
/**
* Render an exception into an HTTP response.
*compo
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, \Exception $exception)
{

if ($exception instanceof TokenMismatchException) {
return redirect()->route('editora.action', 'logout');
}

return parent::render($request, $exception);
}
}
8 changes: 7 additions & 1 deletion src/EditoraServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\ServiceProvider;
use Omatech\Editora\Admin\Exceptions\CustomExceptionHandler;
use Omatech\Editora\Admin\Exceptions\CustomExceptionHandlerOld;
use Omatech\Editora\Admin\Middleware\EditoraAuth;
use Omatech\Editora\Admin\Providers\HelperServiceProvider;
use Illuminate\Contracts\Debug\ExceptionHandler;
Expand Down Expand Up @@ -39,7 +40,12 @@ public function register()
$this->app->register(HelperServiceProvider::class);
$this->app['router']->aliasMiddleware('editoraAuth', EditoraAuth::class);

$this->app->bind(ExceptionHandler::class, CustomExceptionHandler::class);
if(app()->version()<7){
$this->app->bind(ExceptionHandler::class, CustomExceptionHandlerOld::class);
}else{
$this->app->bind(ExceptionHandler::class, CustomExceptionHandler::class);
}


$this->mergeConfigFrom(
__DIR__.'/config/config.php',
Expand Down

0 comments on commit d7dfd14

Please sign in to comment.