本文整理汇总了PHP中Illuminate\Support\Facades\Schema::hasTable方法的典型用法代码示例。如果您正苦于以下问题:PHP Schema::hasTable方法的具体用法?PHP Schema::hasTable怎么用?PHP Schema::hasTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Schema
的用法示例。
在下文中一共展示了Schema::hasTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
if (Schema::hasTable('categories')) {
$categories = Category::getAllFromCache();
view()->share('categories', $categories);
}
}
示例2: schedule
/**
* 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('* * * * *');
}
}
示例3: up
/**
* 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');
});
}
}
示例4: setSource
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));
}
示例5: getPermissions
private function getPermissions()
{
if (!Schema::hasTable('permissions')) {
return [];
}
return Permission::with('roles')->get();
}
示例6: test_tables_exist
/**
* 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));
}
}
示例7: test_tables_exist
/**
* 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));
}
}
示例8: handle
/**
* 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);
}
示例9: show
public function show()
{
if (Schema::hasTable('migrations')) {
return redirect(route('home.show'));
}
return view('core.installer.index');
}
示例10: schedule
/**
* 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']);
}
}
}
示例11:
function __construct($table, $primaryKey, $meta_key = 'iid', $fields = [])
{
parent::__construct($table, $primaryKey, $meta_key, $fields);
if (!Schema::hasTable($this->table())) {
$this->build();
}
}
示例12: createSchema
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);
}
}
}
示例13: getDatabaseConfig
/**
* @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'));
}
}
示例14: setUpBeforeClass
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');
});
}
}
示例15: getPermissions
/**
* 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();
}