My code is not readable and hard to scale.
<?php
namespace App\Services;
use App\Models\BlogCategory;
use Illuminate\Database\Eloquent\Collection;
Class BlogServices
{
public function getCategoriesByUserAndCompany(int $user_id, array $company_ids): Collection
{
return BlogCategory::whereHas('user', function ($query) use ($user_id) {
$query->where('user_id',$user_id);
})->orWhereHas('company', function ($query) use ($company_ids) {
foreach($company_ids as $id) {
$query->oRwhere('company_id',$id);
}
})->get();
}
}
I need to get all categories that are related to companies and users. BlogCategory related many to many with User BlogCategory related many to many with Company
Sorry for my english, thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire