public function toggle_love() { $tour_slug = Input::get('tour_slug'); // get user $user = Auth::user(); if (!$user) { $jsend = new \ThunderID\jsend\jsend('fail', ['error' => 'Login Required']); return Response::json($jsend->toArray(), 400); } // get tour $tour = Tour::SlugIs($tour_slug)->first(); if (!$tour) { $jsend = new \ThunderID\jsend\jsend('fail', ['error' => 'Tour not found']); return Response::json($jsend->toArray(), 400); } // add love $already_love = false; foreach ($user->love as $x) { if ($x->id == $tour->id) { $already_love = true; } } if ($already_love) { $user->love()->detach($tour->id); } else { $user->love()->attach($tour->id); } // return message $jsend = new \ThunderID\jsend\jsend('success', ['love' => $already_love ? 0 : 1]); return Response::json($jsend->toArray(), 200); }
/** * Execute the job. * * @return void */ public function handle() { // check if data exists in subscription $subscriber = \App\Subscriber::findEmail($this->email)->first(); // check if data exists in user if (!$subscriber) { $user = \App\User::FindEmail($this->email)->first(); $subscriber = new \App\Subscriber(); if ($user->email) { $subscriber->email = $user->email; $subscriber->user_id = $user->id; } else { $subscriber->email = $this->email; } $subscriber->is_subscribe = true; // add to subscription if (!$subscriber->save()) { $jsend = new \ThunderID\jsend\jsend('fail', ['data' => $subscriber->getErrors()->toArray()]); } else { $jsend = new \ThunderID\jsend\jsend('success', ['data' => $subscriber]); } } else { $jsend = new \ThunderID\jsend\jsend('success', ['data' => $subscriber]); } return $jsend->toArray(); }
/** * Execute the job. * * @return void */ public function handle() { // check if data exists in subscription $subscriber = \App\Subscriber::find($this->id); // check if data exists in user if (!$subscriber) { $jsend = new \ThunderID\jsend\jsend('fail', ['data' => 'Email belum terdaftar sebagai pelanggan newsletter capcus']); } else { if (Hash::check($subscriber->email, $this->token)) { $subscriber->is_subscribe = 0; $subscriber->save(); $jsend = new \ThunderID\jsend\jsend('success', ['data' => $subscriber]); } else { $jsend = new \ThunderID\jsend\jsend('fail', ['data' => 'Token salah']); } } return $jsend->toArray(); }
/** * Execute the job. * * @return void */ public function handle() { //------------------------------------------ // Check if user from facebook already exists //------------------------------------------ $user = User::FacebookId($this->sso_data->id)->first(); //------------------------------------------ // Check if user with same email already exists //------------------------------------------ if (!$user) { $user = User::FindEmail($this->sso_data->email)->first(); } //------------------------------------------ // Create/Update user //------------------------------------------ if (!$user) { $user = new User(); $user->name = $this->sso_data->name; $user->email = $this->sso_data->email; $user->avatar = $this->sso_data->avatar; $user->password = str_random(100); $user->is_admin = 0; $user->sso_twitter_id = ''; $user->sso_twitter_data = ''; $user->sso_twitter_updated_at = null; } else { $user->email = $this->sso_data->email; $user->avatar = $this->sso_data->avatar; } $user->sso_facebook_id = $this->sso_data->id; $user->sso_facebook_data = json_encode((array) $this->sso_data); $user->sso_facebook_updated_at = \Carbon\Carbon::now(); //------------------------------------------ // Return data //------------------------------------------ if ($user->save()) { $jsend = new \ThunderID\jsend\jsend('success', ['data' => $user]); } else { $jsend = new \ThunderID\jsend\jsend('fail', ['message' => $user->getErrors()]); } return $jsend->toArray(); }