medialibrary-helper/src/ServiceProvider.php

31 lines
1.0 KiB
PHP
Raw Normal View History

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([]));
}
public function boot(): void
{
app(Router::class)->group(['middleware' => ['web', 'auth:web']], function ($router) {
$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');
});
MediaCollection::macro('forceFileName', function ($callback) {
$this->forceFileRenamer = $callback;
return $this;
});
}
}