rmasters / culpa Goto Github PK
View Code? Open in Web Editor NEWA Blameable-type extension for Laravel's ORM Eloquent.
License: MIT License
A Blameable-type extension for Laravel's ORM Eloquent.
License: MIT License
So the idea would be to have:
class Post {
use Culpa\CreatedBy;
use Culpa\UpdatedBy;
}
Which would auto-register the hooks and methods for createdBy
and updatedBy
, rather than having them available anyway.
Use-case I've just come across is having a nullable datetime field, that once set would be nice to automatically assign who set it (separate from updated_at). E.g.:
$table->datetime('scheduled_at')->nullable();
$table->integer('scheduled_by_id')->unsigned();
$table->foreign('scheduled_by_id')->references('id')->on('users');
Potential model syntax:
class Broadcast extends Model {
protected $blameable = ['created'];
protected $blameable_extra = ['scheduled_at' => 'scheduled_by_id'];
}
Then setting scheduled_at
sets scheduled_by_id
to the current user.
A nice-to-have if it's possible to add these - emulate the timestamps() helper for schema building:
Schema::create('comments', function($table) {
$table->increments('id');
$table->createdBy();
$table->updatedBy();
$table->deletedBy();
});
Aliasing to something like:
$table->integer('created_by_id')->unsigned();
$table->foreign('created_by_id')->references('id')->on(Config::get('culpa::users.table'));
Might be a Laravel issue, the following does not work:
class Post extends Eloquent {
public function createdBy() {
// Culpa\CreatedBy
return $this->belongsTo('User')->withTrashed();
}
}
Post::with('createdBy')->get();
Results in "Invalid argument supplied for foreach()" in Illuminate/Database/Eloquent/Builder.php:388 ($this->query->wheres
is null).
While traits are PHP 5.4 and above, we still have a lot of people on 5.3 (even if it is EOL soonish).
It may be possible to pull the set-current-user-automatically parts into model hooks that are applied to all model events. So while 5.3 users would still have to define methods like createdBy()
, updatedBy()
on their models, the automatic-set part could be picked up automatically (I think the only user change would be making Model::$blameable
public rather than protected).
Hello, this is an amazing package I must say, but I'm having trouble to have the deleted_by_id field which is not being set after a softdelete. I can see that the delete_at field is updated as the updated_by_id, but not the deleted_by_id. I'm using the most recent version of Laravel:
"laravel/framework": "4.2.*",
"rmasters/culpa": "dev-master"
For my host I'm using the Laravel's Homestead via vagrant.
Any thoughts?
Appreciate your work and feedback! :)
Hi could you please add
public function restoring(Model $model) {
$model->{$this->getColumn($model, 'deleted')} = null;
}
to the BlameableObserver, in order to also restore the deleted_by column when restoring a soft-deleted model
Thank you
Naughty me...
Is it possible for you to add support for sentry 2?
http://docs.cartalyst.com/sentry-2
You can do Sentry::user()->id to get the user id
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.