/** * 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 index() { $this->auth(); $user = User::find(Session::get('uid')); foreach ($user->notices as $vv) { $vv->wish = Wish::find($vv->wishId); unset($vv->wishId); if (!$vv->wish) { continue; } $v = $vv->wish; $creator = User::find($v->creatorId); $creator->school; unset($creator->schoolId); $v->creatorUser = $creator; $picker = User::find($v->pickerId); if ($picker) { $picker->school; unset($picker->schoolId); $v->pickerUser = $picker; } } return $this->output(array('total' => Notice::where('userId', '=', $user->id)->count(), 'notices' => $user->notices)); }
public function index($creator_id) { return array('code' => 0, 'data' => Wish::orderBy('creatorId', '=', $creator_id)->orderBy('createdTime', 'desc')->get()); }
public function index($creator_id) { return array('code' => 0, 'data' => Wish::orderBy('picker_id', '=', $creator_id)->get()); }
public function delete() { $wish = Wish::find(Input::get("_id")); if (!$wish) { return $this->outputError('no wish'); } $wish->delete(); return $this->output(new \stdClass()); }