7 months ago

Extend Vendor Model to include additional field

Posted 7 months ago by embold_given

I'm using a vendor package, but I wanted to add a new field to a table for a new flag value. I've gone through the migration and added the field, I can adjust it manually, that all works, but now I want to be able to adjust a form to submit to the table directly.

So far I've:

  • created a new migration to add the new field to the table (and run it to apply any structure changes)
  • created a new Model class that extends the vendor class and overrides the $fillable value to include my new field
  • created a service provider that registers an alias that, as I understand it, will direct all references to the original class at my new extended class
  • added a reference to the config\app.php to make sure that my service provider is included

Extended model declared as so:

class ForumCategory extends \Riari\Forum\Models\Category

Relevant service provider code:

        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
        $loader->alias('\Riari\Forum\Models\Category', '\App\ForumCategory');

Everything appears to be working (as I have no errors or exceptions), I'm checking the request values and the form is passing the value, all the names line up, but it's not saving the form field to the new table field as expected.

I'm a relative newcomer to Laravel but fairly savvy with PHP, so I'm assuming there's something Laravel-specific that's thwarting me. Any suggestions or general guidance would be greatly appreciated!

Please sign in or create an account to participate in this conversation.