Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Laravel migrator work with namespaced migrations?

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.

like image 316
sidneydobber Avatar asked Apr 25 '14 18:04

sidneydobber


1 Answers

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.

like image 90
Antonio Carlos Ribeiro Avatar answered Oct 20 '22 09:10

Antonio Carlos Ribeiro