Installation Since the bundle is not yet mature, verify its compatibility with your Laravel version (if applicable) and install via Composer:
composer require desarrolla2/planet-bundle
Note: If this is a Symfony bundle, ensure you’ve added it to config/bundles.php in a Symfony/Laravel-Symfony hybrid project.
Publish Configuration If the bundle includes default config (even if undocumented), publish it:
php artisan vendor:publish --provider="Desarrolla2\PlanetBundle\PlanetBundleServiceProvider"
Check config/planet.php for available settings (if generated).
First Use Case: Basic Planet Feature The README lacks examples, but assume the bundle provides:
Planet, Galaxy)./api/planets).// Example: Fetch planets (if CRUD is exposed)
$planets = \App\Models\Planet::all(); // Hypothetical; verify namespace.
Documentation Gaps
src/ directory for:
PlanetBundleServiceProvider.php (boot/register methods).Resources/config/ (YAML/XML config).Entity/ (Doctrine models, if ORM-based).Model Integration
Planet entity, extend it in Laravel:
class CustomPlanet extends \Desarrolla2\PlanetBundle\Entity\Planet {
// Add custom fields/methods
}
User::morphToMany(Planet::class)).API Resource
php artisan make:resource PlanetResource
// app/Http/Resources/PlanetResource.php
public function toArray($request) {
return [
'name' => $this->name,
'galaxy' => GalaxyResource::make($this->galaxy),
];
}
Route::apiResource('planets', PlanetController::class)->middleware('auth:sanctum');
Frontend Integration
resources/views/vendor/planet/.
@extends('vendor.planet.list')
@section('extra_fields')
<td>{{ $planet->custom_field }}</td>
@endsection
axios.get('/api/planets').then(response => {
response.data.forEach(planet => {
console.log(planet.name);
});
});
Event Listeners
PlanetCreated), listen in EventServiceProvider:
protected $listen = [
\Desarrolla2\PlanetBundle\Events\PlanetCreated::class => [
\App\Listeners\LogPlanetCreation::class,
],
];
Testing
$this->partialMock(PlanetService::class, function ($mock) {
$mock->shouldReceive('findAll')->andReturn([new Planet()]);
});
$response = $this->getJson('/api/planets');
$response->assertStatus(200)->assertJsonStructure([['name']]);
Undocumented Dependencies
make:entity with Laravel’s make:model.ContainerInterface).composer.json for required PHP version (e.g., ^8.0).Namespace Conflicts
Desarrolla2\PlanetBundle\.... Avoid collisions by:
config/app.php:
'aliases' => [
'Planet' => Desarrolla2\PlanetBundle\Facades\Planet::class,
],
Missing Migrations
Planet table, run:
php artisan migrate
src/Resources/migrations/ for custom migrations.Configuration Overrides
config/planet.php:
return [
'default_galaxy' => 'Milky Way',
'api_prefix' => 'api/v1',
];
Event Dispatching
// app/Providers/EventServiceProvider.php
protected $listen = [
\Desarrolla2\PlanetBundle\Events\PlanetEvent::class => [
\App\Listeners\HandlePlanetEvent::class,
],
];
Log Bundle Output Add a listener to debug events:
// app/Listeners/DebugPlanetEvents.php
public function handle(PlanetEvent $event) {
\Log::info('Planet event triggered', $event->toArray());
}
Check Service Container Dump the bundle’s bound services:
$services = app()->getBindings();
dd(array_filter($services, fn($service) => str_contains($service, 'PlanetBundle')));
Override Bundle Classes Use Laravel’s binding overrides:
$this->app->bind(
\Desarrolla2\PlanetBundle\Services\PlanetService::class,
\App\Services\CustomPlanetService::class
);
Custom Repositories Replace the bundle’s repository:
// config/planet.php
'repository' => \App\Repositories\CustomPlanetRepository::class,
Add Fields to Entities
Extend the Planet entity:
namespace App\Entity;
use Desarrolla2\PlanetBundle\Entity\Planet as BasePlanet;
class Planet extends BasePlanet {
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customAttribute;
}
Create Custom Commands Extend the bundle’s commands:
namespace App\Console\Commands;
use Desarrolla2\PlanetBundle\Console\PlanetCommand;
class CustomPlanetCommand extends PlanetCommand {
protected function getOptions() {
return parent::getOptions() + [
['custom', null, InputOption::VALUE_OPTIONAL, 'Custom option'],
];
}
}
Register in AppServiceProvider:
$this->commands([
CustomPlanetCommand::class,
]);
Localization Override translation files:
cp vendor/desarrolla2/planet-bundle/resources/translations/en.json resources/lang/en/planet.json
USAGE.md).php artisan package:discover: If the bundle supports discovery, add it to config/app.php:
'providers' => [
Desarrolla2\PlanetBundle\PlanetBundleServiceProvider::class,
],
---
```markdown
## Final Note
Given the bundle's immaturity, treat it as a "proof of concept." Document your customizations thoroughly and consider wrapping interactions in a service layer for future compatibility.
How can I help you explore Laravel packages today?