austral/social-network-bundle
Installation Add the bundle to your Laravel/Symfony project via Composer:
composer require austral/social-network-bundle
Register the bundle in config/app.php (Symfony) or config/bundles.php (Laravel via Symfony bridge):
Austral\SocialNetworkBundle\AustralSocialNetworkBundle::class => ['all' => true],
Publish Configuration Publish the default config:
php artisan vendor:publish --tag=social-network-config
This generates config/austral/social_network.php.
Database Migrations Run migrations to set up required tables:
php artisan migrate
Key tables include users, posts, comments, likes, and follows.
First Use Case: Basic Post Creation Use the bundle’s services to create a post:
use Austral\SocialNetworkBundle\Service\PostService;
$postService = app(PostService::class);
$post = $postService->createPost(
userId: auth()->id(),
content: "Hello, world!",
mediaIds: [1, 2] // Optional media attachments
);
PostService for CRUD operations:
$postService = app(PostService::class);
$post = $postService->updatePost($postId, ['content' => 'Updated content']);
$posts = $postService->getPosts(
userId: null, // null for global feed
limit: 10,
offset: 0
);
InteractionService:
$interactionService = app(\Austral\SocialNetworkBundle\Service\InteractionService::class);
$interactionService->likePost($postId, auth()->id());
$interactionService->addComment($postId, auth()->id(), "Great post!");
$followService = app(\Austral\SocialNetworkBundle\Service\FollowService::class);
$followService->followUser($userIdToFollow, auth()->id());
MediaService:
$mediaService = app(\Austral\SocialNetworkBundle\Service\MediaService::class);
$mediaId = $mediaService->uploadMedia($filePath, 'post');
config/austral/social_network.php:
'domains' => [
'primary' => 'https://example.com',
'secondary' => 'https://blog.example.com',
],
'supported_languages' => ['en', 'es', 'fr'],
$postService->createPost(..., ['language' => 'es']);
PostCreatedEvent) to extend functionality:
// In a service provider
$this->app->booted(function () {
event(new \Austral\SocialNetworkBundle\Event\PostCreatedEvent($post));
// Trigger custom logic here
});
Service Container Binding
Bind Symfony services to Laravel’s container in AppServiceProvider:
$this->app->bind(\Austral\SocialNetworkBundle\Service\PostService::class,
function ($app) {
return $app->make('austral_social_network.post_service');
}
);
Route Prefixing
Prefix routes in routes/web.php:
Route::prefix('social')->group(function () {
Route::get('/feed', [PostController::class, 'feed']);
});
Blade Templates Use the bundle’s Twig templates or extend them in Laravel Blade:
// Example: Extend the post view
@extends('austral_social_network::post/_partial')
@section('content')
{{ $post->content }}
@endsection
RESTful Endpoints Leverage Symfony’s routing for API endpoints:
# config/routes.yaml
austral_social_network_post:
path: /api/posts
controller: Austral\SocialNetworkBundle\Controller\PostController::index
methods: GET
GraphQL (Optional)
Use austral/graphic-items-bundle to expose GraphQL schemas for posts/comments.
Dependency Conflicts
austral/tools-bundle and other Austral packages. Ensure all dependencies are compatible:
composer why-not austral/tools-bundle
composer.json or use ^3.1 for all Austral bundles.Multi-Domain Routing Issues
TRUSTED_PROXIES in .env:
TRUSTED_PROXIES=192.168.1.0/24
Language Fallback
en. Untranslated content may appear if no fallback is set.config/austral/social_network.php:
'language_fallbacks' => [
'es' => 'en',
'fr' => 'en',
],
Media Upload Limits
php.ini or .env:
UPLOAD_MAX_FILESIZE=10M
POST_MAX_SIZE=10M
Event Listener Overrides
$eventDispatcher->addListener(
\Austral\SocialNetworkBundle\Event\PostCreatedEvent::class,
[$this, 'handlePostCreated'],
100 // High priority
);
Enable Bundle Debugging
Set debug: true in config/austral/social_network.php to log events and queries:
'debug' => env('APP_DEBUG', false),
Query Logging Use Laravel’s query logging to inspect database interactions:
DB::enableQueryLog();
$postService->getPosts(...);
dd(DB::getQueryLog());
Common Errors
ClassNotFoundException: Ensure all Austral bundles are installed and autoloaded.
Fix: Run composer dump-autoload.InvalidArgumentException: Validate input data (e.g., userId must exist).
Fix: Use the bundle’s validators or add custom validation.Custom Post Types
Extend the Post entity by creating a child class:
namespace App\Entity;
use Austral\SocialNetworkBundle\Entity\Post as BasePost;
class CustomPost extends BasePost
{
// Add custom fields/methods
}
Register the new entity in config/austral/social_network.php:
'post_entity' => App\Entity\CustomPost::class,
Custom Notifications Subscribe to events to send notifications (e.g., email/SMS):
$eventDispatcher->addListener(
\Austral\SocialNetworkBundle\Event\UserFollowedEvent::class,
function ($event) {
Notification::send($event->getFollower(), new UserFollowedNotification($event->getFollowed()));
}
);
API Resource Transformers
Override the default API responses using Symfony Serializer or Laravel’s ApiResource:
namespace App\Http\Resources;
use Austral\SocialNetworkBundle\Entity\Post;
use Illuminate\Http\Resources\Json\JsonResource;
class PostResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'content' => $this->content,
'custom_field' => $this->whenLoaded('customField'),
];
}
}
GraphQL Schema Extensions Extend the GraphQL schema using `austral/graphic
How can I help you explore Laravel packages today?