Unsplash gallery for Filament. Search and pick any image from Unsplash.com, specify which size to use.
This package is being re-written and will mostly probably be ready to use after Filament v4. Re-writing this package is allowing me to work on remaining features and remove unnecessary hacks. You may check the re-write branch and the progress on todo list.
You can install the plugin via composer:
composer require mansoor/filament-unsplash-picker
Add Unsplash Client ID to config/services.php
'unsplash' => [ 'client_id' => env('UNSPLASH_CLIENT_ID'),],
Integrate plugin Tailwind CSS by creating a custom Filament theme. After you have created your custom theme, add Unsplash Picker views to your new theme's tailwind.config.js
file located in resources/css/filament/admin/tailwind.config.js
:
content: [ ... './vendor/mansoor/filament-unsplash-picker/resources/views/**/*.blade.php',],
Just add the UnsplashPickerAction
to your FileUpload Field's action.
use Mansoor\UnsplashPicker\Actions\UnsplashPickerAction; Forms\Components\FileUpload::make('featured_image') ->image() ->hintAction( UnsplashPickerAction::make() )
This plugin also supports all the features for Spatie Media Libaray Plugin
SpatieMediaLibraryFileUpload::make('featured_image') ->image() ->hintAction( UnsplashPickerAction::make() )
You can specify which image size to use.
UnsplashPickerAction::make() ->regular()
Available sizes:
->raw()
->full()
->regular()
->small()
->thumbnail()
If you add ->multiple()
to your FileUpload field, the plugin will allow you to pick multiple images. The plugin respects the validation so you will only be able to pick max files set by the FileUpload field.
FileUpload::make('featured_image') ->multiple() // This will indicate the plugin to allow the user to pick multiple files ->hintAction( UnsplashPickerAction::make() )
You may specify how many photos to show per page by appending ->perPage()
method.
UnsplashPickerAction::make() ->perPage(20)
You can choose to dispaly images in square which uses aspect-square
class from Tailwind CSS or disable it to display images in original height.
UnsplashPickerAction::make() ->useSquareDisplay(false)
You may set the default search input.
UnsplashPickerAction::make() ->defaultSearch('Hello world')
You can also pass a custom closure to get search input from a field and return the search string.
UnsplashPickerAction::make() ->defaultSearch(fn (Get $get) => $get('title'))
Similar to core Filament, Unsplash picker provides two hooks beforeUpload
and afterUpload
to let you use Unsplash data.
UnsplashPickerAction::make() ->afterUpload(function (array $data) { dd($data); })
The UnsplashPickerAction
is simple Filament Form Action and you may override all the available methods. The Image picker component is a Livewire component, which is easy to extend.
Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-unsplash-picker-views"
❗ Important: When defining the
extraAlpineAttributes
method forSpatieMediaLibraryFileUpload
orFileUpload
field, make sure to merge the Alpine attributes fromUnsplashPickerAction
.
SpatieMediaLibraryFileUpload::make('media') ->extraAlpineAttributes(function ($component) { return [ 'custom-attribute' => 'custom-attribute-value-goes-here', ...UnsplashPickerAction::getExtraAlpineAttributes($component), ]; })
This plugin is re-written but it is very small and simple, so upgrade is very easy. If you follow the docs from top to bottom, you should be good to use the latest version.
Action::configureUsing()
in service provider to achieve the same. You may also delete the config fileunsplash_client_id
has been removed to from plugin config file. You may add it to config/services.php
. Please check Installation section.composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
Mansoor is a full-stack developer. He is currently working as a freelancer on Upwork.com, where he assists businesses in developing and maintaining their customer-facing and internal applications using Laravel, Vue.js, Tailwind CSS, and Livewire.