mod: fix caching!
This commit is contained in:
parent
34ed81516b
commit
dc5d204cfc
8 changed files with 42 additions and 7 deletions
35
app/View/Components/CacheImage.php
Normal file
35
app/View/Components/CacheImage.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
/// Used to cache online images to local storage
|
||||
class CacheImage extends Component
|
||||
{
|
||||
public function __construct(public string $src, public string $alt = '', public string $class = '', public string $width = "", public string $height = "")
|
||||
{
|
||||
$this->src = $src;
|
||||
$this->alt = $alt;
|
||||
$this->class = $class;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
|
||||
$this->handleCache();
|
||||
}
|
||||
|
||||
public function handleCache()
|
||||
{
|
||||
if (!\Cache::has($this->src)) {
|
||||
$image = file_get_contents($this->src);
|
||||
\Cache::put($this->src, $image, 60 * 24 * 7);
|
||||
}
|
||||
return \Cache::get($this->src);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('components.cache-image', ['src' => $this->handleCache(), 'alt' => $this->alt, 'class' => $this->class, 'width' => $this->width, 'height' => $this->height]);
|
||||
}
|
||||
}
|
1
resources/views/components/cache-image.blade.php
Normal file
1
resources/views/components/cache-image.blade.php
Normal file
|
@ -0,0 +1 @@
|
|||
<img src="{{ $src }}" alt="{{ $alt }}" class="{{ $class }}" width="{{ $width }}" height="{{ $height }}"/>
|
|
@ -19,8 +19,7 @@
|
|||
<div id="showings">
|
||||
@foreach($cinema->showings as $showing)
|
||||
<a href="/showing/{{$showing->showing_id}}">
|
||||
<img src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster"
|
||||
width="200px">
|
||||
<x-cache-image src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster" class="poster" width="200px"/>
|
||||
<div class="details">
|
||||
<span>{{$showing->movie->movie_name}}</span><br/>
|
||||
<span>{{$showing->showing_date}}</span><br/>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<div id="movies">
|
||||
@foreach($genre->movies as $movie)
|
||||
<a href="/movie/{{$movie->movie_id}}">
|
||||
<img src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" width="200px">
|
||||
<x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
|
||||
<div class="details">
|
||||
<span>{{$movie->movie_name}}</span><br/>
|
||||
<span>{{$movie->movie_length}} min</span>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div id="movies">
|
||||
@foreach($movies as $movie)
|
||||
<a class="movie" href="{{route('movie', ['id' => $movie->movie_id])}}">
|
||||
<img src="{{ $movie->movie_image }}" alt="{{ $movie->movie_name }}">
|
||||
<x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
|
||||
<div class="details">
|
||||
<h2>{{ $movie->movie_name }}</h2>
|
||||
<span>{{ $movie->movie_description }}</span>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<h1>{{$movie->movie_name}}</h1>
|
||||
<hr/>
|
||||
<div id="movie">
|
||||
<img src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" width="200px">
|
||||
<x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
|
||||
<div class="details">
|
||||
<span>{{$movie->movie_length}} min</span><br/>
|
||||
<span>{{$movie->movie_description}}</span>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
@section('content')
|
||||
|
||||
<section>
|
||||
<h1><img src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster" width="60px">
|
||||
<h1><x-cache-image src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster" class="poster" width="60px"/>
|
||||
{{$showing->movie->movie_name}}</h1>
|
||||
<hr/>
|
||||
<div id="showing">
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<div id="movies">
|
||||
@foreach($movies as $movie)
|
||||
<a href="/manage/movie/{{$movie->movie_id}}">
|
||||
<img src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" width="200px">
|
||||
<x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
|
||||
<div class="details">
|
||||
<h3>{{$movie->movie_name}}</h3><br/>
|
||||
<span>{{ Str::limit($movie->movie_description, 500) }}</span><br/>
|
||||
|
|
Loading…
Reference in a new issue