Installation
composer require customscripts/client-bundle
Add to config/bundles.php:
return [
// ...
CustomScripts\CSClientBundle\CSClientBundle::class => ['all' => true],
];
Publish Config & Migrations
php artisan vendor:publish --provider="CustomScripts\CSClientBundle\CSClientBundle" --tag="config"
php artisan vendor:publish --provider="CustomScripts\CSClientBundle\CSClientBundle" --tag="migrations"
php artisan migrate
First Use Case Create a client via Tinker:
php artisan tinker
$client = new \CustomScripts\CSClientBundle\Entity\Client();
$client->name = "Acme Corp";
$client->email = "contact@acme.com";
$client->save();
CRUD Operations Use the provided repository:
$clientRepo = $this->get('cs_client.repository');
$clients = $clientRepo->findAll();
$client = $clientRepo->find(1);
Contact Management Attach contacts to clients:
$contact = new \CustomScripts\CSClientBundle\Entity\Contact();
$contact->name = "John Doe";
$contact->email = "john@acme.com";
$contact->client = $client;
$contact->save();
Form Integration Use the bundle’s form types in controllers:
use CustomScripts\CSClientBundle\Form\Type\ClientType;
$form = $this->createForm(ClientType::class, $client);
API Endpoints Leverage FOSRestBundle (if installed) for RESTful routes:
# config/routes.yaml
cs_client:
resource: "@CSClientBundle/Resources/config/routing.yml"
prefix: /api/clients
Event Listeners
Extend functionality via events (e.g., ClientCreatedEvent):
$dispatcher->addListener('cs_client.client.created', function ($event) {
// Send welcome email
});
Custom Fields
Extend the Client or Contact entity:
namespace App\Entity;
use CustomScripts\CSClientBundle\Entity\Client as BaseClient;
class Client extends BaseClient
{
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customField;
}
Validation
Override validation rules in your config/packages/cs_client.yaml:
validation:
Client:
name: "required|min:3"
email: "required|email"
Deprecated Methods
The bundle lacks documentation; check src/Entity/ for deprecated properties (e.g., Client::getClientId() vs. getId()).
No Soft Deletes
Migrations assume hard deletes. Override the delete() method if soft deletes are needed:
use Illuminate\Database\Eloquent\SoftDeletes;
class Client extends BaseClient
{
use SoftDeletes;
protected $dates = ['deleted_at'];
}
Routing Conflicts
The default routes may clash with existing ones. Prefix them in config/routes.yaml:
cs_client:
prefix: /vendor/clients
resource: "@CSClientBundle/Resources/config/routing.yml"
Query Logs Enable Laravel’s query logging to debug repository calls:
\DB::enableQueryLog();
$clientRepo->find(1);
\DB::getQueryLog();
Entity Mapping
Use php artisan doctrine:schema:validate to check for schema mismatches.
Custom Repositories
Bind your own repository in services.yaml:
services:
App\Repository\CustomClientRepository:
arguments: ['@doctrine.orm.entity_manager']
tags: ['cs_client.repository']
Override Templates
Copy Resources/views/ from the bundle to templates/cs_client/ to customize Twig templates.
Add Indexes Extend migrations for performance:
Schema::table('clients', function (Blueprint $table) {
$table->index('email');
$table->index('name');
});
How can I help you explore Laravel packages today?