cybercog / laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.
https://komarev.com/sources/laravel-ownership
MIT License
89 stars 16 forks source link

Overwrite owner on create #6

Closed antonkomarev closed 5 years ago

antonkomarev commented 7 years ago
$owner = NotUserModel::first();
OwnableModel::withDefaultOwner($owner)->create([
    'title' => 'Test title',
]);
OwnableModel::create([
    'title' => 'Test title',
])->withDefaultOwner($owner);

Both of this variants wouldn't work.

To set owners on creation this variants could be used:

$owner = NotUserModel::first();
$model = OwnableModel::create([
    'title' => 'Test title',
]);
$model->withDefaultOwner($owner);
$model->save();
$owner = NotUserModel::first();
$model = (new OwnableModel([
    'title' => 'Test title',
]))->withDefaultOwner($owner)->save();