PHP code example of van-ons / filament-attachment-library
1. Go to this page and download the library: Download van-ons/filament-attachment-library library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
van-ons / filament-attachment-library example snippets
namespace App\Providers\Filament;
use VanOns\FilamentAttachmentLibrary\FilamentAttachmentLibrary;
class ExamplePanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->plugin(
FilamentAttachmentLibrary::make()->navigationGroup('Files')
);
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use VanOns\LaravelAttachmentLibrary\Concerns\HasAttachments;
class ModelName extends Model
{
use HasAttachments;
// ...
}
namespace App\Filament\Resources;
use Filament\Forms;
use Filament\Forms\Form;
use VanOns\FilamentAttachmentLibrary\Forms\Components\AttachmentField;
public static function form(Form $form): Form
{
return $form
->schema([
// ...
// If you want to store the attachments in a column
AttachmentField::make('featured_image'),
// Or if you want to store attachments in the attachments relationship with a specific collection name
AttachmentField::make('gallery')->relationship(),
// Or if you want the collection name to be different from the field name
AttachmentField::make('gallery')->relationship()->collection('product_gallery'),
]);
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use VanOns\LaravelAttachmentLibrary\Concerns\HasAttachments;
class ModelName extends Model
{
use HasAttachments;
public function gallery(): MorphToMany
{
return $this->attachmentCollection('gallery');
}
}