Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Social Network Bundle Laravel Package

austral/social-network-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    
  2. Publish Configuration Publish the default config:

    php artisan vendor:publish --tag=social-network-config
    

    This generates config/austral/social_network.php.

  3. Database Migrations Run migrations to set up required tables:

    php artisan migrate
    

    Key tables include users, posts, comments, likes, and follows.

  4. 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
    );
    

Implementation Patterns

Core Workflows

1. Post Management

  • Create/Update/Delete Posts Use PostService for CRUD operations:
    $postService = app(PostService::class);
    $post = $postService->updatePost($postId, ['content' => 'Updated content']);
    
  • Fetch Posts Retrieve posts with pagination and filters:
    $posts = $postService->getPosts(
        userId: null, // null for global feed
        limit: 10,
        offset: 0
    );
    

2. Social Interactions

  • Likes/Comments Use InteractionService:
    $interactionService = app(\Austral\SocialNetworkBundle\Service\InteractionService::class);
    $interactionService->likePost($postId, auth()->id());
    $interactionService->addComment($postId, auth()->id(), "Great post!");
    
  • Follow/Unfollow Users
    $followService = app(\Austral\SocialNetworkBundle\Service\FollowService::class);
    $followService->followUser($userIdToFollow, auth()->id());
    

3. Media Handling

  • Attach media (images/videos) to posts via MediaService:
    $mediaService = app(\Austral\SocialNetworkBundle\Service\MediaService::class);
    $mediaId = $mediaService->uploadMedia($filePath, 'post');
    

4. Multi-Domain/Language Support

  • Configure domains and languages in config/austral/social_network.php:
    'domains' => [
        'primary' => 'https://example.com',
        'secondary' => 'https://blog.example.com',
    ],
    'supported_languages' => ['en', 'es', 'fr'],
    
  • Localize content dynamically:
    $postService->createPost(..., ['language' => 'es']);
    

5. Event-Driven Extensions

  • Listen to bundle events (e.g., PostCreatedEvent) to extend functionality:
    // In a service provider
    $this->app->booted(function () {
        event(new \Austral\SocialNetworkBundle\Event\PostCreatedEvent($post));
        // Trigger custom logic here
    });
    

Integration Tips

Laravel-Specific Adaptations

  1. 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');
        }
    );
    
  2. Route Prefixing Prefix routes in routes/web.php:

    Route::prefix('social')->group(function () {
        Route::get('/feed', [PostController::class, 'feed']);
    });
    
  3. 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
    

API Integration

  • 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.


Gotchas and Tips

Pitfalls

  1. Dependency Conflicts

    • The bundle requires austral/tools-bundle and other Austral packages. Ensure all dependencies are compatible:
      composer why-not austral/tools-bundle
      
    • Fix: Align versions in composer.json or use ^3.1 for all Austral bundles.
  2. Multi-Domain Routing Issues

    • If using multiple domains, ensure your web server (Nginx/Apache) routes subdomains correctly to Laravel/Symfony.
    • Fix: Configure TRUSTED_PROXIES in .env:
      TRUSTED_PROXIES=192.168.1.0/24
      
  3. Language Fallback

    • The bundle supports multi-language but defaults to en. Untranslated content may appear if no fallback is set.
    • Fix: Configure fallbacks in config/austral/social_network.php:
      'language_fallbacks' => [
          'es' => 'en',
          'fr' => 'en',
      ],
      
  4. Media Upload Limits

    • Default file upload limits may cause failures for large media. Adjust in php.ini or .env:
      UPLOAD_MAX_FILESIZE=10M
      POST_MAX_SIZE=10M
      
  5. Event Listener Overrides

    • Custom event listeners may conflict with the bundle’s default behavior. Use priority flags:
      $eventDispatcher->addListener(
          \Austral\SocialNetworkBundle\Event\PostCreatedEvent::class,
          [$this, 'handlePostCreated'],
          100 // High priority
      );
      

Debugging Tips

  1. Enable Bundle Debugging Set debug: true in config/austral/social_network.php to log events and queries:

    'debug' => env('APP_DEBUG', false),
    
  2. Query Logging Use Laravel’s query logging to inspect database interactions:

    DB::enableQueryLog();
    $postService->getPosts(...);
    dd(DB::getQueryLog());
    
  3. 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.

Extension Points

  1. 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,
    
  2. 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()));
        }
    );
    
  3. 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'),
            ];
        }
    }
    
  4. GraphQL Schema Extensions Extend the GraphQL schema using `austral/graphic

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor