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

Users Profile User Laravel Package

baks-dev/users-profile-user

Модуль профилей пользователя для PHP 8.4+: установка через Composer, установка ресурсов (baks:assets:install), обновление схемы БД через Doctrine migrations, тестирование PHPUnit (group=users-profile-user).

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to First Use

  1. Install the Package

    composer require baks-dev/users-profile-user
    

    Ensure your composer.json specifies PHP 8.4+ and Laravel 10+ constraints.

  2. Publish Configuration and Assets

    php artisan vendor:publish --provider="BaksDev\UsersProfileUser\UsersProfileUserServiceProvider"
    php artisan baks:assets:install
    

    Verify the config/users-profile-user.php and asset files (CSS/JS) are published to config/ and public/ respectively.

  3. Run Migrations

    php artisan doctrine:migrations:diff
    php artisan doctrine:migrations:migrate
    

    Review the generated migration for conflicts with existing users table or custom profile schemas.

  4. Test the Profile System

    • For Blade: Visit /profile (or the configured route) after logging in.
    • For API: Send a GET request to /api/profile (if API routes are included).
    • Run the provided PHPUnit tests:
      php artisan test --group=users-profile-user
      
  5. First Customization Extend the default profile fields by publishing the config and modifying:

    // config/users-profile-user.php
    'fields' => [
        'name' => 'string|max:255',
        'bio' => 'string|nullable',
        'location' => 'string|nullable',
        // Add custom fields (e.g., 'portfolio_url')
    ],
    

Implementation Patterns

Core Workflows

1. Profile CRUD Operations

  • Model Interaction: The package likely provides a Profile model (e.g., BaksDev\UsersProfileUser\Models\Profile) linked to the users table via user_id. Use Eloquent for operations:
    use BaksDev\UsersProfileUser\Models\Profile;
    
    // Get current user's profile
    $profile = Profile::where('user_id', auth()->id())->firstOrFail();
    
    // Update profile
    $profile->update([
        'bio' => 'Updated bio',
        'location' => 'New York',
    ]);
    
  • Validation: Leverage Laravel’s validation with custom rules from the config:
    use Illuminate\Support\Facades\Validator;
    
    $validator = Validator::make($request->all(), [
        'bio' => 'string|max:500',
        'location' => 'string|nullable',
    ], [
        'bio.max' => 'Bio must be less than 500 characters.',
    ]);
    

2. Asset Handling (Profile Images/Avatars)

  • Uploads: The baks:assets:install command likely sets up storage paths. Use Laravel’s Store facade or custom logic:
    use Illuminate\Support\Facades\Storage;
    
    $path = $request->file('avatar')->store('profile_avatars', 'public');
    $profile->update(['avatar_path' => $path]);
    
  • URL Generation:
    $avatarUrl = Storage::url($profile->avatar_path);
    

3. Event-Driven Extensions

  • Listen for Profile Events: The package may dispatch events like ProfileUpdated. Listen in EventServiceProvider:
    protected $listen = [
        \BaksDev\UsersProfileUser\Events\ProfileUpdated::class => [
            \App\Listeners\SendProfileUpdateNotification::class,
        ],
    ];
    
  • Custom Events: Extend the package’s event system by creating your own listeners for post-update actions (e.g., analytics, notifications).

4. API Integration

  • REST/JSON:API Endpoints: The package may include routes like /api/profile. Test with:
    php artisan route:list | grep profile
    
    Example API request:
    curl -X GET http://your-app.test/api/profile \
         -H "Authorization: Bearer {token}"
    
  • Resource Controllers: Extend the default controller or create a custom one:
    namespace App\Http\Controllers;
    
    use BaksDev\UsersProfileUser\Http\Controllers\ProfileController as BaseProfileController;
    
    class ProfileController extends BaseProfileController {
        public function update(Request $request) {
            // Custom logic before/after update
            return parent::update($request);
        }
    }
    

5. Frontend Integration

  • Blade Templates: Include the package’s assets and use provided Blade components:
    <!-- resources/views/profile.blade.php -->
    @include('users-profile-user::profile.form')
    <img src="{{ $profile->avatarUrl() }}" alt="Profile Avatar">
    
  • Dynamic Fields: Render custom fields from the config:
    @foreach(config('users-profile-user.fields') as $field => $rules)
        <div>
            <label for="{{ $field }}">{{ ucfirst($field) }}</label>
            <input type="text" name="{{ $field }}" id="{{ $field }}">
        </div>
    @endforeach
    

6. Testing

  • Unit Tests: Test model interactions and validation:
    public function test_profile_update_validation()
    {
        $profile = Profile::factory()->create();
        $response = $this->put("/profile/{$profile->id}", [
            'bio' => str_repeat('x', 600), // Exceed max length
        ]);
        $response->assertSessionHasErrors('bio');
    }
    
  • Feature Tests: Test routes and API endpoints:
    public function test_profile_api_endpoint()
    {
        $response = $this->actingAs(User::factory()->create())
                         ->get('/api/profile');
        $response->assertStatus(200);
    }
    

Integration Tips

With Laravel Auth

  • Extend User Model: If the package uses a separate Profile model, eager-load it in your User model:

    // app/Models/User.php
    public function profile()
    {
        return $this->hasOne(\BaksDev\UsersProfileUser\Models\Profile::class);
    }
    

    Access via:

    auth()->user()->profile->bio;
    
  • Auth Middleware: Protect profile routes with Laravel’s built-in middleware:

    Route::middleware(['auth'])->group(function () {
        Route::get('/profile', [ProfileController::class, 'show']);
    });
    

With Sanctum/Passport

  • API Authentication: Ensure the package’s API routes are protected by Sanctum/Passport:
    Route::middleware('auth:sanctum')->group(function () {
        Route::apiResource('profile', \BaksDev\UsersProfileUser\Http\Controllers\ProfileController::class);
    });
    

With Spatie Media Library

  • Media Handling: If the package supports profile images, integrate with Spatie for advanced features:
    use Spatie\MediaLibrary\HasMedia;
    use Spatie\MediaLibrary\InteractsWithMedia;
    
    class Profile extends \BaksDev\UsersProfileUser\Models\Profile implements HasMedia
    {
        use InteractsWithMedia;
    }
    

With Laravel Nova

  • Admin Panel: Create a Nova resource for profile management:
    php artisan nova:resource ProfileResource --model=BaksDev\UsersProfileUser\Models\Profile
    
    Customize fields in ProfileResource.php:
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('Bio')->onlyOnDetail(),
            // Add custom fields
        ];
    }
    

With Laravel Horizon

  • Queued Jobs: Offload profile updates or image processing to queues:
    $profile->update([
        'bio' => $request->bio,
    ]);
    
    UpdateProfileNotification::dispatch($profile)->delay(now()->addSeconds(10));
    

With Laravel Scout

  • Search: Index profile data for search:
    use Laravel\Scout\Searchable;
    
    class Profile extends \BaksDev\UsersProfileUser\Models\Profile
    {
        use Searchable;
    
        public function toSearchableArray()
        {
            return [
                'bio' => $this->bio,
                'location' => $this->location,
            ];
        }
    }
    

Gotchas and Tips

Pitfalls

1. Database Schema Conflicts

  • Issue: The package may assume a profiles table or extend the users table in ways conflicting with your existing schema.
  • Solution:
    • Run doctrine:migrations:diff first to preview changes.
    • Manually merge migrations if the package uses a non-standard table name (e.g., user_profiles vs. profiles).
    • Example conflict resolution:
      // In your migration
      Schema::table('user_profiles', function (Blueprint $table) {
          $table->string
      
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.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui