Tengo que unirse a 6 Se puede reservar diferentes en laravel usando elocuente

votos
-1

Tengo 6 mesas diferentes en mi base de datos y tengo que ir a buscar el valor del tipo de columna, ID, título, created_at, updated_at, importados, import_url, cover_type, profile_image de los 6 mesas y algunos valores adicionales de fecha_inicial la columna y la ubicación de la tabla meetup, job_location y cmp_name de la mesa de trabajo y fecha_inicial y la ubicación de la tabla de eventos

          public function wsUserActivity(){
                       $request = Input::all();
                       try {
                                     $user_id = $request['user_id'];
                                     $no=isset($request['page_number'])?$request['page_number']:0;
                                     $nos=isset($request['count'])?$request['count']:10;
                                     $skp=$no*$nos;
                                     $array_json_return = array('status' => '1','msg' => 'Success');


                                     $u_activity = array();
                                     $u_article = DB::table('mst_article as article')
        ->select(DB::raw('article as type'),'id','title', DB::raw('DATE_FORMAT(created_at, %d %b %Y) as created_at'), DB::raw('DATE_FORMAT(updated_at, %d %b %Y) as updated_at'), 'imported', 'import_url', 'cover_type', 'profile_image')
                                     ->selectRaw('SUBSTRING(`description`, 1, 200) as `description`')
                                     ->where('user_id_fk',$user_id)
                                     ->where('status', '=', '1');




                                     $u_meetup = DB::table('mst_meetup as meetup')
                                     ->select(DB::raw('meetup as type'),'id','title', DB::raw('DATE_FORMAT(created_at, %d %b %Y) as created_at'), DB::raw('DATE_FORMAT(updated_at, %d %b %Y) as updated_at'), DB::raw('DATE_FORMAT(start_date, %d %b %Y) as start_date'), 'imported', 'import_url', 'cover_type', 'profile_image', 'location')
                                     ->selectRaw('SUBSTRING(`description`, 1, 200) as `description`')
                                     ->where('user_id_fk',$user_id)
                                     ->where('status', '=', '1');



                                     $u_question = array();
                                     $u_question = DB::table('mst_question as question')
                                     ->select(DB::raw('question as type'),'id','title', DB::raw('DATE_FORMAT(created_at, %d %b %Y) as created_at'), DB::raw('DATE_FORMAT(updated_at, %d %b %Y) as updated_at'), 'imported', 'import_url', 'cover_type', 'profile_image')
                                     ->selectRaw('SUBSTRING(`description`, 1, 200) as `description`')
                                     ->where('user_id_fk',$user_id)
                                     ->where('status', '=', '1');




                                     $u_job = array();
        $u_job = DB::table('mst_job as job')
                                     ->select(DB::raw('job as type'),'id','title', DB::raw('DATE_FORMAT(created_at, %d %b %Y) as created_at'), DB::raw('DATE_FORMAT(updated_at, %d %b %Y) as updated_at'), 'imported', 'import_url', 'cover_type', 'profile_image', 'job_location', 'cmp_name')
                                     ->selectRaw('SUBSTRING(`description`, 1, 200) as `description`')
                                     ->where('user_id_fk',$user_id)
                                     ->where('status', '=', '1');



                                     $u_education = array();
        $u_education = DB::table('mst_education as education')
                                     ->select(DB::raw('education as type'),'id','title', DB::raw('DATE_FORMAT(created_at, %d %b %Y) as created_at'), DB::raw('DATE_FORMAT(updated_at, %d %b %Y) as updated_at'), 'imported', 'import_url', 'cover_type', 'profile_image')
                                     ->selectRaw('SUBSTRING(`description`, 1, 200) as `description`')
                                     ->where('user_id_fk',$user_id)
                                     ->where('status', '=', '1');


                                     $u_activity= DB::table('mst_event as event')
                                     ->select(DB::raw('event as type'),'id','title', DB::raw('DATE_FORMAT(created_at, %d %b %Y) as created_at'), DB::raw('DATE_FORMAT(updated_at, %d %b %Y) as updated_at'), DB::raw('DATE_FORMAT(start_date, %d %b %Y) as start_date'), 'imported', 'import_url', 'cover_type', 'profile_image', 'location')
                                     ->selectRaw('SUBSTRING(`description`, 1, 200) as `description`')
                                     ->where('user_id_fk',$user_id)
                                     ->where('status', '=', '1')
        ->union($u_article)->union($u_question)->union($u_meetup)->union($u_job)->union($u_education)
                                     ->skip($skp)
                                     ->take($nos)
                                     ->get();

                                     if (count($u_activity)>0){
                                                   foreach ($u_activity as $key => $value){
                                                                if (!empty($value->profile_image)){
                                                                $u_activity[$key]->profile_image_url = config(feature_pic_url).'type_image/thumb/'.$value->profile_image;
                                                                }
                                                                $u_activity[$key]->post_url = url('/') . '/view-type' .  '/' . $value->id;
                                                  }
                                     }



                                     $array_json_return['u_activity'] = $u_activity;


                       } catch (\Exception $e) {
                                     $array_json_return = $this->api_default_fail_response(__function__, $e);
                       }

                       echo json_encode($array_json_return);
}

Estoy utilizando la función de unión () pero no funciona como para unirse instrucción de selección de tabla utilizando diferentes unión deberíamos tener el mismo número de columnas.

Publicado el 09/10/2019 a las 18:54
fuente por usuario
En otros idiomas...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more