Пример #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function postServicios(Request $request)
 {
     // var_dump($request->input('key'));
     switch ($request->input('get')) {
         case 'findByKey':
             $input = e($request->input('key'));
             if (!empty($input)) {
                 echo Servicio::where('name', 'like', '%' . $input . '%')->get()->toJson();
             }
             break;
         case 'byUser':
             $user = $request->input('id');
             echo UserMeta::where('id', '=', $user)->where('name', '=', 'servicios')->get()->toJson();
             // print_r(UserMeta::all());
             // echo UserMeta::where('id','=',$user)->where('name','=','servicios')->get()->toJson();
             break;
         case 'saveChanges':
             $collection = json_encode($request->input('collection'));
             $id = $request->input('id');
             $meta = UserMeta::where('id', '=', $id)->where('name', '=', 'servicios')->get();
             $array = $meta->toArray();
             if (empty($array)) {
                 $newMeta = new UserMeta();
                 $newMeta->id = $id;
                 $newMeta->data = $collection;
                 $newMeta->name = 'servicios';
                 echo $newMeta->save();
             } else {
                 $result = DB::table('user_metas')->where('id', $id)->where('name', 'servicios')->update(['data' => $collection]);
                 echo $result;
             }
             break;
         case 'all':
             $services = Servicio::where('state', '=', 'active')->get()->toArray();
             foreach ($services as $k => $v) {
                 // $date = new DateTime($services[$k]['created_at']);
                 $date = date_create($v['created_at']);
                 $categorias = json_decode($v['categorias']);
                 $services[$k]['categorias'] = array();
                 $services[$k]['usuario'] = User::find($v['user_id']);
                 $services[$k]['created_at'] = date_format($date, 'd/m/Y');
                 foreach ($categorias as $kc => $vc) {
                     if (!is_null($vc) && !empty($vc) && is_numeric($vc)) {
                         $array = array();
                         $array['id'] = $vc;
                         $array['name'] = Categoria::find($vc)->name;
                         array_push($services[$k]['categorias'], $array);
                     }
                 }
             }
             echo json_encode(array_reverse($services));
             break;
         default:
             # code...
             break;
     }
 }
Пример #2
0
 public function profileDataSave(Request $request)
 {
     $userId = Auth::User()->id;
     $returnValue = false;
     $userData = $request->all();
     $userDetail = UserDetail::where('userId', $userId)->first();
     $phone = $userData['phone'];
     $phone1 = json_decode($phone);
     $userMetaId = UserMeta::all()->where('userId', $userId);
     $business = Business::find($userDetail->businessId);
     if (empty($business)) {
         DB::table('userDetails')->where('userId', $userId)->update(['name' => $userData['name'], 'location' => $userData['location'], 'about' => $userData['about'], 'updated_at' => time()]);
     } else {
         $business->name = $userData['name'];
         $business->about = $userData['about'];
         $business->website = $userData['website'];
         $business->serviceCoverage = $userData['serviceCoverage'];
         $business->updated_at = time();
         $business->save();
         DB::table('usersMeta')->where('userId', $userId)->delete();
         // Array to insert values in database
         $arrayInsert = array();
         foreach ($phone1 as $key => $value) {
             if (!empty($value)) {
                 $new = array('userId' => $userId, 'metaKey' => 'phone', 'metaValue' => $value);
                 array_push($arrayInsert, $new);
             }
         }
         if (!empty($userData['urlFacebook'])) {
             $new = array('userId' => $userId, 'metaKey' => 'urlFacebook', 'metaValue' => $userData['urlFacebook']);
             array_push($arrayInsert, $new);
         }
         if (!empty($userData['urlGoogle'])) {
             $new = array('userId' => $userId, 'metaKey' => 'urlGoogle', 'metaValue' => $userData['urlGoogle']);
             array_push($arrayInsert, $new);
         }
         if (!empty($userData['urlTwitter'])) {
             $new = array('userId' => $userId, 'metaKey' => 'urlTwitter', 'metaValue' => $userData['urlTwitter']);
             array_push($arrayInsert, $new);
         }
         DB::table('usersMeta')->insert($arrayInsert);
         DB::table('userDetails')->where('userId', $userId)->update(['location' => $userData['location'], 'updated_at' => time()]);
     }
     $userDetail = UserDetail::where('userId', $userId)->first();
     $business = Business::find($userDetail->businessId);
     $userMetaId = UserMeta::all()->where('userId', $userId);
     $arr = array();
     $arr = array();
     $phone = array();
     $phoneBlank = array();
     foreach ($userMetaId as $key => $value) {
         if ($value['metaKey'] == 'phone') {
             $phone[$value['metaKey']][] = $value['metaValue'];
         }
         if ($value['metaKey'] == 'urlFacebook' || $value['metaKey'] == 'urlGoogle' || $value['metaKey'] == 'urlTwitter') {
             $arr[$value['metaKey']] = $value['metaValue'];
         }
         if (is_array($phone)) {
             $arr = array_merge($arr, $phone);
         } else {
             $arr = array_merge($arr, $phoneBlank);
         }
     }
     // return $arr;
     if (empty($business)) {
         $business = array_merge($userDetail->toArray());
     } else {
         $business = array_merge($userDetail->toArray(), $business->toArray(), $arr);
     }
     return $business;
 }