2017-08-29 43 views
2

我試圖創建一個基本上與migrate:status基本相同的定製laravel(5.2)遷移命令,只是它僅列出了掛起的遷移所有遷移。定製laravel遷移命令「[Illuminate Database Migrations MigrationRepositoryInterface]不可實例化」

爲此,我已經非常簡單地將migrate:status複製到我的應用程序/控制檯目錄中的另一個類中,並調整了代碼以適應我的需要。然而,每當我嘗試運行它,我得到一個錯誤:

[Illuminate\Contracts\Container\BindingResolutionException] Target [Illuminate\Database\Migrations\MigrationRepositoryInterface] is not instantiable while building [App\Console\Commands\PendingMigrations, Illuminate\Database\Migrations\Migrator].

類本身和fire()方法的內容似乎並不重要,因爲它不會走到這一步,它__construct()方法中失敗。

<?php namespace App\Console\Commands; 

use Illuminate\Console\Command; 
use Illuminate\Database\Migrations\Migrator; 

class PendingMigrations extends Command 
{ 
    /** 
    * The console command name. 
    * 
    * @var string 
    */ 
    protected $name = 'migrate:pending'; 

    /** 
    * The console command description. 
    * 
    * @var string 
    */ 
    protected $description = 'Shows a list of pending migrations'; 

    /** 
    * The migrator instance. 
    * 
    * @var \Illuminate\Database\Migrations\Migrator 
    */ 
    protected $migrator; 

    /** 
    * Create a new migration rollback command instance. 
    * 
    * @param \Illuminate\Database\Migrations\Migrator $migrator 
    * @return \Illuminate\Database\Console\Migrations\StatusCommand 
    */ 
    public function __construct(Migrator $migrator) 
    { 
     parent::__construct(); 

     $this->migrator = $migrator; 
    } 

    /** 
    * Execute the console command. 
    * 
    * @return void 
    */ 
    public function fire() 
    { 
    } 
} 

其中的原因可能是什麼做的IoC容器,並與東西加載順序,但我不知道有足夠的瞭解Laravel的內部運作,以找出任何超過那。

它肯定有可能嗎?

我目前被困在5.2,所以我不知道這個問題是否存在於更新的版本。

我到目前爲止唯一嘗試過的方法是將遷移服務提供商添加到config/app.php列表頂部,但它似乎沒有影響,無論如何這只是一個隨機猜測。

providers' => [ 
    Illuminate\Database\MigrationServiceProvider::class,` 
] 

回答

4

我這周圍使用:

$this->migrator = app('migrator'); 

,但它不一定要做到這一點

+2

只是花了1小時的最佳方式。謝謝! – Julian

+1

不用擔心,如果你找到更好的方式請發表回答:) – robjbrain

相關問題