Skip to content

Commit 5d9d0fb

Browse files
committed
add blade component
1 parent 13afff3 commit 5d9d0fb

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
}
1111
],
1212
"php": "8.0",
13-
"homepage": "https://github.com/gepopp/image",
14-
"keywords": ["Laravel", "Image"],
13+
"homepage": "https://github.com/gepopp/laravel-image",
14+
"keywords": ["Laravel", "Image", "WebP", "Larave Nova"],
1515
"require-dev": {
1616
"phpunit/phpunit": "~9.0",
1717
"orchestra/testbench": "~7"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="{{ $image->webp_url ?? $image->url }}" width="{{ $image->width }}" height="{{ $image->height }}" srcset="{{ $image->webp_srcset ?? $image->srcset }}" alt="{{ $image->alt }}">

src/ImageServiceProvider.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Gepopp\Image;
44

55
use Gepopp\Image\Observers\ImageObserver;
6+
use Gepopp\Image\View\Components\ImageComponent;
7+
use Illuminate\Support\Facades\Blade;
68
use Illuminate\Support\ServiceProvider;
79

810
class ImageServiceProvider extends ServiceProvider
@@ -15,7 +17,7 @@ class ImageServiceProvider extends ServiceProvider
1517
public function boot(): void
1618
{
1719
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'gepopp');
18-
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'gepopp');
20+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'gepopp');
1921
$this->loadMigrationsFrom( __DIR__ . '/../database/migrations', 'gepopp' );
2022
// $this->loadRoutesFrom(__DIR__.'/routes.php');
2123

@@ -26,6 +28,8 @@ public function boot(): void
2628

2729

2830
\Gepopp\Image\Model\Image::observe( ImageObserver::class );
31+
32+
Blade::component( ImageComponent::class, 'image');
2933
}
3034

3135
/**
@@ -72,9 +76,9 @@ protected function bootForConsole(): void
7276
], 'image.config' );
7377

7478
// Publishing the views.
75-
/*$this->publishes([
79+
$this->publishes([
7680
__DIR__.'/../resources/views' => base_path('resources/views/vendor/gepopp'),
77-
], 'image.views');*/
81+
], 'image.views');
7882

7983
// Publishing assets.
8084
/*$this->publishes([

src/Jobs/CreateImageSizeJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CreateImageSizeJob implements ShouldQueue
2424
/**
2525
* Create a new job instance.
2626
*/
27-
public function __construct( public int $image_id, public int $width, public int|null $height, public bool $crop = false, public bool $webp = true )
27+
public function __construct( public int $image_id, public int $width, public int|null $height, public bool $crop = false )
2828
{
2929
//
3030
}

src/Observers/ImageObserver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function created( Image $image ): void
4848
foreach ($sizes as $size)
4949
{
5050
if( config('image.image_sizes.queue')){
51-
CreateImageSizeJob::dispatch($image->id, $size[0], $size[1], $size[2], config('image.image_sizes.create_webp'));
51+
CreateImageSizeJob::dispatch($image->id, ...$size);
5252
}else{
53-
CreateImageSizeJob::dispatchSync($image->id, $size[0], $size[1], $size[2], config('image.image_sizes.create_webp'));
53+
CreateImageSizeJob::dispatchSync($image->id, ...$size);
5454
}
5555
}
5656
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Gepopp\Image\View\Components;
4+
5+
use Closure;
6+
use Illuminate\Contracts\View\View;
7+
use Illuminate\View\Component;
8+
9+
class ImageComponent extends Component
10+
{
11+
12+
public \Gepopp\Image\Model\Image $image;
13+
/**
14+
* Create a new component instance.
15+
*/
16+
public function __construct( \Gepopp\Image\Model\Image $image )
17+
{
18+
$this->image = $image;
19+
}
20+
21+
/**
22+
* Get the view / contents that represent the component.
23+
*/
24+
public function render(): View|Closure|string
25+
{
26+
return view('gepopp::components.image', ['image' => $this->image]);
27+
}
28+
}

0 commit comments

Comments
 (0)