refactoring on Articles, minor fixes
This commit is contained in:
43
app/Repositories/Shop/ArticleSiblings.php
Normal file
43
app/Repositories/Shop/ArticleSiblings.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ArticleSiblings
|
||||
{
|
||||
public static function getSiblingsIDs($id)
|
||||
{
|
||||
return self::getSiblings($id)->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getSiblingsDescriptions($id)
|
||||
{
|
||||
$data = [];
|
||||
$siblings = self::getSiblings($id);
|
||||
foreach ($siblings as $sibling) {
|
||||
if ($sibling->description && ($sibling->article_nature->name ?? false)) {
|
||||
$data[strtolower($sibling->article_nature->name)] = $sibling->description;
|
||||
}
|
||||
}
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getSiblings($id)
|
||||
{
|
||||
return Article::with([
|
||||
'siblings' => function ($query) use ($id) {
|
||||
$query->where('id', '!=', $id);
|
||||
},
|
||||
])->find($id)->siblings;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user