-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
333ed84
commit aab0135
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace HnhDigital\HelperCollection\Response; | ||
|
||
use Illuminate\Support\Facades\Response; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class MacroServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register the application's response macros. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
// Providesd the ability to download a file from a given path. | ||
// Will also return a not modified header if file has not changed. | ||
Response::macro('downloadAndCache', function ($file_path) { | ||
if (!empty(request()->header('If-Modified-Since'))) { | ||
$cache_last_modified = strtotime(request()->header('If-Modified-Since')); | ||
$file_last_modified = filemtime($file_path); | ||
if ($file_last_modified == $cache_last_modified) { | ||
header('HTTP/1.1 304 Not Modified'); | ||
exit(); | ||
} | ||
} | ||
|
||
return Response::file($file_path); | ||
}); | ||
} | ||
} |