change homepages to contents, add new methods to deliveries and sale_channels by customer

This commit is contained in:
ludo
2023-12-09 23:55:50 +01:00
parent 2a429e4163
commit 25b78f3380
28 changed files with 185 additions and 153 deletions

View File

@@ -7,11 +7,13 @@ use App\Notifications\VerifyEmail;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Venturecraft\Revisionable\RevisionableTrait;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use Yadahan\AuthenticationLog\AuthenticationLogable;
class Customer extends Authenticatable
{
use AuthenticationLogable, Notifiable, SoftDeletes;
use AuthenticationLogable, HasRelationships, Notifiable, RevisionableTrait, SoftDeletes;
protected $guarded = ['id'];
@@ -48,7 +50,10 @@ class Customer extends Authenticatable
public function deliveries()
{
return $this->belongsToMany(Delivery::class, CustomerDelivery::class);
return $this->hasManyDeepFromRelations(
$this->sale_channels(),
(new SaleChannel())->deliveries())
->whereNull('shop_customer_sale_channels.deleted_at');
}
public function sale_channels()
@@ -66,6 +71,11 @@ class Customer extends Authenticatable
return $this->hasMany(Order::class);
}
public function scopeById($query, $id)
{
return $query->where($this->table.'.id', $id);
}
public function scopeBySaleChannel($query, $saleChannelId)
{
return $query->whereHas('sale_channels', function ($query) use ($saleChannelId) {