/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciado' . PHP_EOL; $start = microtime(true); $totalUsers = User::count(); //cria o main loop $loop = \React\EventLoop\Factory::create(); //cria a conexão MySQL $connection = new \React\MySQL\Connection($loop, array('dbname' => $_ENV['DB_DATABASE'], 'user' => $_ENV['DB_USERNAME'], 'passwd' => $_ENV['DB_PASSWORD'])); $connection->connect(function () { }); $query1 = ' SELECT * FROM users LEFT JOIN companies ON users.company_id = companies.id LIMIT ' . $totalUsers / 2 . ' ;'; $query2 = ' SELECT * FROM users LEFT JOIN companies ON users.company_id = companies.id LIMIT ' . $totalUsers / 2 . ' OFFSET ' . $totalUsers / 2 . ' ;'; $this->getUsers($connection, $query1, $loop); $this->getUsers($connection, $query2, $loop); $loop->run(); echo 'Processados ' . count($this->users) . ' usuários' . PHP_EOL; echo 'Demorou ' . number_format((microtime(true) - $start) * 1000, 2, ',', '') . 'ms' . PHP_EOL; }
/** * Displays the admin welcome page. * * @return \Illuminate\View\View */ public function index() { $this->authorize('admin.welcome.index'); $users = $this->user->count(); $roles = $this->role->count(); $permissions = $this->permission->count(); return view('admin.welcome.index', compact('users', 'roles', 'permissions')); }
public function getLoginWrapper() { if (!Utils::isNinja() && !User::count()) { return redirect()->to('invoice_now'); } return self::getLogin(); }
/** * Handle an incoming request. * * @param Request $request * @param Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { // Retrieve the administrator role. $administrator = $this->role->whereName(Role::getAdministratorName())->first(); // Retrieve the count of users. $users = $this->user->count(); if ($administrator instanceof Role && !$request->user() && $users === 0) { // If the administrator role has been created, no user // is logged in, and no users exist, // we'll allow the setup request. return $next($request); } // If the administrator role hasn't already been created, // we'll throw an Unauthorized Exception. throw new HttpException(403, 'Unauthorized.'); }
public function callbackHasNoCode(FunctionalTester $I) { $count = User::count() + Profile::count(); $I->sendGET($this->endpoint . '/facebook/callback'); $I->seeResponseCodeIs(409); $I->seeResponseContainsJson(['status' => 'ERROR', 'message' => 'Ups, something went wrong during authorization']); $I->assertEquals($count, User::count() + Profile::count()); }
public function index() { $users = User::count(); $posts = Post::count(); $categories = Category::count(); $comments = Comment::count(); return $this->view('gag/admin/dashboard/index', ['users' => $users, 'posts' => $posts, 'categories' => $categories, 'comments' => $comments]); }
/** * Display a listing of the resource. * * @return Response */ public function index() { //获得数量 $g = Good::count(); $o = Order::count(); $u = User::count(); $c = Comment::count(); return view('admin.index.index', ['g' => $g, 'o' => $o, 'u' => $u, 'c' => $c]); }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciado' . PHP_EOL; $start = microtime(true); $totalUsers = User::count(); //Pega todos os usuários do banco, transforma a Collection em Array $users = $this->getUsers(); echo 'Processados ' . count($users) . ' usuários' . PHP_EOL; echo 'Demorou ' . number_format((microtime(true) - $start) * 1000, 2, ',', '') . 'ms' . PHP_EOL; }
/** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { $routeName = 'dashboard'; $routeMethod = 'index'; $users = \App\Models\User::count(); $sources = \App\Models\Source::count(); $maps = \App\Models\Map::count(); $data = compact('routeName', 'routeMethod', 'users', 'sources', 'maps'); return view('admin.sections.dashboard.index', $data); }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->info('Synchronising user post counts...'); $this->progress = $this->output->createProgressBar(User::count()); User::chunk(1000, function ($users) { foreach ($users as $u) { $u->refreshForumCache(); $this->progress->advance(); } }); $this->progress->finish(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data['mem_limit'] = ini_get('memory_limit'); $data['english_words'] = Word::where('language_id', '1')->count(); $data['danish_words'] = Word::where('language_id', '2')->count(); $data['pashto_words'] = Word::where('language_id', '3')->count(); $data['unique_users'] = User::count(); $data['users'] = User::limit(4)->get(); $data['words'] = Word::with(['language', 'user'])->limit(8)->orderBy('created_at', 'desc')->get(); $used_mem = memory_get_peak_usage(false); $data['mem_using'] = round($used_mem / 1024 / 1024, 1) . 'M'; return view('admin.dashboard', $data); }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciado' . PHP_EOL; $start = microtime(true); $totalUsers = User::count(); $loop = \React\EventLoop\Factory::create(); $this->getUsers($loop, $totalUsers / 4, 0); $this->getUsers($loop, $totalUsers / 4, $totalUsers / 4 * 1); $this->getUsers($loop, $totalUsers / 4, $totalUsers / 4 * 2); $this->getUsers($loop, $totalUsers / 4, $totalUsers / 4 * 3); $loop->run(); echo 'Processados ' . count($this->users) . ' usuários' . PHP_EOL; echo 'Demorou ' . number_format((microtime(true) - $start) * 1000, 2, ',', '') . 'ms' . PHP_EOL; }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciando servidor...' . PHP_EOL; $totalUsers = User::count(); $loop = \React\EventLoop\Factory::create(); $socket = new \React\Socket\Server($loop); $socket->on('connection', function ($conn) use($totalUsers) { echo 'Enviando mensagem...' . PHP_EOL; $users = $this->getUsers($totalUsers / 2, $totalUsers / 2); $conn->end(serialize($users)); echo 'Enviada' . PHP_EOL; }); $socket->listen(1337); $loop->run(); }
/** * Execute the console command. * * @return mixed */ public function handle() { try { DB::connection(); } catch (Exception $e) { $this->error('Unable to connect to database.'); $this->error('Please fill valid database credentials into .env and rerun this command.'); return; } $this->comment('Attempting to install or upgrade Koel.'); $this->comment('Remember, you can always install/upgrade manually following the guide here:'); $this->info('📙 https://github.com/phanan/koel/wiki' . PHP_EOL); if (!config('app.key')) { $this->info('Generating app key'); Artisan::call('key:generate'); } else { $this->comment('App key exists -- skipping'); } if (!config('jwt.secret')) { $this->info('Generating JWT secret'); Artisan::call('koel:generate-jwt-secret'); } else { $this->comment('JWT secret exists -- skipping'); } $this->info('Migrating database'); Artisan::call('migrate', ['--force' => true]); if (!User::count()) { $this->info('Seeding initial data'); Artisan::call('db:seed', ['--force' => true]); } else { $this->comment('Data seeded -- skipping'); } $this->info('Executing npm install, gulp and whatnot'); system('npm install'); $this->comment(PHP_EOL . '🎆 Success! You can now run Koel from localhost with `php artisan serve`.'); $this->comment('Again, for more configuration guidance, refer to'); $this->info('📙 https://github.com/phanan/koel/wiki.'); $this->comment('WIKI ROCKS WIKI RULES.'); $this->comment('KTHXBYE.'); }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciado' . PHP_EOL; $start = microtime(true); $cacheKey = md5(uniqid('')); $totalUsers = User::count(); $pid = pcntl_fork(); if ($pid == -1) { die('could not fork =('); } else { if ($pid) { // we are the parent //É necessário reconectar no banco, os processos vão compartilhar //a conexão, o que irá gerar erro \DB::reconnect('mysql'); //Pega os usuários da primeira metade do total $users = $this->getUsers($totalUsers / 2, 0); //Aguarda o processo filho terminar pcntl_wait($status); //Faz um merge do que o processo pai e filho processaram //Os dados do processo filho estão no cache $users = array_merge($users, \Cache::pull($cacheKey)); } else { // we are the child //É necessário reconectar no banco, os processos vão compartilhar //a conexão, o que irá gerar erro \DB::reconnect('mysql'); //Pega os usuários da segunda metade do total $users = $this->getUsers($totalUsers / 2, $totalUsers / 2); //Armazena os usuários processados no cache \Cache::forever($cacheKey, $users); die; } } echo 'Processados ' . count($users) . ' usuários' . PHP_EOL; echo 'Demorou ' . number_format((microtime(true) - $start) * 1000, 2, ',', '') . 'ms' . PHP_EOL; }
protected function elements($defaults) { $this->options->oninput = 'this.op.value=this.username.value;'; return array(array('type' => 'markup', 'inside' => function ($form) { return 'Username: <output name="op" xoninput="alert(this);this.value=this.form.username.value;">...</output>'; }), 'username' => array('type' => 'text', 'required' => true, 'minlength' => 2, 'validation' => function ($form) { $db = $form->application->db; $usernameExists = models\User::count(array('username' => $form->input('username'))); return $usernameExists ? 'This username is taken' : true; }, 'description' => Output::translate('Have you read our %1?', array(Output::ajaxLink(Output::translate('username guidelines', null, array('ucfirst' => false)), 'blog/page/username')))), 'password' => array('type' => 'password', 'required' => true, 'minlength' => 0), 'color' => array('title' => 'Favourite colour', 'type' => 'colour', 'required' => true, 'minlength' => 2, 'default' => 'white'), 'category' => array('title' => 'Favourite blog category', 'type' => 'options', 'options' => \app\models\Category::all('category_name <> ?', ''), 'dummy' => '-- I have not the favourite', 'validation' => function ($form, $name) { if ('' == $form->input($name, '')) { // Can be empty $form->output($name, null); return true; } return $form->validateOptions($form, $name); }), 'birthdate' => array('title' => 'When\'s your dob?', 'type' => 'date', 'required' => true, 'validation' => 'date', 'default' => 'YYYY-MM-DD'), 'bio' => array('type' => 'textarea', 'required' => true, 'minlength' => 0, 'rows' => 5, 'regex' => '.*\\w\\s\\w.*'), array('type' => 'markup', 'outside' => '<fieldset><legend>' . Output::translate('Options') . '</legend>'), 'stupid' => array('type' => 'checkbox', 'required' => true, 'name' => 'options[stupid]'), 'this' => array('type' => 'checkbox', 'name' => 'options[this]'), 'that' => array('type' => 'checkbox', 'name' => 'options[that]'), array('type' => 'markup', 'outside' => '</fieldset>'), 'email' => array('type' => 'email', 'required' => true, 'validation' => 'email', 'description' => Output::translate('Only used for account activation. <strong>We won\'t store this.</strong>')), 'gender' => array('type' => 'radio', 'required' => true, 'options' => array('m' => Output::translate('Male'), 'f' => Output::translate('Female'))), 'hobbies' => array('type' => 'checkboxes', 'options' => models\Category::all(), 'required' => true, 'minlength' => 2, 'name' => 'misc[hobbies][]'), array('type' => 'markup', 'outside' => '<fieldset><legend>Terms</legend>'), 'terms' => array('type' => 'checkbox', 'title' => Output::translate('I very much do agree on the terms yes yes'), 'description' => 'Do you really? Huh? <b>Well?? Do ya??</b>', 'required' => true), array('type' => 'markup', 'outside' => '</fieldset>'), array('validation' => function ($form) { return strlen($form->input('username')) <= strlen($form->input('password')); }, 'fields' => 'password', 'message' => 'Your password must be at least as long as your username'), array('require' => 'username', 'validation' => function ($form) { $usr = strtolower($form->input('username')); $clr = strtolower($form->input('color')); return !is_int(strpos($usr, $clr)) && !is_int(strpos($clr, $usr)); }, 'fields' => array('username', 'color'), 'message' => 'Username cannot contain Colour and vice versa')); }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciado' . PHP_EOL; $start = microtime(true); $totalUsers = User::count(); $buffer = ''; $loop = \React\EventLoop\Factory::create(); $dnsResolverFactory = new \React\Dns\Resolver\Factory(); $dns = $dnsResolverFactory->createCached('8.8.8.8', $loop); $connector = new \React\SocketClient\Connector($loop, $dns); $connector->create('127.0.0.1', 1337)->then(function (\React\Stream\Stream $stream) use(&$buffer) { $stream->on('data', function ($data, $stream) use(&$buffer) { $buffer .= $data; }); }); $loop->nextTick(function () use($totalUsers) { $this->users = $this->getUsers($totalUsers / 2, 0); }); $loop->run(); $buffer = unserialize($buffer); $this->users = array_merge($this->users, $buffer); echo 'Processados ' . count($this->users) . ' usuários' . PHP_EOL; echo 'Demorou ' . number_format((microtime(true) - $start) * 1000, 2, ',', '') . 'ms' . PHP_EOL; }
public static function GenerateFake($faker) { return ['user_id' => $faker->numberBetween($min = 1, $max = User::count()), 'local_id' => $faker->numberBetween($min = 1, $max = Local::count())]; }
/** * Gets search page * * @param Request $request * @return \Illuminate\View\View */ public function getSearch(Request $request) { $order = $request->input('order'); $param = $request->input('param'); $search = $request->input('search'); try { $results = User::search($this->search($search, ['proximity' => false, 'fuzzy' => 0.1, 'phrase' => false])); $query = $results; $count = $query->count(); // Order if ($param && $order) { $results = $results->orderBy($param, $order); } else { $param = null; } $data = ['results' => $results->get(), 'param' => $param, 'order' => $order, 'search' => $search, 'uri' => 'admin/users', 'count' => $count, 'all' => User::count(), 'delete_message' => trans('users.delete_message')]; } catch (\Exception $e) { $data = ['results' => [], 'param' => null, 'order' => null, 'search' => $search, 'uri' => 'admin/users', 'count' => 0, 'all' => 0, 'delete_message' => trans('users.delete_message')]; } return view('admin.users.search', $data); }
public static function GenerateFake($faker) { return ['uid' => $faker->uuid, 'access_token' => $faker->swiftBicNumber, 'user_id' => $faker->numberBetween($min = 1, $max = User::count()), 'provider_id' => $faker->numberBetween($min = 1, $max = Provider::count())]; }
public static function GenerateFake($faker) { return ['user_id' => $faker->numberBetween($min = 1, $max = User::count()), 'guestList_id' => $faker->numberBetween($min = 1, $max = GuestList::count())]; }
} $articles = $articles->orderBy('articles.updated_at', 'desc')->select(DB::raw('articles.id, articles.text, articles.title, articles.slug, articles.user_id, articles.updated_at'))->paginate(5); $topUsers = Article::published()->limit(3)->groupBy('user_id')->orderByRaw('count(user_id) DESC')->get(); $bestUsers = User::all(); $bestUsers = collect($bestUsers->sortByDesc(function ($user) { return $user->average_rating; }))->reject(function ($user) { return $user->average_rating == 0; }); $bestUsers = $bestUsers->slice(0, 3); return view('index', ['articles' => $articles, 'topUsers' => $topUsers, 'bestUsers' => $bestUsers, 'search' => $search]); }); Route::get('/about-us', function () { $users = User::where('role', '=', User::TEACHER_ROLE)->get(); $articlesCount = Article::published()->count(); $usersCount = User::count(); $commentsCount = \App\Models\Discussion::count(); return view('aboutus', ['users' => $users, 'articlesCount' => $articlesCount, 'usersCount' => $usersCount, 'commentsCount' => $commentsCount]); }); Route::get('/faq', function () { return view('faq'); }); Route::get('/rules', function () { return view('rules'); }); Route::get('/migrate/{id}', function () { Artisan::call('migrate', ['--force' => true]); })->where('id', 'lesna_jahoda'); Route::get('/seed/{id}', function () { Artisan::call('db:seed', ['--force' => true]); })->where('id', 'lesna_jahoda');
/* |-------------------------------------------------------------------------- | Model Factories |-------------------------------------------------------------------------- | | Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ use App\Models\Article; use App\Models\Category; use App\Models\Comment; use App\Models\Topic; use App\Models\User; $factory->define(User::class, function (Faker\Generator $faker) { return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)]; }); $factory->define(Category::class, function (Faker\Generator $faker) { return []; }); $factory->define(Article::class, function (Faker\Generator $faker) { return ['user_id' => rand(1, User::count()), 'category_id' => rand(1, Category::count()), 'title' => $faker->sentence(mt_rand(3, 10)), 'content' => join('<br>', $faker->paragraphs(mt_rand(3, 6))), 'published_at' => rand(0, 2) >= 1 ? Carbon\Carbon::now() : null]; }); $factory->define(Topic::class, function (Faker\Generator $faker) { return []; }); $factory->define(Comment::class, function (Faker\Generator $faker) { return ['user_id' => rand(1, User::count()), 'article_id' => rand(1, Article::count()), 'content' => join("\n", $faker->paragraphs(mt_rand(1, 2)))]; });
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $type = User::count() > 0 ? 0 : 1; return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'type' => $type]); }
public function getTotalUser() { return User::count(); }
/** * Gets search page * * @param Request $request * @return Response */ public function getSearch(Request $request) { $order = $request->input('order'); $param = $request->input('param'); $search = $request->input('search'); $results = User::search($this->search($search, 'users')); $query = $results; $count = $query->count(); // Order if ($param && $order) { $results = $results->orderBy($param, $order); } else { $param = null; } return view('admin.users.search', ['results' => $results->get(), 'param' => $param, 'order' => $order, 'search' => $search, 'uri' => 'admin/users', 'count' => $count, 'all' => User::count(), 'delete_message' => trans('users.delete_message')]); }
public function sortUser($slug) { $users = User::whereHas('role', function ($q) use($slug) { $q->where('slug', $slug); })->orderBy('seen', 'asc')->orderBy('created_at', 'desc')->paginate($this->itemPerPage); $roles = Role::all(); $counts['total'] = User::count(); foreach ($roles as $role) { $slug = $role->slug; $counts[$slug] = User::whereHas('role', function ($q) use($slug) { $q->whereSlug($slug); })->count(); } return view('admin.users.index', compact('users', 'roles', 'counts')); }
public function __construct() { if (User::count()) { return redirect()->action('DashboardController@index')->with('error', 'There is already an existing user. Can\'t reinitate install'); } }
public static function GenerateFake($faker) { return ['user_id' => $faker->numberBetween($min = 1, $max = User::count()), 'event_id' => $faker->numberBetween($min = 1, $max = Event::count()), 'geo_attended' => $faker->boolean($chanceOfGettingTrue = 50)]; }