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?