The user call in the constructor will always see null as required middleware has not yet ran, see https://stackoverflow.com/a/39175335/11995193. Note this assumes you've posted code from a controller.
For the rest of the class I'd personally add aminor refactor to make the code more readable:
class SomeClassName
{
/**
* @var array
*/
protected $defaultHiddenFields = [
'phone',
'employees',
'email',
'created_at',
'updated_at',
'id',
'description'
];
/**
* @var array
*/
protected $hidden = [];
/**
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->middleware(function ($request, $next) {
$this->user = auth()->user();
return $next($request);
});
$this->hidden = array_merge($this->hidden, $this->getHiddenUserFields());
}
/**
* @return array
*/
private function getHiddenUserFields(): array
{
$validUser = !$this->user || ($this->user && ($this->user->id !== $this->user_id));
return $validUser ? $this->defaultHiddenFields : [];
}
}