First, fix bug. Then, love Laravel.

Bugs during development are indispensable for every programmer, it’s like a “close friend” indispensable in the life of us life.

Being close friends we need to care and understand each other. 😁
For this process to take place more quickly and to love Laravel, we need to capture these extraordinary “trait”, or fundamental errors that we will encounter in the development process.
Here is the list you will have to familiarize yourself with:

# Problem
RuntimeException in EncryptionServiceProvider.php line 29:
No supported encrypter found. The cipher and / or key length are invalid
orWhoops, looks like something went wrong.# Solution: Run cmdphp artisan key:generate
# Problem
Unexpected Exception: SQLSTATE[HY000] [1045] Access denied for user ****@'localhost' (using password: YES)
# Solution: Check connection DB_USERNAME, DB_PASSWORD in file .env or config/database.php
# Problem
[ReflectionException]
Class LoveLaravelSeeder does not exist
# Solution: Run cmd
composer dump-autoload
# Problem
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
# Solution: Edit file AppServiceProvider.php
use Illuminate\Support\Facades\Schema;
.....
public function boot()
{
Schema::defaultStringLength(191);
}
# Problem
TokenMismatchException in VerifyCsrfToken.php line 68:
# Solution: Add method in <form>...</form>{{ csrf_field() }}When use ajax(jquery):$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
# Problem
NotFoundHttpException in RouteCollection.php
# Solution: This error may be due to set permission
sudo chmod -R 777 storage
sudo chmod -R 777 bootstrap/cache
# Problem
This is not an error, but it implies a lot of risk.
# Solution: Eager loading
https://laravel.com/docs/5.6/eloquent-relationships#eager-loading
# Problem
Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint ...
# Solution:class DatabaseSeeder extends Seeder {
public function run()
{
Eloquent::unguard();
//disable foreign key before running seeders
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
$this->call('UsersTableSeeder');
...
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
}
}
# Problem
[RuntimeException]
Error Output: PHP Warning: require(bootstrap/../vendor/autoload.php):
# Solution:Run composer with --no-scripts
composer update --no-scripts
# Problem
It is scary if the implementation has an error, and everything in the .env file is revealed :(
# Solution: Given this in config/app.php filereturn [
'blacklist' => [
'_ENV' => [
'APP_KEY',
'DB_PASSWORD',
'REDIS_PASSWORD',
'MAIL_PASSWORD',
'PUSHER_APP_KEY',
'PUSHER_APP_SECRET',
],
'_SERVER' => [
'APP_KEY',
'DB_PASSWORD',
'REDIS_PASSWORD',
'MAIL_PASSWORD',
'PUSHER_APP_KEY',
'PUSHER_APP_SECRET',
],
'_POST' => [
'password',
],
],
];

Thank you for reading, I hope it will help you in the process of practicing with Laravel.
I ❤️ Laravel.

This is the article I participated in the contest about writing about Laravel, you can see more here, my issue.

Be Curious!| ☕️+✍🏼=❤️ | buihuycuong.com