Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Maartencast's avatar

Php artisan commands break, unless I use '['attr']' instead of '->attr'

So as the title states, I was having problems with running php artisan. Checking the laravel.log brought me to my custom HtmlBuilder:

class HtmlBuilder extends \Collective\Html\HtmlBuilder {

    function __construct()
    {
            $this->accessibleSlugs = auth()->user()->accessibleSlugs;
    }


//in the Admin model...
public function getAccessibleSlugsAttribute()
{
    return static::$roleSlugs[$this->role];
}

When I comment the line out, php artisan works properly again. Weird thing is this code runs fine, and I am also using this in a routeMiddleware where it doesn't cause problems to php artisan. Basicly accessing anything on the authenticated user's model, from within the HtmlBuilder's contstruct, breaks artisan. But when I did some further digging, this seemed to work..

function __construct()
{
    $this->accessibleSlugs = auth()->user()['accessibleSlugs'];     
}

I have no idea why I should use [] instead of -> , It seemed to be a proper Admin model instance. Hopefully someone here can give me some direction to why this is happening ;)

0 likes
3 replies
shez1983's avatar

try:

accessibleSlugs change to:

accessible_slugs

1 like
Maartencast's avatar
auth()->user()->accessible_slugs; 

seems to run the application, but still breaks artisan commmands :(.

When I try a function:

auth()->user()->getAccessibleSlugs();

Artisan returns " Call to a member function getAccessibleSlugs() on null", even though the function exists and the application runs.

Please or to participate in this conversation.