-1
Error:
Auth::user()->id trying to get a property of a non-object
Model:
<?php
namespace App\Models;
use App\Scopes\Tenant\TenantScope;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
class Devedor extends Model
{
protected $fillable = [
'nome',
'endereco',
'logradouro',
'numero',
//code
];
public static function boot()
{
parent::boot();
//$user = User::isAdmin();
$usuario = User::findOrfail(Auth::user()->id); //Erro aqui
$usuario->existePapel('Admin');
if ($user) {
echo "Usuario encontrado";
}
static::addGlobalScope(new TenantScope);
}
}
Auth::user()
there’s something here, and another question, you’re logged in?– novic
Yes, I’m logged in, but it’s not working inside the model
– André Cabral
I think it’s weird, but, um,
var_dump(Auth::user())
and check what returns, what you did if you are logged in works ...– novic
Thanks Virgilio, but I’ve already solved with Guilherme’s tip
– André Cabral
You solved apparently ... but, broke the code, because if this is not working when the user is theoretically logged in (
Auth::user()->id
) your code has problems.– novic
Another thing, if you’re doing it in the wrong place, you should have (
middleware
) to verify this, being that this is done in the routes– novic
Yes, I am using
Middleware
and that’s the weirdest thing about it not workingAuth::user()->id
– André Cabral
look I don’t know what you’re doing, but if it doesn’t work with the login successfully ta wrong and something else there is in the
model
shouldn’t be there ... well are only alerts– novic
I’ll find out for sure. Thank you Virgilio
– André Cabral