Open realtebo opened 6 years ago
I ended up with something like this:
You create create your pivot table with an id
Schema::table('post_user', function (Blueprint $table) {
$table->bigIncrements('id')
$table->unsignedBigInteger('post_id');
$table->unsignedBigInteger('user_id');
});
You create a model class for this
namespace App;
use Eloquent;
use Venturecraft\Revisionable\RevisionableTrait;
class PostUser extends Pivot
{
use RevisionableTrait;
public $incrementing = true;
public $timestamps = false;
protected $revisionCreationsEnabled = true;
}
Now the most stupid part. You can no longer user $user->attach($post)
because this will not trigger the saved event of the PostUser class.
You need to create this entry manually
PostUser::create([
'user_id' => $user->id,
'post_id' => $post_id
]);
Looking for better solution :(
I cannot figure how log events for records in the pivot table.
I m starting using your package because is so easy. But how can I tell laravel to use your code when using a n to n relation table?