Errors in laravel

  1. SQLSTATE[42000]: Syntax error or access violation: specified key was too long->This is due to old version (In 5.4 and 5.5) on mysql or mariadb. To fix that error, goto app>providers>AppServiceProviders.php. Inside boot() method write
    Schema::defaultStringLength(191);
    And write after namespace
    use Illuminate\Support\Facades\Schema;
  2. The page has expired due to inactivity: Refreshing the page could solve the problem. If refreshment cannot solve the problem then you might missed csrf_token() field in any form of that page.
  3. No such file or directory: Run the command composer dump-autoload
  4. MassAssignmentException: Create $fillable in you model and give the key which will be filled.
  5. Foreign key constraint is incorrectly formed: You fault is: you have put $table->references()->on() inside Schema::create(){}Your migration should be like below:
    Schema::create('articles', function (Blueprint $table) {
         $table->increments('id');
         $table->string('body');
         $table->timestamps();
    });
    // Add Foreign key
    Schema::table('articles', function (Blueprint $table) {
         $table->unsignedInteger('user_id');
         $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
    });
  6. errno: 121 “Duplicate key on write or update”: Carefully check names of the table in Schema::table('is_it_correct?‘){}
  7. Edit your applications’s database config file config/database.phpIn mysql array, set strict => false to disable MySQL’s strict mode
  8. nl2br: When anybody
    Using app\Providers\AppServiceProvider
    Add the following code to AppServiceProvider.php> boot function
    Blade::setEchoFormat('nl2br(e(%s))');
    and the namespace for it
    use Illuminate\Support\Facades\Blade;
    Now all new line will be replaced by <br/&gh; including textarea during update. You can escape this text using three curly bracket as like below:
    {{{ $your_variable }}}
    NB: Be careful about cache.
  9. You can use nl2br in your blade
    {{ nl2br(e($your_variable)) }}
  10. 'Class 'PayPal\Rest\ApiContext' not found'
    Solution: Either the package is not installed correctly or composer dump-autoload need to run. If you have installed the paypal once, please install again (In my case, I installed once did not run).
  11. vendor/autoload.php failed to open stream laravel: This error occured after cloning my project from gitlab. To solve run the command below: 
    composer update --no-scripts
  12. Trying to get property 'id' of non-object .... in AppServiceProvider.php line 20: This error occured because you are logged out. Login again and problem solved.

Labels: ,

© copyright-2020 Rejaul