Magick Method Laravel IDE x Qodana
Bug description
i am having alert with magic code generation in laravel IDE and Qodana
Plugin version
7.2.0.232
Operating system
Windows
Steps to reproduce
No response
Relevant log output
No response
Hello, Elvis. Have you generated a helper code? If yes, could you show the migration code for this field?
Schema::create('safira.sisobra_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('usuario_id')->nullable(false)->comment('Usuário')->constrained('geral.usuarios')->onUpdate('cascade')->onDelete('restrict');
$table->foreignId('documento_id')->nullable(false)->comment('Documento Alvará/Habite-se')->constrained('geral.documentos')->onUpdate('cascade')->onDelete('restrict');
$table->string('codigo')->default(false)->comment('Código');
$table->tinyText('descricao')->default(false)->comment('Descrição');
$table->longText('xml')->default(false)->comment('XML');
$table->softDeletes()->comment('Excluído Logicamente');
$table->timestamp('created_at')->useCurrent()->comment('Criado');
$table->timestamp('updated_at')->useCurrent()->comment('Alterado');
});
Could you also share a model class? How is the table calculated? $table field?
<?php
namespace App\Models\Safira;
use App\Models\Contribuinte;
use App\Models\Documento;
use App\Models\Usuario;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
class SisObraLog extends Model
{
use SoftDeletes;
protected $table = 'safira.sisobra_logs';
public function usuario(): BelongsTo
{
return $this->BelongsTo(Usuario::class);
}
public function documento(): BelongsTo
{
return $this->BelongsTo(Documento::class);
}
public function contribuinte(): HasManyThrough
{
return $this->hasOneThrough(Contribuinte::class, Usuario::class, 'id', 'id', 'usuario_id', 'contribuinte_id');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('safira.sisobra_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('usuario_id')->nullable(false)->comment('Usuário')->constrained('geral.usuarios')->onUpdate('cascade')->onDelete('restrict');
$table->foreignId('documento_id')->nullable(false)->comment('Documento Alvará/Habite-se')->constrained('geral.documentos')->onUpdate('cascade')->onDelete('restrict');
$table->string('codigo')->default(false)->comment('Código');
$table->tinyText('descricao')->default(false)->comment('Descrição');
$table->longText('xml')->default(false)->comment('XML');
$table->softDeletes()->comment('Excluído Logicamente');
$table->timestamp('created_at')->useCurrent()->comment('Criado');
$table->timestamp('updated_at')->useCurrent()->comment('Alterado');
});
DB::unprepared('ALTER TABLE IF EXISTS safira.sisobra_logs OWNER TO safira;');
DB::unprepared("INSERT INTO safira.tabela_auditadas(tabela, ativo) VALUES ('sisobra_logs', 't');");
}
public function down(): void
{
Schema::dropIfExists('safira.sisobra_logs');
}
};
CREATE TABLE "safira"."sisobra_logs" (
"id" int8 NOT NULL DEFAULT nextval('"safira".sisobra_logs_id_seq'::regclass),
"usuario_id" int8 NOT NULL,
"documento_id" int8 NOT NULL,
"codigo" varchar(255) COLLATE "pg_catalog"."default" NOT NULL DEFAULT '0'::character varying,
"descricao" varchar(255) COLLATE "pg_catalog"."default" NOT NULL DEFAULT '0'::character varying,
"xml" text COLLATE "pg_catalog"."default" NOT NULL DEFAULT '0'::text,
"deleted_at" timestamp(0),
"created_at" timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "sisobra_logs_pkey" PRIMARY KEY ("id"),
CONSTRAINT "safira_sisobra_logs_documento_id_foreign" FOREIGN KEY ("documento_id") REFERENCES "geral"."documentos" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "safira_sisobra_logs_usuario_id_foreign" FOREIGN KEY ("usuario_id") REFERENCES "geral"."usuarios" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
)
;
Thank you. I'll check.
hi, did you manage to check
Yes. Laravel Idea didn't know about "tinyText" method :( Sorry. It's fixed, and the new version will be released next week, I hope.
there are some other types of fields inside laravel, depending on the database you use
I know... I have to hard-code them.
could you check for me this alert
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Estado extends Model
{
protected $with = ['pais:id,nome,iso2'];
protected $table = 'geral.estados';
protected $fillable = ['nome', 'pais_id'];
protected $hidden = ['pais_id'];
public function pais(): BelongsTo
{
return $this->belongsTo(Pais::class, 'pais_id', 'id');
}
public function cidades(): HasMany
{
return $this->hasMany(Cidade::class);
}
public static function firstOrCreateEstado($value, Pais $pais): Estado
{
return Estado::where('id', '=', $value['estado']['id'] ?? null)->firstOr(function () use ($value, $pais) {
return Estado::firstOrCreate([
'nome' => $value['estado']['nome'],
'pais_id' => $pais->id,
]);
});
}
}
Laravel Idea suppresses these warnings for PhpStorm. However, Qodana uses its own inspections... maybe later, I could suppress them too.