How to Solve ErrorException file_put_contents failed to open stream: No such file or directory in Laravel 5.7

The best way to solve this problem is,

You should typically run the php artisan config:cache command as part of your production deployment routine. I suggest you

  1. Remove the configuration cache file
  2. Flush the application cache
  3. Create a cache file for faster configuration loading

To do this, run the following Artisan commands on your command line

  1. php artisan config:clear
  2. php artisan cache:clear
  3. php artisan config:cache

Where you don’t have access to the command line on your server, you can programmatically execute commands by adding the following to your routes:

Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('config:clear');
    $exitCode = Artisan::call('cache:clear');
    $exitCode = Artisan::call('config:cache');
    return 'DONE'; //Return anything
});

And then call the clear-cache route from your browser.

I hope this is helpful.