Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Fatal error: Class 'App\Providers\ServiceProvider' not found, after I fixed err Laravel migration: unique key is too long,

Tags:

php

I just started to learn Laravel 5.4 and trying to migrate a users table in Laravel. When I run my migration I get this error:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

After following this tutorial, I now have another error:

PHP Fatal error: Class 'App\Providers\ServiceProvider' not found

My migration code is

use Illuminate\Support\Facades\Schema;

public function boot()
{
    //
    Schema::defaultStringLength(191);
}

What am I doing wrong?

like image 805
Tavash Avatar asked Jan 29 '23 18:01

Tavash


1 Answers

The problem is that you are missing the use statement that identifies where the ServiceProvider class is. Since the AppServiceProvider class extends ServiceProvider, but there is no use statement, PHP assumes that the class can be found in the same namespace as AppServiceProvider. This is why it can't find \App\Providers\ServiceProvider - because \App\Providers is the namespace of the AppServiceProvider class.

Try this

<?php

namespace App\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()
    {
        //
    }
}
like image 157
stratedge Avatar answered Feb 02 '23 10:02

stratedge