tighten / parental

Use single table inheritance in your Laravel app
MIT License
1.36k stars 98 forks source link

Set attributes on child Models #74

Closed AniketMagadum closed 1 year ago

AniketMagadum commented 4 years ago

I have created a Admin model which is the child of the User Model

class Admin extends User
{
    use \Parental\HasParent;

    protected $fillable = ['contact'];
}

I have a extra attribute for the Admin model called contact and have also created a migration for the same

Schema::create('admins', function (Blueprint $table) {
   $table->bigIncrements('id');
   $table->string('contact');
   $table->timestamps();
});

But when I am trying to insert the attribute, a entry is created in the users table but there is no entry in the admins table. I am not understanding how can I add custom attributes to child models. This is the code I am writing to create a Admin Record

 App\Admin::create([
   'name'=> "Aniket Magadum",
   "email" => "aniket.magadum@sts.in",
   "password" => "password",
   "contact" => "8286000000"
 ]);
roni-estein commented 4 years ago

I'm no expert I was just reading this package to see what it did, but this is an STI (Single Table Inheritance) package as I understand it so you are not going to make another 'admins' table you are going to add contact to you users table. Then use users for BOTH you users and admins

mattstauffer commented 1 year ago

Hey friends! The team at Tighten has taken Parental back over and we're re-opening the issue tracker, but to give us a clean slate, I'm going to close all old issues that remain from when Caleb closed the issue tracker in 2020. If this is still an outstanding concern with the latest version of Parental, please feel free to open a new issue referencing this one.

Thank you!