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

News Bundle Laravel Package

dywee/news-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dywee/news-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        Dywee\NewsBundle\DyweeNewsBundle::class => ['all' => true],
    ];
    
  2. Routing Add to config/routes.yaml:

    dywee_news:
        resource: "@DyweeNewsBundle/Controller/"
        type: annotation
        prefix: /news
    
  3. First Use Case

    • Create a News Item: Use the admin interface (if DyweeCoreBundle is installed) or manually create a News entity via:
      $news = new \Dywee\NewsBundle\Entity\News();
      $news->setTitle('My News');
      $news->setContent('Content here...');
      $news->setPublishedAt(new \DateTime());
      $em->persist($news);
      $em->flush();
      
    • Display News: Fetch via repository:
      $news = $em->getRepository(\Dywee\NewsBundle\Entity\News::class)
          ->findBy([], ['publishedAt' => 'DESC']);
      

Implementation Patterns

Core Workflows

  1. Admin Integration

    • If using DyweeCoreBundle, leverage its CRUD admin generator for News entities. Configure in config/admin.yml:
      dywee_core:
          admin:
              news:
                  entity: Dywee\NewsBundle\Entity\News
                  menu: News
      
  2. Frontend Display

    • Twig Templates: Use dywee_news namespace in templates:
      {% for news in dywee_news_list %}
          <h2>{{ news.title }}</h2>
          <p>{{ news.content|truncate(200) }}</p>
      {% endfor %}
      
    • Controller Integration: Fetch news via service:
      $newsService = $this->get('dywee_news.service.news');
      $latestNews = $newsService->getLatest(5);
      
  3. Custom Queries

    • Extend the repository or use DQL:
      $publishedNews = $em->createQuery(
          'SELECT n FROM DyweeNewsBundle:News n WHERE n.publishedAt <= :now ORDER BY n.publishedAt DESC'
      )->setParameter('now', new \DateTime())
       ->getResult();
      
  4. Event Listeners

    • Subscribe to NewsEvents (if defined) for post-save logic:
      // config/services.yaml
      Dywee\NewsBundle\EventListener\NewsListener:
          tags:
              - { name: kernel.event_listener, event: dywee.news.post_save, method: onNewsSaved }
      

Gotchas and Tips

Pitfalls

  1. Missing DyweeCoreBundle

    • The bundle assumes DyweeCoreBundle for admin features. Without it, you’ll need to manually handle CRUD operations or disable admin routes in routing.yml.
  2. Entity Configuration

    • The News entity may lack annotations (e.g., @ORM\Table). Verify your Entity/News.php includes:
      use Doctrine\ORM\Mapping as ORM;
      /**
       * @ORM\Entity(repositoryClass="Dywee\NewsBundle\Repository\NewsRepository")
       * @ORM\Table(name="news")
       */
      
  3. Routing Conflicts

    • The default prefix: / in routing may clash with other bundles. Use a unique prefix (e.g., /news) and clear cache:
      php bin/console cache:clear
      
  4. Translation Support

    • If using translations, ensure News entity fields are marked translatable (e.g., title, content) and configure liip/translate-bundle separately.

Debugging Tips

  • Check Routes: Verify routes are loaded:
    php bin/console debug:router | grep dywee_news
    
  • Entity Mapping: Validate Doctrine mappings:
    php bin/console doctrine:schema:validate
    
  • Service Availability: Confirm the NewsService is registered:
    php bin/console debug:container dywee_news.service.news
    

Extension Points

  1. Custom Fields

    • Extend the News entity:
      /**
       * @ORM\Column(type="string", nullable=true)
       */
      private $customField;
      
    • Update migrations and admin config accordingly.
  2. Validation

    • Add constraints to the News entity:
      use Symfony\Component\Validator\Constraints as Assert;
      /**
       * @Assert\NotBlank
       */
      private $title;
      
  3. API Integration

    • Expose news via API Platform or FOSRestBundle by creating a NewsOutput DTO or serializer group:
      # config/serializer/Entity.News.yaml
      Dywee\NewsBundle\Entity\News:
          attributes:
              publishedAt:
                  groups: [api]
      
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.
ilhamsyabani/laravel-volt-starter
thethunderturner/filament-latex
ghostcompiler/laravel-querybuilder
webrek/laravel-telescope-mongodb
anousss007/blatui
zatona-eg/zatona-eg-api
cocosmos/filament-sticky-save-bar
patrickbussmann/oauth2-apple
3brs/enterprise-security-bundle
anousss007/vigilance
supportpal/eloquent-model
ardenexal/fhir-models
laravel-at/laravel-image-sanitize
romalytar/yammi-audit-log-laravel
ardenexal/fhir-validation
arshaviras/weather-widget
laravel-chronicle/core
sunchayn/nimbus
daikazu/eloquent-salesforce-objects
unseen-codes/chat