samedi 23 septembre 2017

fetch and push the data in new table

I have the table 'project','user' and 'role_mapping'.I want to to fetch the project_owner_id from the project table and push the user_id which is fetched from user table and role_id=1 in role_mapping table.one project owner has multiple project.so I want to restrict duplicate entry. I want to do it in laravel controller controller.

project table
project_id   project name project_owner_id
 1             DEC01
 2             DEC02
 3             DEC01

user table
 id user_string
 1     DEC03
 2     DEC01
 3     DEC02

role_mapping table
user_id  role_id
 2        1
 3        1     

$heads = DB::table('project')
      ->join('users', 'project.project_owner_id', '=', 'users.user_string')
      ->select('project.project_owner_id','users.id as user_id')->get();
      foreach($heads as $head){
          print_r($head->project_owner_id);  
          print_r($head->user_id);            
      }

The below query fetched project owner id and user_id.How to push the value in role_mapping table



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xpDl6L
via IFTTT

Aucun commentaire:

Enregistrer un commentaire