Skip to content

Commit

Permalink
Filament - Add missing model relation methods (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson authored Nov 29, 2023
1 parent 78aaa9c commit 5bb4220
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/core/src/Models/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lunar\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Lunar\Base\BaseModel;
Expand Down Expand Up @@ -63,4 +64,18 @@ public function channelable()
{
return $this->morphTo();
}

/**
* Return the products relationship
*/
public function products(): MorphToMany
{
$prefix = config('lunar.database.table_prefix');

return $this->morphedByMany(
Product::class,
'channelable',
"{$prefix}channelables"
);
}
}
14 changes: 14 additions & 0 deletions packages/core/src/Models/CustomerGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lunar\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Lunar\Base\BaseModel;
use Lunar\Base\Traits\HasDefaultRecord;
use Lunar\Base\Traits\HasMacros;
Expand Down Expand Up @@ -49,4 +50,17 @@ public function customers()
"{$prefix}customer_customer_group"
)->withTimestamps();
}

/**
* Return the product relationship.
*/
public function products(): BelongsToMany
{
$prefix = config('lunar.database.table_prefix');

return $this->belongsToMany(
Product::class,
"{$prefix}customer_group_product"
)->withTimestamps();
}
}

0 comments on commit 5bb4220

Please sign in to comment.