beyondcode / invoker-community

74 stars 2 forks source link

Fail to get Model Definition - Laravel 8.54 using PHP 7.4 #280

Closed patrickmaciel closed 6 months ago

patrickmaciel commented 2 years ago

For me the relationship is working well. But for Invoker not.

What's wrong with the code?

I get that error when I double click the column departamento_id on table.


OS: win32 Invoker Version: 2.8.0 Laravel Version: 8.83.4 Local project: true PHP Binary: C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64\php.exe Route: /project/index?class=App%5CModels%5CUser&time=1647875104783&project=local-aZB7GtWfSH85Rt6kgxfgBv

Error:

Error 

  Class '' not found

  at phar://C:/Users/patri/AppData/Local/Programs/Invoker/resources/invoker.phar/src/Actions/GetModelDefinitionAction.php:18
     14▕     private $baseModel;
     15▕     public function __construct(string $basePath, $request)
     16▕     {
     17▕         $this->className = $request->model;
  ➜  18▕         $this->baseModel = new $this->className();
     19▕     }
     20▕     public function execute()
     21▕     {
     22▕         $attributes = $this->getAttributes();

  1   phar://C:/Users/patri/AppData/Local/Programs/Invoker/resources/invoker.phar/src/ActionInvoker.php:65
      _HumbugBoxcd54a32bc978\Invoker\Actions\GetModelDefinitionAction::__construct("C:\laragon\www\precdash-develop", Object(stdClass))

  2   phar://C:/Users/patri/AppData/Local/Programs/Invoker/resources/invoker.phar/src/ActionInvoker.php:26
      _HumbugBoxcd54a32bc978\Invoker\ActionInvoker::setUpAction(Object(stdClass))

Tha's my User.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens;
    use HasFactory;
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var string[]
     */
    protected $fillable = ['perfil_id', 'departamento_id', 'telefone', 'name', 'email', 'password', 'photo', 'facebook_id', 'google_id'];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array
     */
    protected $hidden = [
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function perfil()
    {
        return $this->belongsTo(Perfil::class, 'perfil_id');
    }

    public function departamento()
    {
        return $this->belongsTo(Departamento::class, 'departamento_id');
    }
}

And that's my Departamento.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Departamento extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'departamentos';
    protected $fillable = ['nome', 'descricao'];

    public function users()
    {
        return $this->hasMany(User::class, 'departamento_id');
    }
}