I was facing the issue when I do php artisan optimize
.
Below is my api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
/* |-------------------------------------------------------------------------- | API Routes |-------------------------------------------------------------------------- | | Here is where you can register API routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | is assigned the "api" middleware group. Enjoy building your API! | */
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
I am confuse & don't know what I am missing. Already tried following options
- Delete all cache files
- Also tried
php artisan cache:clear
- Composer update / composer dump-autoload
- env file changes
CACHE_DRIVER=file
,SESSION_DRIVER=database
Thanks in advance .
CodePudding user response:
If you check Laravel's optimize command:
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->call('config:cache');
$this->call('route:cache');
$this->info('Files cached successfully!');
}
There is a line $this->call('route:cache');
This line is throwing the error.
Laravel is trying to cache the routes. It does not accept Closure while caching the route. That's why moving your code to a controller fixed the issue.