예제 #1
0
 public function addFriend()
 {
     if (Auth::check() && Input::get('id')) {
         $friend = Friend::whereRaw('user_id = ? AND related_user_id = ?', [Auth::user()->id, Input::get('id')])->update(["status" => "friend", "category_id" => Input::get('categoryId')]);
         if (!$friend) {
             $friend = new Friend();
             $friend->user_id = Auth::user()->id;
             $friend->related_user_id = Input::get('id');
             $friend->category_id = Input::get('categoryId');
             $friend->status = "friend";
             $friend->save();
             $friend = null;
         }
         $friend = Friend::whereRaw('user_id = ? AND related_user_id = ?', [Input::get('id'), Auth::user()->id])->first();
         if (!$friend) {
             $friend = new Friend();
             $friend->user_id = Input::get('id');
             $friend->related_user_id = Auth::user()->id;
             $friend->category_id = Input::get('categoryId');
             $friend->save();
         }
         return response()->json(["result" => "success"], 200);
     }
     return response()->json(["result" => "error"], 200);
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $rules = ['category' => 'required', 'name' => 'required', 'latitude' => 'required', 'longitude' => 'required', 'address' => 'required'];
     $this->validate($request, $rules);
     $friend = new Friend();
     $friend->category = $request->input('category');
     $friend->name = $request->input('name');
     $friend->latitude = $request->input('latitude');
     $friend->longitude = $request->input('longitude');
     $friend->address = $request->input('address');
     $friend->tel = $request->input('tel');
     $friend->homepage = $request->input('homepage');
     $friend->description = $request->input('description');
     $friend->save();
     return redirect('/admin/friend');
 }
 public function approve($id)
 {
     $Request = FriendRequest::find($id);
     if (!$Request) {
         echo json_encode(['success' => false]);
         return;
     }
     $Friend = new Friend();
     $Friend->friend_id = $Request->sender_id;
     $Friend->user_id = $Request->recipient_id;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = $Request->sender_id;
     $Friend->friend_id = $Request->recipient_id;
     $Friend->save();
     $result = $Request->delete();
     echo json_encode(['success' => (bool) $result]);
 }
예제 #4
0
 function run()
 {
     Friend::truncate();
     $Friend = new Friend();
     $Friend->user_id = 1;
     $Friend->friend_id = 2;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 2;
     $Friend->friend_id = 1;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 1;
     $Friend->friend_id = 3;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 3;
     $Friend->friend_id = 1;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 1;
     $Friend->friend_id = 4;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 4;
     $Friend->friend_id = 1;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 2;
     $Friend->friend_id = 3;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 3;
     $Friend->friend_id = 2;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 3;
     $Friend->friend_id = 4;
     $Friend->save();
     $Friend = new Friend();
     $Friend->user_id = 4;
     $Friend->friend_id = 3;
     $Friend->save();
 }
예제 #5
0
 public function deploy(Request $request)
 {
     $ids = $request->input('ids');
     if (empty($ids)) {
         $gathers = Gather::select('id', 'title', 'category', 'description', 'telephone', 'address', 'road_address', 'latitude', 'longitude', 'deploy')->where([['deploy', '<>', true], ['delete', '<>', true]])->orderby('created_at', 'desc')->get();
     } else {
         $where = explode(',', $ids);
         $gathers = Gather::select('id', 'title', 'category', 'description', 'telephone', 'address', 'road_address', 'latitude', 'longitude', 'deploy')->where([['deploy', '<>', true], ['delete', '<>', true]])->whereIn('id', $where)->orderby('created_at', 'desc')->get();
     }
     $success = 0;
     foreach ($gathers as $item) {
         $friend = Friend::where('gather_id', $item->id)->first();
         if (empty($friend)) {
             $friend = new Friend();
         }
         // 업장정보 저장
         $friend->type = $item->category;
         $friend->gather_id = $item->id;
         $friend->name = $item->title;
         $friend->latitude = $item->latitude;
         $friend->longitude = $item->longitude;
         $friend->address = $item->address;
         $friend->road_address = $item->road_address;
         $friend->tel = $item->telephone;
         $friend->description = $item->description;
         $friend->save();
         // 수집자료 배포 상태 업데이트
         $item->deploy = true;
         $item->save();
         $success++;
     }
     // 배포 히스토리 저장
     $deployHistory = new GatherDeployHistory();
     $deployHistory->deploy_count = $success;
     $deployHistory->save();
     return response()->json(['result' => 'success', 'count' => $gathers->count(), 'success' => $success]);
 }
예제 #6
0
 /**
  * validate friend request and connect user to logged in account
  *
  * @return json array
  */
 public function connect()
 {
     $data = [];
     $email = Input::get('email');
     //get auth user
     $my_id = Auth::id();
     //get user by email
     $friend = User::where('email', '=', $email)->first();
     if (count($friend)) {
         $current_friends = User::find($my_id)->friends;
         if (!$current_friends->contains($friend->id)) {
             //save friendship
             $new_friend = new Friend();
             $new_friend->user_id = $my_id;
             $new_friend->my_friend = $friend->id;
             $new_friend->save();
         }
         $data['status'] = 1;
         $data['friends'] = User::find($my_id)->friends;
         $data['most_recent'] = $friend->id;
     } else {
         $data['status'] = 0;
         $data['message'] = "Error: Email not found";
     }
     return $data;
 }