File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/Components/ComponentArea/HasComponentAreasTrait.php
<?php
namespace App\Components\ComponentArea;
use App\Components\Component\Component;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\MorphMany;
/**
* Trait HasDynamicGroupSectionsTrait
*
* Can be used by your models to get their dynamicGroupSections
*
* @package App\Components\Section
*/
trait HasComponentAreasTrait
{
public function componentAreas():MorphMany
{
return $this->morphMany(ComponentArea::class, 'componentable');
}
// Grab all components of all component areas
public function components()
{
// First we need to get the component areas
$componentAreas = $this->componentAreas;
// Return empty collection if no componentAreas are bind
if($componentAreas->count() == 0) return collect();
if($componentAreas->count() > 1){
dd('HasComponentAreasTrait: Functionality hasnt been tested for more then 1 area. I question if the orderBy sort_order still works like it should because there will be duplicate sort_orders');
}
return Component::whereIn('component_area_id', $this->componentAreas->pluck('id')->toArray())
->orderBy('sort_order')
->get();
}
}