public function invitePost(Request $request) { /* @var $newUser /App/User */ $newUser = User::create(['name' => $request->input('name'), 'email' => $request->input('email'), 'password' => 'temporary', 'is_admin' => 0]); if ($newUser->isValid()) { $album_ids = $request->input('albums', []); foreach ($album_ids as $album_id) { $newUser->albums()->attach($album_id); } $albums = Album::whereIn('id', $album_ids)->get(); $token = base64_encode(sha1("{$newUser->id}_{$newUser->email}")); Mail::send('emails.invite', ['user' => $newUser, 'albums' => $albums, 'current' => $request->user(), 'token' => $token, 'domain' => $request->server('HTTP_HOST')], function ($m) use($newUser) { $m->to($newUser->email); $m->subject('Invitation'); }); return redirect('user/invite')->with('success', 'Invite sent.'); } else { return redirect()->back()->withErrors($newUser->getErrors())->withInput(); } }
/** * Return the favorites of a certain model or table, leave the data as is under $model->settings['favorites'] * * @param $model * @param $data * * @return object|false */ static function getFavoritesByModel($model, $data) { if (!isset($data[$model])) { return false; } $data = array_keys($data[$model]); switch ($model) { case 'articles': return Article::whereIn('id', $data)->get(); case 'sites': return Site::whereIn('id', $data)->get(); case 'professions': return Profession::whereIn('id', $data)->get(); case 'classifieds': return Classified::whereIn('id', $data)->get(); case 'albums': return Album::whereIn('id', $data)->get(); case 'agoda': return AgodaHotel::whereIn('hotel_id', $data)->get(); default: return false; } }