Search code examples
laraveleloquenteloquent-relationship

relational database in eloquent laravel


hay i have table schema like this

table transaction_fueler

id | code | user_id |user_name| ref_code | area_name

table user_community

user_id | community_id

table user_community is pivot table from table users and community

in table transaction_fueler i want to get community_id from table user_community, depends on user_id* in **transaction_fueler how to get community_id depends on user_id in table transaction_fueler ??

i stuck this.. thanks


Solution

  • i recommend joining the two tables and select the columns you want:

      $values = DB::table('transaction_fueler')
                ->join('user_community', 'user_community.user_id', '=', 'transaction_fueler.user_id')
                ->select('transaction_fueler.*', 'user_community.community_id')->get();