/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $user = DB::table('user')->where('user.id', $id)->where('user.is_deleted', '=', '0')->where('user.is_enable', '=', '1')->join('role', 'user.role_id', '=', 'role.id')->join('media', 'user.media_id', '=', 'media.id')->join('contact', 'user.contact_id', '=', 'contact.id')->select('user.id', 'first_name', 'last_name', 'role.name AS role', 'media.name AS photo', 'email', 'phone', 'address')->first(); if ($user) { $user->count_friends = Friend::where('user_id', $user->id)->where('status', "friend")->where('related_user_id', '!=', Auth::user()->id)->count(); $user->count_wishes = Wish::where('user_id', $user->id)->count(); return response()->json(["data" => $user, "result" => "success"], 200); } else { return response()->json(["result" => "error_user_not_found"], 200); } }
public function editWish($id) { // return response()->json(['result' => 'success', 'data' => $text], 200); $wish = Wish::where('id', $id)->first(); if ($wish) { $wish->name = Input::get('name'); $wish->description = Input::get('description'); $wish->category_id = Input::get('category')['id']; $wish->link = Input::get('link'); $text = Input::get("photo"); if (isset($text['$ngfDataUrl'])) { $destinationPath = 'images/wishes/'; $data = $text['$ngfDataUrl']; list($type, $data) = explode(';', $data); list(, $type) = explode('/', $type); list(, $data) = explode(',', $data); $fileName = md5(date("YmdHis") . rand(5, 50)) . '.' . $type; $data = base64_decode($data); $media = Media::where('id', $wish->media_id)->first(); if (file_put_contents($destinationPath . $fileName, $data)) { if ($media->id != 3) { $tmp = $media->name; $media->name = URL::to('/') . "/" . $destinationPath . $fileName; $media->save(); $arr = explode("/", $tmp); unlink($destinationPath . $arr[count($arr) - 1]); } else { $media = new Media(); $media->name = URL::to('/') . "/" . $destinationPath . $fileName; $media->save(); $wish->media_id = $media->id; } } } $wish->save(); return response()->json(['result' => 'success'], 200); } else { return response()->json(['result' => 'error'], 200); } }
public function mylist() { $this->auth(); $user = User::find(Session::get('uid')); if (Input::get('type') == 'picked') { $wishes = Wish::where('pickerId', '=', Session::get('uid'))->orderBy('isPicked', 'desc')->orderBy('pickedTime', 'desc')->get(); } else { $wishes = Wish::where('creatorId', '=', Session::get('uid'))->orderBy('isPicked', 'desc')->orderBy('pickedTime', 'desc')->orderBy('createdTime', 'desc')->get(); } foreach ($wishes as $v) { unset($v->updatedTime); $creator = User::find($v->creatorId); $v->creatorUser = $creator; if ($creator) { $creator->school; } $picker = User::find($v->pickerId); if ($picker) { $picker->school; $v->pickerUser = $picker; } } return $this->output(array('wishList' => $wishes)); }