I hereby claim:
- I am joetannenbaum on github.
- I am joetannenbaum (https://keybase.io/joetannenbaum) on keybase.
- I have a public key whose fingerprint is D9E1 01CB 874D 4BD5 78AF 3CE1 51CD 2476 414B 2083
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| <?php | |
| class CreateHistoryTable extends Migration | |
| { | |
| public function up() | |
| { | |
| Schema::create('history', function (Blueprint $table) { | |
| $table->increments('id'); | |
| // Which table are we tracking | |
| $table->string('reference_table'); |
| <?php | |
| public function updated($model) | |
| { | |
| $this->track($model); | |
| } |
| <?php | |
| trait TracksHistoryTrait | |
| { | |
| protected function track(Model $model, callable $func = null, $table = null, $id = null) | |
| { | |
| // Allow for overriding of table if it's not the model table | |
| $table = $table ?: $model->getTable(); | |
| // Allow for overriding of id if it's not the model id | |
| $id = $id ?: $model->id; |
| <?php | |
| class MyModelObserver | |
| { | |
| use TracksHistoryTrait; | |
| public function updated(MyModel $model) | |
| { | |
| $this->track($model); |
| <?php | |
| class MyModel extends Model | |
| { | |
| public function history() | |
| { | |
| return $this->morphMany(History::class, 'my_model_table', 'reference_table', 'reference_id'); | |
| } | |
| } |
| <?php | |
| use Hashids\Hashids; | |
| class Hasher | |
| { | |
| public static function encode(...$args) | |
| { | |
| return app(Hashids::class)->encode(...$args); | |
| } |
| <?php | |
| $hashed_id = Hasher::encode(1); | |
| $id = Hasher::decode($hashed_id); |
| <?php | |
| Route::bind('id', function ($id) { | |
| return Hasher::decode($id); | |
| }); |