dongnvwang8591 2017-10-27 11:54
浏览 42

扩展laravel的SeedCommand

Trying to make an extension to the core db:seed command to add a couple of necessary options. Extending the Illuminate\Database\Console\Seeds\SeedCommand and registering my command in Kernel.php give me following output when running php artisan :

[Illuminate\Contracts\Container\BindingResolutionException]
Target [Illuminate\Database\ConnectionResolverInterface] is not instantiable while building [App\Console\Commands\TenantSeeder].

Any hints what I am missing ? the class itself below :

<?php

namespace App\Console\Commands;

use Illuminate\Database\Console\Seeds\SeedCommand;
use Illuminate\Console\ConfirmableTrait;
use Symfony\Component\Console\Input\InputOption;
use Illuminate\Database\ConnectionResolverInterface as Resolver;

class TenantSeeder extends SeedCommand
{
    use ConfirmableTrait;
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'tenant:seed';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * The connection resolver instance.
     *
     * @var \Illuminate\Database\ConnectionResolverInterface
     */
    protected $resolver;

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

        $this->resolver = $resolver;
    }

    public function getOptions()
    {
        $opts = parent::getOptions();
        return array_merge($opts, [
            ['tenant', null, InputOption::VALUE_REQUIRED, 'Tenant is required to generate tenant-specific data'],
        ]);
    }
}
  • 写回答

1条回答 默认 最新

  • dongshenling6585 2018-06-04 12:20
    关注

    You can do it like this if you are using a regular database like MySQL:

    <?php
    
    namespace App\Console\Commands;
    
    use Illuminate\Database\Console\Seeds\SeedCommand;
    use Illuminate\Database\DatabaseManager;
    
    class CustomSeedCommand extends SeedCommand
    {
    
        public function __construct(DatabaseManager $databaseManager)
        {
    
            parent::__construct($databaseManager);
        }
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于Lammps建模的描述
  • ¥15 #lingo#请问一下为什么会出现以下情况,是因为l第一个值是0的缘故吗?
  • ¥15 设计格雷码同步八进制计数器
  • ¥100 改写matlab程序(关键词-系统对)
  • ¥15 函数信号发生器仿真电路
  • ¥15 Qt的pixmap和image图片加载都导致程序崩溃怎么办
  • ¥15 Kali木马生成问题求解
  • ¥30 求一下解题思路,完全不懂
  • ¥15 C51单片机串口控制JQ6500语音模块
  • ¥30 想给yolo5模型加一个图片识别界面,但是图片还没有检测出来就闪退了