1. Go to this page and download the library: Download moh-slimani/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/ */
moh-slimani / media example snippets
...
/*
* The fully qualified class name of the media model.
*/
'media_model' => MohSlimani\Media\Models\Media::class,
...
...
/*
* The class that contains the strategy for determining a media file's path.
*/
'path_generator' => MohSlimani\Media\Helpers\MediaPathGenerator::class,
...
use MohSlimani\Media\Traits\UseMediaModel
use MohSlimani\Media\Media
use Spatie\MediaLibrary\HasMedia;
class User extends Authenticatable implements HasMedia
{
// you don't need to user InteractsWithMedia
use HasApiTokens, HasFactory, Notifiable, UseMediaModel;
/**
* This array should contain the list of media keys to be registered.
*
* @var array $files
* @example ['photo' => Media::SINGLE_FILE, 'files' => Media::MULTIPLE_FILES]
*/
protected array $files = [
'photo' => Media::SINGLE_FILE,
'cv', // Media::SINGLE_FILE is the default
'files' => Media::MULTIPLE_FILES
];
...
/** @var File $photo */
$user->addMedia($photo)->toMediaCollection('photo');
// Or use the