我的项目在本地服务器上运行良好,但是当我将它部署到生产服务器上时,我的中间件不起作用,我使用卫队来限制经过身份验证的用户访问页面,但是当我将路由放在组中间件中时,它总是返回未经身份验证的.在网上找到了很多解决方案,但到目前为止没有什么有用的.
Route::middleware(['auth:admin'])->group(function () {
Route::get('notifications',Notifications::class);
});
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],```
发布于 2022-04-12 02:22:18
这个问题可能是由路由组声明引起的。试着像这样声明:
Route::group(['middleware' => 'admin'], function (){
// If you haven't declared the controller path within web.php, declare the route like this
Route::get('notifications', [App\Http\Controllers\Notifications::class, 'method_you_want']);
});
编辑:带电控制器示例
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Livewire\WithPagination;
use App\Models\Ente;
class TableEnti extends Component
{
public $enti = null;
public $idt = null;
public $markedRows = null;
public function openModal(Request $request, $id){
// Setting up the db connection ( this for multi-tenant app)
if (null !== $request->get('throughMiddleware')) {
$this->connection = 'tenant';
} else {
//recupero l'id del tenant
$this->connection = null;
$this->idt = tenant('id');
}
//recupero lo specifico ente
$ente = Ente::on($this->connection)->find($id);
//$ente = $this->parseValues($ente);
$this->dispatchBrowserEvent('open', ['ente' => $ente, 'idt' => $this->idt]);
$this->markRow($id);
}
public function markRow($id){
$this->markedRows = null;
$this->markedRows = $id;
}
public function render()
{
return view('livewire.table-enti')
->with('enti', $this->enti)
->with('idt', $this->idt)
->with('markedRows', $this->markedRows);
}
private function parseValues($ente)
{
$ente->codicefiscale = $ente->codicefiscale == null ? 'Dato mancante' : $ente->codicefiscale;
$ente->abilitato = $ente->abilitato == true ? 'SI' : 'NO';
$ente->id_qualifica = $ente->id_qualifica == null ? 'Dato mancante' : Qualifica::on($this->connection)->find($ente->id_qualifica)->descrizione;
$ente->ruolo = $ente->ruolo == 0 ? 'Admin' : 'Collaboratore';
$ente->ufficio = $ente->ufficio == null ? 'Dato mancante' : $ente->ufficio;
$ente->indirizzo = $ente->indirizzo == null ? 'Dato mancante' : $ente->indirizzo;
$ente->id_comune = $ente->id_comune == null ? 'Dato mancante' : Comune::on($this->connection)->find($ente->id_comune)->denominazione_comune;
$ente->id_provincia = $ente->id_provincia == null ? 'Dato mancante' : Provincia::on($this->connection)->find($ente->id_provincia)->nome;
$ente->cap = $ente->cap == null ? 'Dato mancante' : $ente->cap;
$ente->cellulare = $ente->cellulare == null ? 'Dato mancante' : $ente->cellulare;
$ente->telefono = $ente->telefono == null ? 'Dato mancante' : $ente->telefono;
$ente->fax = $ente->fax == null ? 'Dato mancante' : $ente->fax;
return $ente;
}
}
https://stackoverflow.com/questions/71840595
复制相似问题