How to make Laravel migrator work with namespaced migrations?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 02:46:07

问题


I namespaced my whole package successfully but I can not get namespaced migrations to work. In the autoload_classmap.php the migration classes are nicely namespaced, but the Migrator is not looking for the migration classes within the namespace. How to get the migrator to search for the migrations within the namespace?

The migration file

<?php namespace Atomend\Aeuser;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Schema, User;

class UsersTable extends Migration {

   public function up() {
      Schema::create("users", function(Blueprint $table) {

         $table
            ->increments("id");

autoload_classmap.php

'Atomend\\Aeuser\\UsersTable' => $baseDir . '/src/migrations/2014_04_21_184359_users_table.php',

Terminal error

PHP Fatal error:  Class 'UsersTable' not found in

This is logical since the UsersTable is in the Atomend\Aeuser namespace.

Issuing the migration

php artisan migrate --bench="atomend/aeuser"`

So to be clear, when losing the namespace everything works fine and dandy.


回答1:


Laravel migrator doesn't play nice with namespaced migrations. Your best bet in this case is to subclass and substitute the Migrator class, like Christopher Pitt explains in his blog post: https://medium.com/laravel-4/6e75f99cdb0.



来源:https://stackoverflow.com/questions/23300555/how-to-make-laravel-migrator-work-with-namespaced-migrations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!