Add laravel-medialibrary for avatars
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateMediaTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('media', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->morphs('model');
|
||||
$table->string('collection_name');
|
||||
$table->string('name');
|
||||
$table->string('file_name');
|
||||
$table->string('mime_type')->nullable();
|
||||
$table->string('disk');
|
||||
$table->unsignedInteger('size');
|
||||
$table->json('manipulations');
|
||||
$table->json('custom_properties');
|
||||
$table->json('responsive_images');
|
||||
$table->unsignedInteger('order_column')->nullable();
|
||||
$table->nullableTimestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('media');
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@ class FileController extends Controller
|
||||
* Remove the file from storage.
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
|
||||
49
app/Support/Media/PublicUrlGenerator.php
Normal file
49
app/Support/Media/PublicUrlGenerator.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Support\Media;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Spatie\MediaLibrary\Exceptions\UrlCannotBeDetermined;
|
||||
use Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator;
|
||||
|
||||
/**
|
||||
* Class PublicUrlGenerator
|
||||
* @package App\Support\Media
|
||||
*/
|
||||
class PublicUrlGenerator extends BaseUrlGenerator
|
||||
{
|
||||
/**
|
||||
* Get the url for the profile of a media item.
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return public_asset($this->getPathRelativeToRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the temporary url for a media item.
|
||||
*
|
||||
* @param DateTimeInterface $expiration
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTemporaryUrl(DateTimeInterface $expiration, array $options = []): string
|
||||
{
|
||||
throw UrlCannotBeDetermined::filesystemDoesNotSupportTemporaryUrls();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url to the directory containing responsive images.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponsiveImagesDirectoryUrl(): string
|
||||
{
|
||||
return public_asset('/').'/'.$this->pathGenerator->getPathForResponsiveImages($this->media);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user