The error message you're encountering, Route [storage.local] not defined, suggests that Laravel is trying to generate a temporary URL for a local disk, but the necessary route to serve the file is not set up. In Laravel, when you want to serve files from a local disk using temporary URLs, you need to ensure that the appropriate route is defined.
Here's how you can resolve this issue:
-
Define the Route: Laravel 11 introduced the ability to serve files from local disks using temporary URLs, but you need to define a route to handle these requests. You can do this by adding the following to your
routes/web.phpfile:use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Storage; Route::get('/storage/{path}', function ($path) { $file = Storage::disk('files')->path($path); if (!file_exists($file)) { abort(404); } return response()->file($file); })->where('path', '.*')->name('storage.local');This route will handle requests to
/storage/{path}and serve the file if it exists. -
Update the
temporaryUrlCall: Ensure that yourtemporaryUrlmethod call is correctly generating the URL. You should pass the relative path to the file, not the full path. Here's how you can adjust your code:$temporaryUrl = Storage::disk('files')->temporaryUrl($this->full_path, now()->addMinutes(5));Make sure
$this->full_pathis the relative path from the root of the disk, not the full system path. -
Check Configuration: Ensure your filesystem configuration is correct. You've already set
'serve' => true, which is necessary for serving files. Double-check that the'root'path is correct and points to the directory where your files are stored.
By following these steps, you should be able to generate temporary URLs for files stored on a local disk without encountering the RouteNotFoundException.