定制 gromatics/laravel-nova-unsplash-media-library 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gromatics/laravel-nova-unsplash-media-library

最新稳定版本:1.0.4

Composer 安装命令:

composer require gromatics/laravel-nova-unsplash-media-library

包简介

Search and add Unsplash images to media library in Laravel Nova

README 文档

README

Laravel Nova Unsplash Media Library is a package that integrates Unsplash with Laravel Nova, enabling you to search and select images from Unsplash directly within your Nova resource. This package builds upon Spatie's Laravel Media Library for robust media handling.

Draggable

Installation

Step 1: Get an Unsplash API Key

First, you need to obtain an Unsplash API key. Follow these steps:

  1. Go to the Unsplash Developers page.
  2. Sign up or log in to your Unsplash account.
  3. Create a new application to get your API key.

Step 2: Install Spatie Laravel Media Library

Follow the installation and setup guide for Spatie's Laravel Media Library.

Step 3: Install Laravel Nova Unsplash Media Library

Install the Laravel Nova Unsplash Media Library package via Composer:

composer require gromatics/laravel-nova-unsplash-media-library

Step 4: Publish Configuration (optional)

Publish the configuration file:

php artisan vendor:publish --provider="Gromatics\LaravelNovaUnsplashMediaLibrary\FieldServiceProvider"

Step 5: Configure Unsplash API Key

Add your Unsplash API key to the .env file:

UNSPLASH_CLIENT_ID=your_unsplash_client_id

Usage

Step 1: Prepare Your Model

Ensure your model is set up to use the Spatie Media Library:

use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\Image\Manipulations;

class YourModel extends Model implements HasMedia
{
use InteractsWithMedia;

    public function registerMediaConversions(Media $media = null): void
    {
        $this
            ->addMediaConversion('thumb')
            ->fit(Manipulations::FIT_CROP, 150, 150)
            ->nonQueued();
    }
}

Step 2: Add UnsplashMediaLibrary to Your Nova Resource

Add the UnsplashMediaLibrary field to your Nova resource:

use YourName\LaravelNovaUnsplashMediaLibrary\UnsplashMediaLibrary;

class YourResource extends Resource
{
// Other resource methods...

    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            UnsplashMediaLibrary::make('Image'),
            // Other fields...
        ];
    }
}

License

This package is open-sourced software licensed under the MIT license.

Contributing

Contributions are welcome! Please open a new issue or submit a pull request.

Support

For support or any questions, please open an issue on the GitHub repository.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-09