Framework: Use Auth in construct method

Created on 8 Mar 2018  路  1Comment  路  Source: laravel/framework

  • Laravel Version: 5.6.*
  • PHP Version: 7.2.2
  • Database Driver & Version: Mysql 5.0.12

Description:

I need return logged user in contruct method

Steps To Reproduce:

I need return logged user in contruct method,

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Menu;
use View;
use Session;
use Redirect;
use App\User;
use App\UserPermissions;
use Auth;
use DB;


class GerencialController extends Controller{
    public function __construct(){

        $this->menu = new Menu();

        $this->menu->getEnabledMenu();

        $this->categories = $this->
        menu::with('children')->
        where('parent_id','=',0)->
        whereIn('id', [8,9,7])->
        orderBy('position', 'asc')->
        get();
    }

i tried with $this->user->Auth::user()->id; but this doesn't work

i also tried this

https://laravel-news.com/controller-construct-session-changes-in-laravel-5-3

$this->middleware(function ($request, $next) {
        $this->user= Auth::user();

        return $next($request);
    });

but i I do not know how to access $this->user

please
i need help

sorry for my english

Most helpful comment

Welcome to Laravel! We are glad to have you as part of the community.

Unfortunately GitHub is not an appropriate platform for general application issues. This is only for issues/bugs with the framework code itself.

Please close your issue, and instead try asking your question on one of the many great community support areas that will likely give you a better answer more quickly:

Laravel Slack (https://larachat.co/)
Laravel.io Forum (https://laravel.io/forum)
Laracasts Forum (https://laracasts.com/discuss)
StackOverflow (http://stackoverflow.com/questions/tagged/laravel)

Thanks!

>All comments

Welcome to Laravel! We are glad to have you as part of the community.

Unfortunately GitHub is not an appropriate platform for general application issues. This is only for issues/bugs with the framework code itself.

Please close your issue, and instead try asking your question on one of the many great community support areas that will likely give you a better answer more quickly:

Laravel Slack (https://larachat.co/)
Laravel.io Forum (https://laravel.io/forum)
Laracasts Forum (https://laracasts.com/discuss)
StackOverflow (http://stackoverflow.com/questions/tagged/laravel)

Thanks!

Was this page helpful?
0 / 5 - 0 ratings