首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >->user()返回NULL

->user()返回NULL
EN

Stack Overflow用户
提问于 2022-04-12 09:53:26
回答 1查看 337关注 0票数 0

我的项目在本地服务器上运行良好,但是当我将它部署到生产服务器上时,我的中间件不起作用,我使用卫队来限制经过身份验证的用户访问页面,但是当我将路由放在组中间件中时,它总是返回未经身份验证的.在网上找到了很多解决方案,但到目前为止没有什么有用的.

代码语言:javascript
代码运行次数:0
运行
复制
Route::middleware(['auth:admin'])->group(function () {

Route::get('notifications',Notifications::class);

});

代码语言:javascript
代码运行次数:0
运行
复制
       'web' => [
           'driver' => 'session',
           'provider' => 'users',
       ],
       'admin' => [
           'driver' => 'session',
           'provider' => 'admins',
       ],
     
   ],```
EN

回答 1

Stack Overflow用户

发布于 2022-04-12 10:22:18

这个问题可能是由路由组声明引起的。试着像这样声明:

代码语言:javascript
代码运行次数:0
运行
复制
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']);
});

编辑:带电控制器示例

代码语言:javascript
代码运行次数:0
运行
复制
<?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;
    }
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71840595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档