При создании связки создается ui, но не возвращает значение id.
Model test:
class test extends Model
{
use HasFactory;
protected $guarded = [];
public function ui_name() {
return $this->belongsTo('App\Models\Uis', 'name_id', 'id');
}
public function ui_desc() {
return $this->belongsTo('App\Models\Uis', 'desc_id', 'id');
}
}
UI Model:
class Uis extends Model
{
use HasFactory;
protected $guarded = [];
public function category() {
return $this->hasOne('App\Models\Categories\Category', 'ui_id', 'id');
}
public function tag() {
return $this->hasOne('App\Models\Tags\Tag', 'ui_id', 'id');
}
public function test_name() {
return $this->hasOne('App\Models\Tests\test', 'name_id', 'id');
}
public function test_desc() {
return $this->hasOne('App\Models\Tests\test', 'desc_id', 'id');
}
}
Controller:
$test = new test();
$test->ui_name()->create([
'text' => "TEXT",
'desc'=> "TEXT",
'module_id' =>1,
'isHTML' => false
]);
tests table:
Schema::create('tests', function (Blueprint $table) {
$table->id();
$table->bigInteger('name_id');
$table->bigInteger('desc_id')->nullable();
$table->integer('max_ball')->default(20);
$table->string('password')->nullable();
$table->string('special_link')->unique()->nullable();
$table->timestamps();
});
uis table:
$table->id();
$table->string('text');
$table->text('desc');
$table->bigInteger('module_id')->nullable();
$table->boolean('isHTML')->default(false);
$table->timestamps();
Warning:
ErrorException
Trying to get property 'id' of non-object