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

rhand's avatar
Level 6

Undefined method 'isEditor' in backups controller

I am using a controller to run backups for customers. I defined several roles in app/Traits/Models/UserHelper.php to decide who can do what. In the controller I have

<?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Models\Editor\Project;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Traits\Models\UserHelper;

/**
 * Client Backup Resource Controller
 * https://laravel.com/docs/9.x/controllers#resource-controllers
 * 
 */
class BackupsController extends Controller
{
    // load the dashboard backups overview for clients
    public function index()
    {
        if (Auth::user()->isEditor()) {
            $projects = Auth::user()->editorProjects;
        } else {
            $projects = Auth::user()->company->projects()
                            ->whereNull('project_id')
                            ->get();
        }

        $selectProject = Project::find(request()->id) ?: $projects->first();

        return view('dashboard.backups.index', [
            'projects' => $projects,
            'selectProject' => $selectProject,
        ]);
    }

    /**
     * Backup client projects
     * POST, /store action, route backups.store
     */
    public function store()
    {
        $project = Auth::user()->company->projects()->findOrFail(request()->project_id);
        $backup = $project->backups()->find(request()->backup);

        if (! $backup) {
            return redirect()->back()
                ->with('exception', 'Please select a backup');
        }

        (new \App\Services\ProjectBackupService($project))->restore($backup);

        return redirect()->back()
                    ->with('saved-success', 'Project has been backed up successfully');
    }
}

I am getting Undefined method 'isEditor'.intelephense(1013) for the editor check. The method isEditor() is in app/Traits/Models/UserHelper.php and I added use App\Traits\Models\UserHelper; to the controller, but it is not being used for some reason.

I tried doing a check for just isEditor instead of if (Auth::user()->isEditor()) { but that still gives me another error

Undefined function 'App\Http\Controllers\Dashboard\isEditor'.intelephense(1010)

in Visual Studio code.

What and I missing here?

0 likes
5 replies
SilenceBringer's avatar

@rhand

The method isEditor() is in app/Traits/Models/UserHelper.php and I added use App\Traits\Models\UserHelper; to the controller, but it is not being used for some reason.

if you call the isEditor method on user - you need to use this trait in your User model

try to add use App\Traits\Models\UserHelper to User model

1 like
rhand's avatar
Level 6

@SilenceBringer use App\Traits\Models\UserHelper; is already added to app/Models/Auth/User.php and the UserHelper does have

...
/**
  * Check user is editor.
 * @return bool
  */
 public function isEditor()
  {
    return $this->role && $this->role->name === UserRole::EDITOR;
 }
...

but it seems the user being loaded is Illuminate\Support\Facades\Auth::user

tykus's avatar

@rhand the "problem" is your IDE does not know that Auth::user() returns an App\Models\User instance; it know that it gets Illuminate\Foundation\Auth\User instance instead (which does not have the trait mentioned).

1 like
rhand's avatar
Level 6

@tykus I even have Barry's IDE helper but it does not seem to help now somehow. Any tips on how to make the IDE understand this all?

tykus's avatar
tykus
Best Answer
Level 104

@rhand introduce a variable if this IDE "error" annoys you:

/** @var \App\Models\User $user */
$user = auth()->user();
if ($user->isEditor()) {
    $projects = $user->editorProjects;

Please or to participate in this conversation.