File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
web-developer/laravel/tips/vip Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -142,3 +142,39 @@ class Test extends controllers {
142142 }
143143}
144144```
145+
146+ ## custom storage content route
147+
148+ * if you can't take hussle for siblink with public folder you can use custom route
149+
150+ * ` route ` for ` local ` storage
151+
152+ ``` php
153+ Route::get('/storage/{params}', function($params){
154+ $path = storage_path('app/'.$params);
155+ $file = File::get($path);
156+ $type = File::mimeType($path);
157+ $response = Response::make($file, 200);
158+ $response->header("Content-Type", $type);
159+ if(file_exists(storage_path('app/'.$params))){
160+ return $response;
161+ }
162+ })->where('params', '.*');
163+
164+ ```
165+
166+ * ` route ` for storage ` 2nd method `
167+
168+ ``` php
169+ Route::get('/storage/{disk}/{params}', function($disk,$params){
170+ if (Storage::disk($disk)->exists($params)) {
171+ $storageFile = Storage::disk($disk)->get($params);
172+ return response($storageFile, 200)->header('Content-Type', Storage::disk('local')->mimeType($params));
173+ }
174+ })->where('params', '.*');
175+
176+ ```
177+
178+ ``` php
179+ {{ asset('storage/diskname/test.png')` }}
180+ ```
You can’t perform that action at this time.
0 commit comments