albinodrought / laravel-fillable-relations
This package is abandoned and no longer maintained.
No replacement package was suggested.
Provides HasFillableRelations trait to Eloquent models
v1.1.0
2018-04-26 23:07 UTC
Requires
- illuminate/database: ~5.5
Requires (Dev)
- php: ~7.1
- ext-sqlite3: *
- orchestra/database: ~3.5
- orchestra/testbench: ^3.5
- phpunit/phpunit: ~7.0
This package is not auto-updated.
Last update: 2020-01-24 17:53:01 UTC
README
This library provides a trait for mixing in to an Eloquent Model. Doing so will enable support for fillable relations.
This is a stricter, versioned, and opinionated fork of https://github.com/troelskn/laravel-fillable-relations
Installation
composer require albinodrought/laravel-fillable-relations
Usage
First, in your model:
<?php namespace MyApp\Models; use Illuminate\Database\Eloquent\Model; use LaravelFillableRelations\Eloquent\Concerns\HasFillableRelations; class Foo extends Model { use HasFillableRelations; protected $fillableRelations = ['bar']; function bar() { return $this->hasOne(Bar::class); } } class Bar extends Model { use HasFillableRelations; protected $fillableRelations = ['foos']; function foos() { return $this->hasMany(Foo::class); } }
And you can now fill relations, like so:
<?php $foo = new Foo( [ 'cuux' => 42, 'bar' => [ 'id' => 42 ] ] );
Or perhaps:
<?php $foo = new Foo( [ 'cuux' => 42, 'bar' => [ 'name' => "Ye Olde Pubbe" ] ] );
And also:
<?php $bar = new Bar( [ 'name' => "Ye Olde Pubbe", 'foos' => [ [ 'cuux' => 42 ], [ 'cuux' => 1337 ] ] ] );
Testing
composer test