cybercog / laravel-ownership Goto Github PK
View Code? Open in Web Editor NEWLaravel Ownership simplify management of Eloquent model's owner.
Home Page: https://komarev.com/sources/laravel-ownership
License: MIT License
Laravel Ownership simplify management of Eloquent model's owner.
Home Page: https://komarev.com/sources/laravel-ownership
License: MIT License
$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();
Could you make route middleware for ownership checking ?
So, if anyone have similar issues, plz tell me.
My models are:
User implements CanBeOwner contract
Profile use HasOwner trait
Both use SoftCascadeTrait
// in User model
public function profile(): HasOne
{
// using withTrashed() here
return $this->hasOne(Profile::class, 'owned_by_id')->withTrashed();
}
But for Profile model, I don't set this association cause it's already handled by the trait.
The problem is, when fetching Profile content, I need to configure it everytime using ->with().
$profiles = Profile::withTrashed()->with(['owner' => function ($query) {
$query->withTrashed(); // not filtering trashed owners
}])->get();
I just wanna to simplify, call it directly and stay not filtering trashed records. Any thoughts?
Could you add method(s) throwing exception when not owner ?
We need to get rid of the laravel/legacy-factory dev dependency.
This package requires total refactoring before adding new Laravel versions support and new features.
I Get Error Saying
{ "message": "Type error: Argument 1 passed to App\\Brand::changeOwnerTo() must be an instance of Cog\\Contracts\\Ownership\\CanBeOwner, instance of App\\User given, called in C:\\xampp\\htdocs\\real\\haayaa\\app\\Http\\Controllers\\Auth\\RegisterController.php on line 142", "exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError", "file": "C:\\xampp\\htdocs\\real\\haayaa\\vendor\\cybercog\\laravel-ownership\\src\\Traits\\HasMorphOwner.php", "line": 139, "trace": }
Could you add method for checking if model if owned by currently authorized user ?
Require to add events:
\Cog\Ownership\Events\OwnershipWasChanged
\Cog\Ownership\Events\OwnershipWasAbandoned
What to check:
changeOwnerTo
and abandonOwner
would be required.A time ago. I created a pr for support Laravel ban on 5.5-dev.
But now it triggers errors. So here is the stacktrace.
PS C:\Users\Gebruiker\Desktop\petition> composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for cybercog/laravel-ban dev-laravel-5.5 -> satisfiable by cybercog/lara
vel-ban[dev-laravel-5.5].
- cybercog/laravel-ban dev-laravel-5.5 requires cybercog/laravel-ownership ^3.0 -> satisfiable
by cybercog/laravel-ownership[3.0.0].
- Conclusion: remove laravel/framework 5.5.x-dev
- cybercog/laravel-ownership 3.0.0 requires illuminate/database ~5.2.0|~5.3.0|~5.4.0 -> satisfi
able by illuminate/database[5.2.x-dev, 5.3.x-dev, 5.4.x-dev, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.
2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.
0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.9].
- don't install illuminate/database 5.2.x-dev|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database 5.3.x-dev|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database 5.4.x-dev|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.0|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.19|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.21|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.24|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.25|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.26|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.27|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.28|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.31|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.32|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.37|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.43|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.45|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.6|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.2.7|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.3.0|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.3.16|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.3.23|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.3.4|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.4.0|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.4.13|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.4.17|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.4.19|don't install laravel/framework 5.5.x-dev
- don't install illuminate/database v5.4.9|don't install laravel/framework 5.5.x-dev
- Installation request for laravel/framework 5.5.* -> satisfiable by laravel/framework[5.5.x-dev].```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.