/** * 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(); }
public function created($model) { // ADD TO SUBSCRIBER if ($model->email) { $subscriber = \App\Subscriber::where('user_id', '=', $model->id)->first(); if (!$subscriber) { $subscriber = new \App\Subscriber(); $subscriber->email = $model->email; $subscriber->is_subscribe = 1; $subscriber->user_id = $model->id; $subscriber->save(); } } // SEND WELCOME EMAIL event(new \App\Events\NewMemberRegistered($model)); }
/** * Execute the console command. * * @return mixed */ public function handle() { // if (Storage::exists($this->argument('file'))) { $contents = Storage::get($this->argument('file')); $users = json_decode($contents); foreach ($users as $x) { $subscriber = new \App\Subscriber(); $subscriber->user_id = $x->user_id; $subscriber->email = $x->email; $subscriber->is_subscribe = $x->is_subscribe; $subscriber->save(); } } else { $this->error('file not exists'); } }