dejwcake/craftable-media

Associate files with Eloquent models

Installs: 413

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 10

Type:project

1.0.0 2025-02-24 17:48 UTC

This package is auto-updated.

Last update: 2025-02-24 20:35:52 UTC


README

This packages adds an ability to assign a media to your eloquent models. It uses Spatie's spatie/laravel-medialibrary, but it goes a bit further:

  • Collections definition - inspired by the conversions definition, we have created Media Collections definition via similar fluent API
  • Auto-Process - saving the eloquent model automatically processes and attaches media collections from the request
  • Authorization - controls, who has the permission to attach specific medium to specific model
  • Private access - controls, who has the permission to view specific medium

You can find full documentation at https://docs.getcraftable.com/#/media.

Composer

To develop this package, you need to have composer installed. To run composer command use:

  docker compose run -it --rm test composer update

For composer normalization:

  docker compose run -it --rm php-qa composer normalize

Run tests

To run tests use this docker environment.

  docker compose run -it --rm test vendor/bin/phpunit -d pcov.enabled=1

To switch between postgresql and mariadb change in docker-compose.yml DB_CONNECTION environmental variable:

- DB_CONNECTION: pgsql
+ DB_CONNECTION: mysql

Run code analysis tools

To be sure, that your code is clean, you can run code analysis tools. To do this, run:

For php compatibility:

  docker compose run -it --rm php-qa phpcs --standard=.phpcs.compatibility.xml --cache=.phpcs.cache

For code style:

  docker compose run -it --rm php-qa phpcs -s --colors --extensions=php

or to fix issues:

  docker compose run -it --rm php-qa phpcbf -s --colors --extensions=php

For static analysis:

  docker compose run -it --rm php-qa phpstan analyse --configuration=phpstan.neon

For mess detector:

  docker compose run -it --rm php-qa phpmd ./src,./config,./install-stubs,./resources,./routes,./tests ansi phpmd.xml --suffixes php --baseline-file phpmd.baseline.xml