activity()
->performedOn($anEloquentModel)
->causedBy($user)
->withProperties(['customProperty' => 'customValue'])
->log('Look mum, I logged something');
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'category_product', 'category_id', 'product_id');
}
Schema::create('category_product', function (Blueprint $table) {
$table->primary(['category_id', 'product_id']);
$table->foreignId('category_id')->nullable();
$table->foreignId('product_id')->nullable();
});
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->foreignId('parent_id')->nullable()->constrained('categories')->cascadeOnDelete();
$table->string('name');
$table->mediumText('description')->nullable();
$table->unsignedInteger('rank')->default(0);
$table->boolean('active')->default(0);
$table->timestamps();
});
public function children(): HasMany
{
return $this->hasMany(Category::class, 'parent_id');
}
public function parent(): BelongsTo
{
return $this->belongsTo(Category::class, 'parent_id');
}
<?php
View::withCount(['orders as total_orders' => function($query) {
$query->whereRaw('date(`modx_ms2_orders`.`createdon`) = date(`modx_site_partner_views`.`date`)');
}])
->where('partner_id', auth()->user()->partner_code)
->orderByDesc('id')
->paginate(10);