2023-03-06 14:00:22 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zoomyboy\MedialibraryHelper;
|
|
|
|
|
|
|
|
use Illuminate\Routing\Router;
|
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
|
|
|
use Spatie\MediaLibrary\MediaCollections\MediaCollection;
|
|
|
|
|
|
|
|
class ServiceProvider extends BaseServiceProvider
|
|
|
|
{
|
|
|
|
public function register(): void
|
|
|
|
{
|
|
|
|
app()->bind('media-library-helpers', fn () => collect([]));
|
2023-03-07 21:53:36 +01:00
|
|
|
app()->singleton(CollectionExtension::class, fn () => new CollectionExtension());
|
2023-03-06 14:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function boot(): void
|
|
|
|
{
|
2023-03-07 15:31:24 +01:00
|
|
|
app(Router::class)->group($this->routeGroup(), function ($router) {
|
2023-03-06 14:00:22 +01:00
|
|
|
$router->post('mediaupload', [MediaController::class, 'store'])->name('media.store');
|
|
|
|
$router->delete('mediaupload/{media}', [MediaController::class, 'destroy'])->name('media.destroy');
|
|
|
|
$router->get('mediaupload/{parent_model}/{parent_id}/{collection}', [MediaController::class, 'index'])->name('media.index');
|
|
|
|
});
|
|
|
|
|
2023-03-07 21:53:36 +01:00
|
|
|
app(CollectionExtension::class)->boot();
|
2023-03-06 14:00:22 +01:00
|
|
|
|
2023-03-07 15:31:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array{middleware: array<int, string>}
|
|
|
|
*/
|
|
|
|
protected function routeGroup(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'middleware' => config('medialibrary-helper.middleware'),
|
|
|
|
];
|
2023-03-06 14:00:22 +01:00
|
|
|
}
|
|
|
|
}
|