F
Filament10mo ago
Avriant

How to query data from 20+ tables and pass it as a single variable to a View: UNION? JOIN?

Laravel/Filament V2 First Time Project Imagine something like this: Table 1 "Company" columns: id, name Table 2 "Company Members" columns: id, company_id, total_members, members_10s, members_20s Table 3 "Company Achievements" columns: id, company_id, scale, projects The method below requires my tables to have same fields, which just does not make sense to me (how can I put number of members into the same field as company name?). https://jianjye.medium.com/how-to-search-multiple-models-easily-with-laravel-eloquent-without-using-packages-d8773c43eda9 ANY video I managed to find on YouTube ALWAYS has literally one table for users and one table for entity and does not have anything specific for this mess. I've been staring at my app\Http\Controllers\CompanyController.php for the past 2 days, but staring seems to be not a solid strategy to resolve my conundrum
$companies = Company::query()
->where('created_at', '!=', NULL)
->orderBy('created_at', 'desc')
->paginate();

$members = CompanyMembers::query()
>select('')
->where('company_id', 'LIKE', )
->get();

$achievements = CompanyAchievements::query()
->select('')
->where('', 'LIKE', )
->get()

$companyData = $companies->union($members)->union($achievements)->get();
$companies = Company::query()
->where('created_at', '!=', NULL)
->orderBy('created_at', 'desc')
->paginate();

$members = CompanyMembers::query()
>select('')
->where('company_id', 'LIKE', )
->get();

$achievements = CompanyAchievements::query()
->select('')
->where('', 'LIKE', )
->get()

$companyData = $companies->union($members)->union($achievements)->get();
Please, show me the way
https://tenor.com/view/adam-levine-embarrassed-gif-21343983
Medium
How to search multiple models easily with Laravel Eloquent without ...
Recently at work, I have to implement a quick search that searches across multiple models and return a unified list of results. I thought I…
Tenor
0 Replies
No replies yetBe the first to reply to this messageJoin