File: /home/imensosw/www/mpl.imenso.co/app/Repositories/GenreRepository.php
<?php
namespace App\Repositories;
use App\Models\Genre;
use Illuminate\Support\Collection;
class GenreRepository extends Repository
{
public $top_only = false;
public static function topOnly($top_only)
{
$repo = new self;
$repo->top_only = $top_only;
return $repo;
}
public function get()
{
if ($this->top_only == true) {
$genres = Genre::where('parent_id', 0)->get();
} else {
$genres = Genre::all();
}
foreach ($genres as $g_item) {
$this->items->push($g_item);
}
return $this->items;
}
public function prepareForExternalUse()
{
$flattened = new Collection;
foreach ($this->items as $item) {
$data = $item->toArray();
$flattened->push($data);
}
return $flattened;
}
}