mod: fix caching!

This commit is contained in:
Didier Slof 2023-02-02 08:31:50 +01:00
parent 34ed81516b
commit dc5d204cfc
Signed by: didier
GPG key ID: 01E71F18AA4398E5
8 changed files with 42 additions and 7 deletions

View 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]);
}
}

View file

@ -0,0 +1 @@
<img src="{{ $src }}" alt="{{ $alt }}" class="{{ $class }}" width="{{ $width }}" height="{{ $height }}"/>

View file

@ -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/>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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">

View file

@ -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/>