/** * Bootstrap the application services. * * @return void */ public function boot() { if (Schema::hasTable('categories')) { $categories = Category::getAllFromCache(); view()->share('categories', $categories); } }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { if (Schema::hasTable('migrations') && Schema::hasTable('users')) { $banned = User::banned()->get(); $all = User::all(); $schedule->call(function () use($banned) { foreach ($banned as $u) { if ($u->banned_until != null) { if ($u->banned_until < Carbon::now()->toDateTimeString()) { $u->update(array('is_banned' => 0, 'banned_until' => null)); } } } })->when(function () use($banned) { return $banned->count() > 0; })->cron('* * * * *'); $schedule->call(function () use($all) { $now = Carbon::now(); $now->subMinutes(15); // A user is offline if they do nothing for 15 minutes foreach ($all as $u) { if ($u->last_active != null && $u->last_active < $now->toDateTimeString()) { $u->update(array('is_online' => 0)); } } })->when(function () use($all) { return $all->count() > 0; })->cron('* * * * *'); } }
/** * Run the migrations. * * @return void */ public function up() { if (!DbSchema::hasTable('jobs')) { DbSchema::create('jobs', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('queue'); $table->longText('payload'); $table->tinyInteger('attempts')->unsigned(); $table->tinyInteger('reserved')->unsigned(); $table->unsignedInteger('reserved_at')->nullable(); $table->unsignedInteger('available_at'); $table->unsignedInteger('created_at'); $table->index(['queue', 'reserved', 'reserved_at']); }); } if (!DbSchema::hasTable('failed_jobs')) { DbSchema::create('failed_jobs', function (Blueprint $table) { $table->increments('id'); $table->text('connection'); $table->text('queue'); $table->longText('payload'); $table->timestamp('failed_at'); }); } }
protected function setSource($source) { if ($source instanceof EloquentBuilder) { return $this->source = new Source\SEloquentBuilder($this, $source); } if ($source instanceof QueryBuilder) { return $this->source = new Source\SQueryBuilder($this, $source); } if ($source instanceof Model) { return $this->source = $source->exists ? new Source\SCollection($this, with(new Collection())->push($source)) : new Source\SModel($this, $source); } if ($source instanceof Collection) { return $this->source = new Source\SCollection($this, $source); } if ($source instanceof ArrayObject) { return $this->source = new Source\SArrayObject($this, $source); } if (is_array($source)) { return $this->source = new Source\SArray($this, $source); } if (is_string($source) && Schema::hasTable($source)) { return $this->source = new Source\SDb($this, $source); } throw new DataSetException(' "source" must be a table name, an eloquent model or an eloquent builder. you passed: ' . get_class($this->source)); }
private function getPermissions() { if (!Schema::hasTable('permissions')) { return []; } return Permission::with('roles')->get(); }
/** * Ensures the migrations ran and tables exist in the database. */ public function test_tables_exist() { $expectedTables = ['users', 'password_resets', 'email_addresses', 'phone_numbers', 'addresses']; foreach ($expectedTables as $table) { $this->assertTrue(Schema::hasTable($table)); } }
/** * Ensures the migrations ran and tables exist in the database. */ public function test_tables_exist() { $expectedTables = ['pages']; foreach ($expectedTables as $table) { $this->assertTrue(Schema::hasTable($table)); } }
/** * Handle an incoming request. * * @param Request $request * @param Closure $next * @return mixed * @throws \Exception */ public function handle($request, Closure $next) { if (!file_exists(base_path('.env')) || !Schema::hasTable('users')) { throw new \Exception('Asgard is not yet installed'); } return $next($request); }
public function show() { if (Schema::hasTable('migrations')) { return redirect(route('home.show')); } return view('core.installer.index'); }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * * @return void */ protected function schedule(Schedule $schedule) { // Check that the schedules table exists. This // could cause a fatal error if the app is // still being setup or the db has not yet // been configured. This is a relatively ugly // hack as this schedule() method is core to // the framework. try { DB::connection(); if (!Schema::hasTable('schedules')) { throw new Exception('Schema schedules does not exist'); } } catch (Exception $e) { return; } // Load the schedule from the database foreach (DbSchedule::all() as $job) { $command = $schedule->command($job['command'])->cron($job['expression']); // Check if overlapping is allowed if (!$job['allow_overlap']) { $command = $command->withoutOverlapping(); } // Check if maintenance mode is allowed if ($job['allow_maintenance']) { $command = $command->evenInMaintenanceMode(); } if ($job['ping_before']) { $command = $command->pingBefore($job['ping_before']); } if ($job['ping_after']) { $command->thenPing($job['ping_after']); } } }
function __construct($table, $primaryKey, $meta_key = 'iid', $fields = []) { parent::__construct($table, $primaryKey, $meta_key, $fields); if (!Schema::hasTable($this->table())) { $this->build(); } }
public function createSchema() { if (!DbSchema::hasTable('sessions')) { try { DbSchema::create('sessions', function ($table) { $table->string('id')->unique(); $table->longText('payload'); $table->integer('last_activity'); }); } catch (QueryException $e) { } } $exec = $this->getSystemSchemas(); $builder = new DbUtils(); foreach ($exec as $data) { // Creates the schema if (!method_exists($data, 'get')) { break; } $schemaArray = $data->get(); if (!is_array($schemaArray)) { break; } foreach ($schemaArray as $table => $columns) { $builder->build_table($table, $columns); } } }
/** * @return array */ public function getDatabaseConfig() { if (Schema::hasTable('options')) { $table = $this->app['db']->table('options'); return $this->changeConfigWithHelpers($table->where('type', 'config')->lists('value', 'key')); } }
public static function setUpBeforeClass() { if (!isset(self::$app)) { self::$app = AppFactory::create(); } if (!Schema::hasTable('users')) { Schema::create('users', function ($table) { $table->increments('id'); $table->string('name'); }); } DB::insert('insert into users (name) values (?)', array('Test User')); if (!Schema::hasTable('posts')) { Schema::create('posts', function ($table) { $table->increments('id'); $table->string('title'); $table->integer('created_by')->unsigned()->nullable(); $table->integer('updated_by')->unsigned()->nullable(); $table->integer('deleted_by')->unsigned()->nullable(); $table->timestamps(); $table->timestamp('deleted_at')->nullable(); $table->foreign('created_by')->references('id')->on('users'); $table->foreign('updated_by')->references('id')->on('users'); $table->foreign('deleted_by')->references('id')->on('users'); }); } }
/** * Fetch the collection of site permissions. * * @return \Illuminate\Database\Eloquent\Collection */ protected function getPermissions() { if (!Schema::hasTable('roles')) { return new Collection(); } return Permission::with('roles')->get(); }
/** * Bootstrap any application services. * * @return void */ public function boot() { $categories = []; if (Schema::hasTable('categories')) { $categories = App\Category::orderBy('name')->get(); } view()->share(compact('categories')); }
protected function init() { $firstUp = !Schema::hasTable('migrations'); if ($firstUp) { $this->_repository->createRepository(); $this->output('Migration table created successfully.'); } }
/** * Open Database Source * * @return bool */ public function openSource() { // If tables exists then data will be attempt to insert into current table and columns if (Schema::hasTable($this->table)) { $this->source = DB::table($this->table); } return true; }
public function createPartialTablesOnly($partials) { foreach ($partials as $partial) { $tableName = "partial_" . strtolower($partial->display); if (!Schema::hasTable($tableName)) { $this->createTable($tableName, "partial"); } } }
/** * Bootstrap any application services. * * @return void */ public function boot() { if (Schema::hasTable('categories')) { view()->share('nav_categories', Category::active()->get()); } if (Schema::hasTable('users')) { Stripe::setApiKey(config('services.stripe.secret')); } }
public function prepareDatabase() { if (!Schema::hasTable('planets')) { Schema::create('planets', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('order'); }); } }
/** * Run the migrations. * * @return void */ public function up() { if (!Schema::hasTable('acl_user_roles')) { Schema::create('acl_user_roles', function ($table) { $table->integer('user_id'); $table->integer('role_id'); $table->timestamps(); $table->primary(['user_id', 'role_id']); }); } }
/** * Register any application authentication / authorization services. * * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return void */ public function boot(GateContract $gate) { $this->registerPolicies($gate); if (Schema::hasTable('permissions')) { foreach ($this->getPermissions() as $permission) { $gate->define($permission->name, function ($user) use($permission) { return $user->hasRole($permission->roles); }); } } }
/** * Bootstrap any application services. * * @return void */ public function boot() { // if (Schema::hasTable('sections')) { $sections = Section::all(); $pages = Page::all(); $pagesNew = []; $sectionsNew = []; view()->share(['sections' => $sections, 'pages' => $pages, 'sectionsNew' => $sectionsNew, 'pagesNew' => $pagesNew]); } }
public function setUp() { parent::setUp(); putenv('DB_CONNECTION=sqlite_testing'); if (!Schema::hasTable('migrations')) { Artisan::call('mage2:migrate'); Artisan::call('db:seed'); $this->setupAdminUserAndWebsite(); } //Artisan::call('db:seed'); }
public function login(LoginUserRequest $request) { if (!Schema::hasTable('users')) { return "Não existe uma tabela de usuários."; } $credencials = $request->only(['email', 'password']); if (Auth::attempt($credencials, $request->has('remember'))) { return redirect()->intended($this->redirect_login); } return redirect()->back()->with(['login_error' => 'Email ou senha inválidos!']); }
/** * Create "publish_history" table if it does not exist. */ public function setPublishHistoryTable() { if (!Schema::hasTable('publish_history')) { Schema::create('publish_history', function (Blueprint $table) { $table->increments('id'); $table->string('path')->unique(); $table->string('hash')->nullable(); $table->timestamps(); }); } }
/** * Bootstrap any application services. * * @return void */ public function boot() { // Artisan uses routing, so it tries to retrieve all the categories when doing migrating // getting an error if (!Schema::hasTable('categories')) { return; } view()->share('categories', Category::all()->take(8)); //view()->share('cart_total', Cart::total()); //view()->share('cart_items', count(Cart::content())); }
public function create($table) { if (!Schema::hasTable($table)) { Schema::create($table, function (Blueprint $blueprint) { $blueprint->increments("id"); $blueprint->string("token"); $blueprint->longText("objects"); $blueprint->timestamp("created_at"); $blueprint->unique("token"); }); } }
/** * Execute the console command. * @return mixed */ public function handle() { // Delete media from the database and from the uploads directory. if (Schema::hasTable('media')) { $media = Media::all(); $media->each(function ($item) { $item->delete(); }); } $this->call('migrate:reset'); $this->call('birdmin:launch'); }