Вход Регистрация
Файл: system/vendor/illuminate/database/Console/Seeds/SeedCommand.php
Строк: 149
<?php

namespace IlluminateDatabaseConsoleSeeds;

use 
IlluminateConsoleCommand;
use 
IlluminateConsoleConfirmableTrait;
use 
IlluminateDatabaseConnectionResolverInterface as Resolver;
use 
IlluminateDatabaseEloquentModel;
use 
SymfonyComponentConsoleInputInputOption;

class 
SeedCommand extends Command
{
    use 
ConfirmableTrait;

    
/**
     * The console command name.
     *
     * @var string
     */
    
protected $name 'db:seed';

    
/**
     * The console command description.
     *
     * @var string
     */
    
protected $description 'Seed the database with records';

    
/**
     * The connection resolver instance.
     *
     * @var IlluminateDatabaseConnectionResolverInterface
     */
    
protected $resolver;

    
/**
     * Create a new database seed command instance.
     *
     * @param  IlluminateDatabaseConnectionResolverInterface  $resolver
     * @return void
     */
    
public function __construct(Resolver $resolver)
    {
        
parent::__construct();

        
$this->resolver $resolver;
    }

    
/**
     * Execute the console command.
     *
     * @return int
     */
    
public function handle()
    {
        if (! 
$this->confirmToProceed()) {
            return 
1;
        }

        
$previousConnection $this->resolver->getDefaultConnection();

        
$this->resolver->setDefaultConnection($this->getDatabase());

        
Model::unguarded(function () {
            
$this->getSeeder()->__invoke();
        });

        if (
$previousConnection) {
            
$this->resolver->setDefaultConnection($previousConnection);
        }

        
$this->info('Database seeding completed successfully.');

        return 
0;
    }

    
/**
     * Get a seeder instance from the container.
     *
     * @return IlluminateDatabaseSeeder
     */
    
protected function getSeeder()
    {
        
$class $this->laravel->make($this->input->getOption('class'));

        return 
$class->setContainer($this->laravel)->setCommand($this);
    }

    
/**
     * Get the name of the database connection to use.
     *
     * @return string
     */
    
protected function getDatabase()
    {
        
$database $this->input->getOption('database');

        return 
$database ?: $this->laravel['config']['database.default'];
    }

    
/**
     * Get the console command options.
     *
     * @return array
     */
    
protected function getOptions()
    {
        return [
            [
'class'nullInputOption::VALUE_OPTIONAL'The class name of the root seeder''DatabaseSeeder'],

            [
'database'nullInputOption::VALUE_OPTIONAL'The database connection to seed'],

            [
'force'nullInputOption::VALUE_NONE'Force the operation to run when in production'],
        ];
    }
}
Онлайн: 0
Реклама