1. Go to this page and download the library: Download palgoal/media-library 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/ */
use Palgoal\MediaLibrary\Concerns\HasMedia;
class Product extends Model
{
use HasMedia;
}
$product->attachMedia($mediaId, 'gallery');
$product->firstMediaUrl('cover', asset('images/placeholder.png'));
// أحد Service Providers الخاصة بتطبيقك
Gate::policy(\Palgoal\MediaLibrary\Models\Media::class, \App\Policies\MyMediaPolicy::class);
class MyMediaPolicy
{
public function viewAny($user): bool { return (bool) $user; }
public function view($user, Media $media): bool { return (bool) $user; }
public function create($user): bool { return (bool) $user; }
public function update($user, Media $media): bool { return $media->uploader_id === $user->id; }
public function delete($user, Media $media): bool { return $media->uploader_id === $user->id; }
}
// config/media-library.php
'disk' => 's3', // أي disk معرَّف في config/filesystems.php
'directory' => 'uploads', // الملفات تُخزَّن تحت {disk}/{directory}/{Year}/{Month}/{file}