public function up()
{
//drop old table
Schema::dropIfExists('views');
$this->schema->create($this->table, function (Blueprint $table) {
$table->bigIncrements('id');
$table->uuidMorphs('viewable');
$table->text('visitor')->nullable();
$table->string('collection')->nullable();
$table->timestamp('viewed_at')->useCurrent();
});
}
Model Article
class Article extends Model implements HasMedia, Viewable
{
use Uuids;
use HasFactory;
use LogsActivity;
use InteractsWithMedia;
use DefaultOrderBy;
use SoftDeletes;
use Cachable;
use InteractsWithViews;
protected static $orderByColumn = 'created_at';
protected static $orderByColumnDirection = 'desc';
protected static $logFillable = true;
protected static $logOnlyDirty = true;
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
protected $removeViewsOnDelete = true;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'articles';
/**
* The database primary key value.
*
* @var string
*/
protected $primaryKey = 'id';
protected $keyType = 'string';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = [
'title',
'body',
'active',
'can_comment',
'user_id',
];
protected $casts = [
'active' => 'boolean',
'can_comment' => 'boolean',
];
protected $hidden = ['deleted_at'];
}
Description:
Migrations i Used uuidMorphs
Model Article
route
ArticleController
Expected behavior:
Expected add new record to views table
Actual behavior:
no record added
More Debug
add log to helper
show log