change homepages to contents, add new methods to deliveries and sale_channels by customer
This commit is contained in:
@@ -18,7 +18,6 @@ use Kirschbaum\PowerJoins\PowerJoins;
|
||||
use Rinvex\Categories\Traits\Categorizable;
|
||||
use Rinvex\Tags\Traits\Taggable;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
use Venturecraft\Revisionable\RevisionableTrait;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Homepage extends Model
|
||||
class Content extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table = 'shop_homepages';
|
||||
protected $table = 'shop_contents';
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -4,12 +4,13 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
use Venturecraft\Revisionable\RevisionableTrait;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
class Delivery extends Model
|
||||
{
|
||||
use RevisionableTrait, SoftDeletes, Userstamps;
|
||||
use HasRelationships, RevisionableTrait, SoftDeletes, Userstamps;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
@@ -34,7 +35,7 @@ class Delivery extends Model
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany(Customer::class);
|
||||
return $this->hasManyThrough(Customer::class, CustomerSaleChannel::class);
|
||||
}
|
||||
|
||||
public function sale_channel()
|
||||
@@ -67,6 +68,11 @@ class Delivery extends Model
|
||||
return $query->where($this->table.'.at_house', 1);
|
||||
}
|
||||
|
||||
public function scopeBySaleChannels($query, $ids)
|
||||
{
|
||||
return $query->whereIn($this->table.'.sale_channel_id', $ids);
|
||||
}
|
||||
|
||||
public function scopeBySaleChannel($query)
|
||||
{
|
||||
return $query->where($this->table.'.sale_channel_id', 1);
|
||||
@@ -81,4 +87,11 @@ class Delivery extends Model
|
||||
{
|
||||
return $query->byPublic(1);
|
||||
}
|
||||
|
||||
public function scopeByCustomer($query, $customerId)
|
||||
{
|
||||
return $query->whereHas('customers', function($query) use ($customerId) {
|
||||
return $query->byId($customerId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class Price extends Model
|
||||
{
|
||||
use HasRelationships;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table = 'shop_prices';
|
||||
|
||||
Reference in New Issue
Block a user