crisistextline/user-profile-bundle
Installation
Run composer require crisistextline/user-profile-bundle in your Laravel project (note: this bundle is Symfony-based, but can be adapted for Laravel via bridge packages like symfony/console or symfony/dependency-injection if needed).
Bundle Registration
Add the bundle to your config/app.php under providers (Laravel) or AppKernel.php (Symfony):
'providers' => [
// ...
CrisisTextLine\UserProfileBundle\CrisisTextLineUserProfileBundle::class,
],
Routing
Define routes in routes/web.php (Laravel) or routing.yml (Symfony):
Route::prefix('/')->group(function () {
Route::resource('user-profile', 'CrisisTextLine\UserProfileBundle\Controller\UserProfileController');
});
User Entity Configuration
Configure the bundle to resolve your Laravel User model (e.g., App\Models\User) in config/services.php:
'user-profile' => [
'entity' => App\Models\User::class,
],
First Use Case
Trigger the bundle’s default controller actions (e.g., GET /user-profile) to verify CRUD operations for user profiles.
Profile Management
Extend the bundle’s UserProfileController to handle custom profile fields (e.g., crisis-related metadata):
// app/Http/Controllers/UserProfileController.php
namespace App\Http\Controllers;
use CrisisTextLine\UserProfileBundle\Controller\UserProfileController as BaseController;
class UserProfileController extends BaseController
{
public function show($id)
{
$profile = $this->getUserProfile($id);
return view('user.profile', compact('profile'));
}
}
Form Integration
Use the bundle’s form types (if available) or create custom forms in Laravel’s Form facade:
use Illuminate\Support\Facades\Form;
$form = Form::model($user, [
'method' => 'PUT',
'url' => route('user-profile.update', $user->id)
]);
Event Listeners
Hook into user profile events (e.g., profile.created) via Laravel’s event system:
// app/Providers/EventServiceProvider.php
protected $listen = [
'CrisisTextLine\UserProfileBundle\Events\ProfileCreated' => [
'App\Listeners\LogProfileActivity',
],
];
API Integration Expose profile endpoints via Laravel’s API resources:
Route::apiResource('api/profiles', 'Api\UserProfileController');
User model to include crisis-related fields (e.g., crisis_level, support_history).$validator = Validator::make($request->all(), [
'crisis_level' => 'required|integer|between:1,5',
]);
Route::middleware(['auth'])->group(function () {
Route::resource('user-profile', 'UserProfileController');
});
laravel-doctrine/orm to bridge Laravel’s Eloquent with Doctrine entities.Validator, Form, or Serializer components via Laravel’s service container.HttpTests to test profile routes:
$response = $this->get('/user-profile/1');
$response->assertStatus(200);
Symfony vs. Laravel Mismatch
Kernel, DependencyInjection, and Doctrine setup. Use bridge packages (e.g., symfony/console-bridge) or rewrite controllers/services for Laravel.Outdated Dependencies
symfony/*, doctrine/*).Hardcoded Routes/Config
/) and config keys (crisis_text_line_user_profile).boot() or register() methods.No Eloquent Support
// app/Repositories/UserProfileRepository.php
class UserProfileRepository {
public function find($id) {
return User::find($id);
}
}
php artisan route:list to check for overlaps with Laravel’s default routes.php artisan cache:clear) and config (php artisan config:clear) after bundle changes.user-profile.entity config points to a valid Laravel model:
// config/services.php
'user-profile' => [
'entity' => App\Models\User::class, // Must exist
],
Custom Controllers Replace the bundle’s controller with a Laravel-specific one:
// app/Http/Controllers/UserProfileController.php
class UserProfileController extends Controller {
public function index() {
return User::all();
}
}
Profile Extensions
Add crisis-specific fields to the User model:
// app/Models/User.php
class User extends Authenticatable {
protected $fillable = ['name', 'crisis_level', 'last_contacted_at'];
}
API Resources Format profile data for APIs:
// app/Http/Resources/UserProfileResource.php
class UserProfileResource extends JsonResource {
public function toArray($request) {
return [
'id' => $this->id,
'crisis_level' => $this->crisis_level,
'created_at' => $this->created_at->toDateTimeString(),
];
}
}
Testing
Mock the bundle’s services in Laravel’s AppServiceProvider:
public function register() {
$this->app->bind(
'crisis_text_line.user_profile.manager',
function () {
return new \App\Services\UserProfileManager();
}
);
}
Legacy Workarounds
For Symfony-specific features (e.g., Twig templates), use Laravel’s Blade or Symfony\Bridge\Twig\Extension\RoutingExtension:
// config/app.php
'view' => [
'composer' => [
'App\View\Composers\ProfileComposer',
],
],
How can I help you explore Laravel packages today?