PHP Artisan migrate: Class Schema not found

2

I am studying Laravel 5.4 and I have the following problem:

When performing a migration, in the console of Windows I execute the command:

php artisan migrate

When executing this command, it shows me the following error:

  

[Symfony \ Component \ Debug \ Exception \ FatalErrorException] Class   'Market \ Providers \ Schema' not found

How can I solve Class Schema not found ? annex the migration code:

-To create the product table:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table){
            $table->increments('id');
            $table->string('name',100);
            $table->decimal('price',5,2);
            $table->integer('marks_id')->unsigned();
            $table->foreign('marks_id')->references('id')->on('marks');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('products');
    }
}

-To create the Brand Table

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateMarkTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('marks', function (Blueprint $table){
            $table->increments('id');
            $table->string('name',50);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('marks');
    }
}

-Code of AppServiceProvider.php

<?php

namespace Market\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
    
asked by FranMoronR 04.05.2017 в 23:40
source

2 answers

1

Because of what you show in the code of your AppServiceProvider.php, you are not including the Facade class from the appropriate namespace, it simply replicates the use that is in the migrations:

<?php

namespace Market\Providers;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
    
answered by 05.05.2017 / 17:14
source
0

When loading the service provider it does not find the indicated class, either because you did not put it correctly or because you did not put it. Open the file "../app/providers/AppServiceProvider.php" and before the definition of the class indicates that you are going to use the class Schema , indicating the full namespace :

use \Market\Providers\Schema;
class AppServiceProvider extends  ServiceProvider
{
...
    
answered by 05.05.2017 в 00:42