You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Don't call `Schema::defaultStringLength()` in `ServiceProvider::boot()`
302
+
303
+
#### Problem
304
+
305
+
Assume that you have the following `ServiceProvider`.
306
+
307
+
```php
308
+
<?php
309
+
310
+
namespace App\Providers;
311
+
312
+
use Illuminate\Support\Facades\Schema;
313
+
use Illuminate\Support\ServiceProvider;
314
+
315
+
class AppServiceProvider extends ServiceProvider
316
+
{
317
+
/**
318
+
* Bootstrap any application services.
319
+
*
320
+
* @return void
321
+
*/
322
+
public function boot()
323
+
{
324
+
Schema::defaultStringLength(191);
325
+
}
326
+
}
327
+
```
328
+
329
+
If you run `composer install` or directly call `php artisan pacakge:discover`, it will unexpectedly use caches. It will trigger errors when we execute the command in the environment unreachable to the cache repository.
330
+
331
+
```
332
+
RedisException : Operation timed out
333
+
```
334
+
335
+
#### Solution
336
+
337
+
Directly use **`Illuminate\Database\Schema\Builder`**. Don't call via `Illuminate\Support\Facades\Schema` Facade.
338
+
339
+
```diff
340
+
<?php
341
+
342
+
namespace App\Providers;
343
+
344
+
-use Illuminate\Support\Facades\Schema;
345
+
+use Illuminate\Database\Schema\Builder as SchemaBuilder;
0 commit comments