happytodev/filament-social-networks
Filament plugin for managing and displaying social network links in your Laravel admin. Configure common platforms with icons/URLs, keep profiles consistent across your app, and render social links where needed with a simple, reusable setup.
Installation
composer require happytodev/filament-social-networks
Publish the config (if needed):
php artisan vendor:publish --provider="Happytodev\FilamentSocialNetworks\FilamentSocialNetworksServiceProvider" --tag="config"
First Use Case Add the field to a Filament resource form:
use Happytodev\FilamentSocialNetworks\Fields\SocialNetworksField;
SocialNetworksField::make('social_links')
->required()
->columns(2) // Adjust layout
->help('Add your social media profiles.')
Where to Look First
config/filament-social-networks.php for customizationapp/Models/User.php to define the database column (e.g., social_links->json).Resource Integration
// In a Filament Resource
public static function form(Form $form): Form
{
return $form
->schema([
// ...
SocialNetworksField::make('social_media')
->label('Social Profiles')
->columnSpanFull(),
]);
}
Customizing Networks Extend the default list via config:
// config/filament-social-networks.php
'networks' => [
'github' => [
'label' => 'GitHub',
'icon' => 'heroicon-o-code-bracket',
'url_pattern' => 'https://github.com/{username}',
],
// Add custom networks here
],
Validation & Storage
social_links column in DB).SocialNetworksField::make('social_links')
->rules(['required', 'url'])
->validateUrls() // Built-in URL validation
Dynamic Data Handling
// Retrieve data in a model
$user->social_links['twitter'] ?? null;
// Update via API
$user->update(['social_links' => ['twitter' => 'https://twitter.com/user']]);
SocialNetworksField inside custom Livewire components.public function toArray($request)
{
return [
'social_links' => $this->social_links,
];
}
Database Schema
json or text (not string).$table->json('social_links')->nullable();
URL Validation
->rules(['required', function ($attribute, $value, $fail) {
if (!preg_match('/linkedin\.com\/in\/[a-zA-Z0-9_-]+/', $value)) {
$fail('Invalid LinkedIn URL.');
}
}])
Icon Conflicts
'icons' => [
'github' => 'https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg',
],
null or malformed. Use:
$user->social_links = json_encode($user->social_links);
AppServiceProvider:
FilamentSocialNetworksServiceProvider::make();
Custom Networks Dynamically add networks via a callback:
SocialNetworksField::make('social_links')
->getNetworksUsing(function () {
return collect(config('filament-social-networks.networks'))
->merge(['custom' => ['label' => 'Custom', 'icon' => 'heroicon-o-globe-alt']]);
})
Event Hooks Listen for social link updates (if the package emits events):
// Example (hypothetical)
event(new SocialLinksUpdated($user, $oldLinks, $newLinks));
Localization Translate labels/network names:
->label(__('Social Media'))
->networkLabels([
'twitter' => __('Twitter'),
'linkedin' => __('LinkedIn'),
])
with():
User::with(['social_links' => function ($query) {
$query->select('id', 'social_links');
}])->get();
Cache::remember('filament-social-networks-networks', now()->addHours(1), function () {
return config('filament-social-networks.networks');
});
How can I help you explore Laravel packages today?