1. Go to this page and download the library: Download rawbinn/media library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Models;
use Rawbinn\Media\Models\Media as BaseMedia;
class Media extends BaseMedia
{
protected $fillable = [
...parent::getFillable(),
'alt_text',
];
}
'model' => \App\Models\Media::class,
media_model()::find($id);
media($id); // URL for media ID
media($id, '200x200'); // Cached resize URL
media_url('path/to/file'); // Storage URL for a path
media_disk(); // Configured filesystem disk
use Rawbinn\Media\Facades\Media;
return Media::cache('uploads/photo.jpg', '300x200');
'security' => [
'enforce_ownership' => true, // Restrict download/preview/delete to owner
'verify_mime' => true, // Validate MIME type against extension
'signed_downloads' => false, // Require signed URLs for downloads
],
$media->signedDownloadUrl(30); // minutes
use Rawbinn\Media\Events\MediaUploaded;
use Rawbinn\Media\Events\MediaDeleted;
Event::listen(MediaUploaded::class, function (MediaUploaded $event) {
// $event->media
});