/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { $router->bind('username', function ($username) { return User::whereUsername($username)->first(); }); parent::boot($router); }
public function home() { $users = User::get(['username', 'latitude', 'longitude', 'email']); $users->map(function ($user) { $user->avatar = Gravatar::src($user->email); $user->profile_url = route('profile_path', $user->username); }); JavaScript::put(compact('users')); return view('pages.home'); }
/** * Bootstrap any application services. * * @return void */ public function boot() { //Set user's longitude and latitude on saving (update and create) User::saving(function ($user) { try { $response = GeoLocation::getGeocodeFromGoogle($user->address); $user->latitude = $response->results[0]->geometry->location->lat; $user->longitude = $response->results[0]->geometry->location->lng; } catch (\Exception $e) { throw new InvalidAddressException("It seems that your address is missing or invalid. Please don't forget to set it on your Github profile if you are using Github Authentication."); // return false; } }); }
/** * Return user if exists; create and return if doesn't * * @param $githubUser * @return User */ private function findOrCreateUser($githubUser) { if ($authUser = User::where('github_id', $githubUser->id)->first()) { return $authUser; } return User::create(['username' => $githubUser->nickname, 'github_id' => $githubUser->id, 'name' => $githubUser->name, 'email' => $githubUser->email, 'website' => $githubUser->user['blog'] ?: null, 'github' => 'https://github.com/' . $githubUser->nickname, 'address' => $githubUser->user['location'] ?: null, 'avatar' => $githubUser->avatar ?: null, 'bio' => $githubUser->user['bio'] ?: '']); }
/** * Display a list of all artisans. * * @return Response */ public function index() { $usersCount = User::count(); $users = User::latest()->simplePaginate(200); return view('users.index', compact('users', 'usersCount')); }