{"id":20513445,"url":"https://github.com/slimani-dev/media","last_synced_at":"2025-04-23T20:02:59.035Z","repository":{"id":223241339,"uuid":"759661433","full_name":"slimani-dev/media","owner":"slimani-dev","description":"A model for Laravel Medialibrary","archived":false,"fork":false,"pushed_at":"2025-02-03T14:00:25.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T07:07:31.334Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slimani-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Mohamed slimani"}},"created_at":"2024-02-19T04:58:44.000Z","updated_at":"2025-02-03T14:00:30.000Z","dependencies_parsed_at":"2024-02-19T20:24:23.531Z","dependency_job_id":"dcfa2fee-db98-4197-a5c3-ef19efd91eb7","html_url":"https://github.com/slimani-dev/media","commit_stats":null,"previous_names":["moh-slimani/laravel-medialibrary-model","moh-slimani/media","slimani-dev/media"],"tags_count":16,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fmedia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fmedia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fmedia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fmedia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slimani-dev","download_url":"https://codeload.github.com/slimani-dev/media/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240521050,"owners_count":19814694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T21:11:07.050Z","updated_at":"2025-02-24T17:13:59.635Z","avatar_url":"https://github.com/slimani-dev.png","language":"PHP","funding_links":["https://github.com/sponsors/Mohamed slimani"],"categories":[],"sub_categories":[],"readme":"# A Media Model for laravel medialibrary\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/moh-slimani/media.svg?style=flat-square)](https://packagist.org/packages/moh-slimani/media)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/moh-slimani/media/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/moh-slimani/media/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/moh-slimani/media/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/moh-slimani/media/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/moh-slimani/media.svg?style=flat-square)](https://packagist.org/packages/moh-slimani/media)\n\nThis package simplifies the integration of Spatie MediaLibrary by offering a streamlined approach to registering\nand managing media assets within Laravel applications, effortlessly cast media to a simple format, leveraging a\npath generator that enhances readability and organization. Seamlessly handle media registration\nwhile maintaining all functionalities of The MediaLibrary package.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require moh-slimani/media\n```\n\nYou must publish and run the migrations,this will add soft delete to the media model\n\n```bash\nphp artisan vendor:publish --tag=\"media-migrations\"\nphp artisan migrate\n```\n\nchange the media_model in the media library config file\n\n`config/media-library.php`\n\n```php\n\n    ...\n    /*\n     * The fully qualified class name of the media model.\n     */\n    'media_model' =\u003e MohSlimani\\Media\\Models\\Media::class,\n    \n    ...    \n\n```\n\n**Optional :** you can change the path generator in the media library config file\n\n```php\n\n    ...\n    \n    /*\n     * The class that contains the strategy for determining a media file's path.\n     */\n    'path_generator' =\u003e MohSlimani\\Media\\Helpers\\MediaPathGenerator::class,\n\n    ...\n\n```\n\n## Usage\n\n```php\nuse MohSlimani\\Media\\Traits\\UseMediaModel\nuse MohSlimani\\Media\\Media\nuse Spatie\\MediaLibrary\\HasMedia;\n\n\nclass User extends Authenticatable implements HasMedia\n{\n\n    // you don't need to user InteractsWithMedia\n    use HasApiTokens, HasFactory, Notifiable, UseMediaModel;\n\n\n    /**\n     * This array should contain the list of media keys to be registered.\n     *\n     * @var array $files\n     * @example ['photo' =\u003e Media::SINGLE_FILE, 'files' =\u003e Media::MULTIPLE_FILES]\n     */\n    protected array $files = [\n        'photo' =\u003e Media::SINGLE_FILE, \n        'cv', // Media::SINGLE_FILE is the default\n        'files' =\u003e Media::MULTIPLE_FILES\n    ];\n\n    ...\n```\n\nAfter that you can add files it like you used to using the `medialibrary` package\n\n```php\n\n/** @var File $photo */\n$user-\u003eaddMedia($photo)-\u003etoMediaCollection('photo');\n\n// Or use the included function\n$user-\u003eaddMediaFiles($photo, 'photo');\n```\n\n\u003e the function addMediaFiles to simplify the process of adding media files to collections. This function allows you to\n\u003e add a single file to a specified collection and provides an option to keep or delete existing files in the collection.\n\u003e it will also generate a unique code based on current time to prepend to the file name\n\u003e You can find more information about this and other changes in the [CHANGELOG](CHANGELOG.md).\n\nyou can get the files like this\n\n```php\n\n    $user-\u003ephoto\n \n    [\n        \"id\" =\u003e 15,\n        \"name\" =\u003e \"IMG_7833\",\n        \"url\" =\u003e \"http://media.test/storage/Users/1/photo/IMG_7833.jpg\",\n        \"size\" =\u003e 249686,\n        \"mime\" =\u003e \"image/jpeg\",\n        \"type\" =\u003e \"image\",\n        \"created_at\" =\u003e Illuminate\\Support\\Carbon @1705898712 {#6527\n          date: 2024-02-19 00:00:00.0 UTC (+00:00),\n        },\n        \"updated_at\" =\u003e Illuminate\\Support\\Carbon @1705898712 {#6782\n          date: 2024-02-19 00:00:00.0 UTC (+00:00),\n        },\n    ]\n\n\n\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\n- [Mohamed slimani](https://github.com/moh-slimani)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimani-dev%2Fmedia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslimani-dev%2Fmedia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimani-dev%2Fmedia/lists"}