I have 2 models: "benefactor" and "abilities".
The benefactor table has a column named "abilities_id" and it has more than one value, like "AB2,AB3".
In the abilities table these ids have names. For example: "AB2 = Money Resource", and "AB3 = Language Skills"
How can I get the names of abilities with relationships in Laravel?
Assuming Your Data Structure Like This :
benefactor
Table -
benefactor_id | abilities_id
: 1 | AB2
, 2 | AB3
abilities
Table -
abilities_id | names
: AB2 | Money Resource
, AB3 | Language Skills
Using Query Builder Solution Would Be :
$names = DB::table('abilities as a')
->join('benefactor as b', 'b.abilities_id', '=', 'a.abilities_id')
->get(['a.names']);
Change the field names according to your needs.