dovstone/symfony-blog-admin-bundle-mongodb-based
Installation:
composer require dovstone/symfony-blog-admin-bundle-mongodb-based
Note: Since this is a Symfony bundle, ensure your Laravel project can integrate Symfony components (e.g., via symfony/http-kernel or symfony/dependency-injection).
Configuration:
php artisan vendor:publish --provider="Dovstone\BlogAdminBundle\DovstoneBlogAdminBundle"
.env with MongoDB credentials:
MONGO_DB_HOST=your_mongodb_host
MONGO_DB_PORT=27017
MONGO_DB_NAME=your_db_name
MONGO_DB_USER=your_username
MONGO_DB_PASSWORD=your_password
First Use Case:
config/app.php under extra.bundles (Symfony-style):
'bundles' => [
Dovstone\BlogAdminBundle\DovstoneBlogAdminBundle::class => ['all' => true],
],
config/app.php:
'providers' => [
// ...
Dovstone\BlogAdminBundle\ServiceProvider::class,
],
Basic Route:
Resources/config/routing.yml (Symfony) or routes/blog_admin.php (if Laravel-compatible) for predefined routes. Example:
// In routes/web.php (if Laravel routes are exposed)
use Dovstone\BlogAdminBundle\Http\Controllers\BlogController;
Route::resource('blog', BlogController::class);
Test Connection:
php artisan tinker
>>> \Dovstone\BlogAdminBundle\Repository\BlogRepository::find(1);
Repository Pattern:
$blog = $this->blogRepository->findBy(['title' => 'Laravel Tips']);
class BlogService {
public function __construct(private BlogRepository $repository) {}
public function getPublishedPosts() {
return $this->repository->createQueryBuilder()
->field('published')->equals(true)
->getQuery()
->execute();
}
}
Event-Driven Workflows:
// In EventServiceProvider
protected $listen = [
\Dovstone\BlogAdminBundle\Event\BlogCreatedEvent::class => [
\App\Listeners\SendBlogWelcomeEmail::class,
],
];
Illuminate\Events\Dispatcher) to bridge gaps.Form Handling:
Request validation:
use Symfony\Component\Form\FormFactoryInterface;
class BlogController {
public function store(Request $request, FormFactoryInterface $formFactory) {
$form = $formFactory->createNamedBuilder('blog', BlogType::class)
->getForm();
$form->submit($request->all());
if ($form->isValid()) {
$blog = $form->getData();
// Save via repository
}
}
}
Middleware Integration:
app/Http/Kernel.php:
protected $middlewareGroups = [
'web' => [
// ...
\Dovstone\BlogAdminBundle\Http\Middleware\CheckBlogPermissions::class,
],
];
CRUD Operations:
isDeleted flag (common in MongoDB).Authentication/Authorization:
Authenticatable to integrate Symfony’s security component:
use Symfony\Component\Security\Core\User\UserInterface;
class BlogUser extends User implements UserInterface {
// Implement Symfony's UserInterface
}
API Integration:
Route::apiResource('blogs', BlogApiController::class);
Resource classes to shape responses:
public function toArray($request) {
return [
'title' => $this->title,
'content' => Str::limit($this->content, 200),
];
}
MongoDB Schema:
class Blog extends Model {
protected $connection = 'mongodb';
protected $collection = 'blogs';
protected $guarded = [];
}
Service Container:
$this->app->bind(
\Dovstone\BlogAdminBundle\Service\BlogService::class,
\App\Services\LaravelBlogService::class
);
Testing:
$this->mock(\Dovstone\BlogAdminBundle\Repository\BlogRepository::class)
->shouldReceive('findBy')
->andReturn([$mockBlog]);
Asset Management:
php artisan vendor:publish --tag=blog-admin-assets
Symfony vs. Laravel Incompatibility:
Kernel, Container, and HttpFoundation. Laravel’s Illuminate\Foundation\Application may conflict.class SymfonyToLaravelAdapter {
public function __construct(private ContainerInterface $symfonyContainer) {}
public function getBlogRepository() {
return $this->symfonyContainer->get('dovstone_blog_admin.repository.blog');
}
}
MongoDB Connection:
config/database.php won’t override them.config/services.php:
'dovstone_blog_admin' => [
'mongo_db' => [
'host' => env('MONGO_DB_HOST', 'localhost'),
'port' => env('MONGO_DB_PORT', 27017),
],
],
Routing Conflicts:
routing.yml may clash with Laravel’s routes.Route::prefix('admin')->group(function () {
// Include Symfony routes here
});
Event Dispatcher:
EventDispatcher won’t work with Laravel’s Dispatcher.class EventDispatcherBridge {
public function __construct(
private EventDispatcherInterface $symfonyDispatcher,
private Dispatcher $laravelDispatcher
) {}
public function dispatch(string $eventName, $event) {
$this->symfonyDispatcher->dispatch($eventName, $event);
$this->laravelDispatcher->dispatch($eventName, $event);
}
}
Form Validation:
Validator. Laravel’s FormRequest validation may conflict.First Release Risks:
Symfony Debug Dump:
dump() from symfony/var-dumper:
use Symfony\Component\VarDumper\VarDumper;
VarDumper::dump($variable);
MongoDB Queries:
.env:
MONGO_LOG_LEVEL=debug
Container Binding Errors:
php artisan container:inspect Dovstone\BlogAdminBundle\Service\
How can I help you explore Laravel packages today?