This is the documentation for
v4 but the latest version is
v9
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-medialibrary
To associate media with a model, the model must implement the following interface and trait:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia;
class News extends Model implements HasMedia
{
use HasMediaTrait;
...
}