Skip to content

Commit 746fb54

Browse files
author
mostafa
committed
route
1 parent 8360fa8 commit 746fb54

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

web-developer/laravel/tips/vip/restful-api-image-uplod.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
```

0 commit comments

Comments
 (0)