EDIT: лучший пример
У меня проблема с контроллером checkauth, который вызывается после конструктора SectionsController - из-за этого расширенный ReportController, и я не знаю, почему он работает так. Я пытаюсь добавить промежуточное программное обеспечение в начале SectionController costruct, как $ this-> middleware ('checkauth'); , но тоже не работает.
Middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class CheckAuth
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!Auth::check())
{
return redirect('/admin/login')->withErrors(['message' => 'You need to login before proceeding']);
}
return $next($request);
}
}
SectionsController
<?php
namespace App\Http\Controllers\RMReport;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\View;
use App\Http\Controllers\Controller;
use Illuminate\Http\UploadedFile;
class SectionsController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $user;
public function __construct(){
$this->middleware('checkauth');
dump("SECTIONSCONTROLLER: ");
dump(\Auth::check());
//PROBLEM HERE - \Auth::Check is false , \Auth::user is null
$this->user = \Auth::user();
if( !$this->user->can('something') ) return redirect()->route('someroute');
}
}
ReportController
<?php
namespace App\Http\Controllers\RMReport\Form;
use App\Http\Controllers\RMReport\SectionsController;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class ReportController extends SectionsController
{
public function form(){
if( $this->user->status != 'Active'){
return something;
}
return another something;
}
}
Вывод из маршрута: список
GET|HEAD | admin/remote-report/{id?} | rm.report | App\Http\Controllers\RMReport\Form\ReportController@form | web,checkauth,checkownerRMreport |
POST | admin/remote-report/{id?} | rm.report | App\Http\Controllers\RMReport\Form\ReportController@store | web,checkauth,checkownerRMreport |
Вывод по вызову GET
"SECTIONSCONTROLLER: "
false
"CHECKAUTH:"
true