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

Ti Ext User Laravel Package

tastyigniter/ti-ext-user

Core TastyIgniter extension for user management: administer customers and staff, authentication and registration (optional email verification), password resets, and admin impersonation. Includes automation events for customer registration and attribute conditions.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require tastyigniter/ti-ext-user
    php artisan igniter:up
    

    Run migrations to set up the required tables (users, customers, user_roles, etc.).

  2. Publish Config:

    php artisan vendor:publish --provider="TastyIgniter\TiExtUser\Providers\TiExtUserServiceProvider"
    

    Configure email settings, registration defaults, and permissions in config/ti-ext-user.php.

  3. First Use Case:

    • Enable Registration: Add the registration form to your frontend using the provided Blade components:
      @include('ti-ext-user::auth.register')
      
    • Test Authentication: Use the default login routes (/login, /register) or integrate with your frontend:
      use TastyIgniter\TiExtUser\Facades\Auth;
      
      if (Auth::check()) {
          // User is logged in
      }
      
  4. Admin Access:

    • Log in to the TastyIgniter admin panel (/admin) and navigate to Users > Customers or Users > Staff to manage users via the built-in UI.
  5. Impersonation (Admin Feature):

    • Admins can impersonate users for debugging:
      use TastyIgniter\TiExtUser\Facades\Auth;
      
      $customer = \App\Models\Customer::find(1);
      Auth::impersonate($customer);
      

Where to Look First

  • Documentation: TastyIgniter Docs for setup and API references.
  • Blade Components: /resources/views/vendor/ti-ext-user/ for reusable frontend templates.
  • Events: /src/Events/ for extending user lifecycle hooks (e.g., UserRegistered, UserLoggedIn).
  • Middleware: /src/Http/Middleware/ for custom auth logic (e.g., AdminAuth, CustomerAuth).

Implementation Patterns

Usage Patterns

1. Frontend Integration

  • Registration/Login Forms: Use the provided Blade components in your frontend:
    @auth
        <p>Welcome, {{ Auth::user()->name }}!</p>
    @else
        @include('ti-ext-user::auth.login')
    @endauth
    
  • Custom Validation: Extend the default CustomerRequest or UserRequest:
    namespace App\Http\Requests;
    
    use TastyIgniter\TiExtUser\Http\Requests\CustomerRequest as BaseCustomerRequest;
    
    class CustomerRequest extends BaseCustomerRequest
    {
        public function rules()
        {
            return array_merge(parent::rules(), [
                'custom_field' => 'required|string',
            ]);
        }
    }
    

2. Backend Workflows

  • User Creation:
    use TastyIgniter\TiExtUser\Models\Customer;
    
    $customer = Customer::create([
        'email' => 'customer@example.com',
        'password' => bcrypt('password123'),
        'first_name' => 'John',
        'last_name' => 'Doe',
        'status' => true, // Active/inactive
    ]);
    
  • Role Assignment:
    $customer->assignRole('customer'); // Predefined roles: 'customer', 'staff', 'admin'
    

3. Impersonation

  • Impersonate a User (Admin):
    use TastyIgniter\TiExtUser\Facades\Auth;
    
    $user = \App\Models\User::find(1);
    Auth::impersonate($user);
    
  • Exit Impersonation:
    Auth::endImpersonation();
    

4. Events and Listeners

  • Listen for Registration:
    use TastyIgniter\TiExtUser\Events\UserRegistered;
    
    UserRegistered::listen(function (UserRegistered $event) {
        // Send welcome email or trigger automation
        \Log::info("New user registered: {$event->user->email}");
    });
    
  • Custom Conditions: Use the can() method for authorization:
    if (Auth::user()->can('manage_orders')) {
        // Grant access
    }
    

5. API Integration

  • API Authentication: Use Laravel’s built-in API auth (e.g., Sanctum or Passport) with the package’s models:
    use TastyIgniter\TiExtUser\Models\Customer;
    
    $customer = Customer::where('email', $request->email)->first();
    if ($customer && Hash::check($request->password, $customer->password)) {
        $token = $customer->createToken('auth_token')->plainTextToken;
        return response()->json(['token' => $token]);
    }
    

Workflows

Customer Onboarding

  1. User submits registration form (/register).
  2. UserRegistered event fires → trigger welcome email/SMS.
  3. Admin reviews user in /admin/users/customers (if email verification is enabled).
  4. User logs in and is redirected to a dashboard with account links (e.g., orders, profile).

Staff Management

  1. Admin creates a staff account via /admin/users/staff.
  2. Staff logs in and accesses a restricted dashboard (e.g., /staff/orders).
  3. Admins use impersonation to debug staff issues:
    Auth::impersonate($staffUser);
    // Debug staff session
    Auth::endImpersonation();
    

Password Reset

  1. User requests reset via /forgot-password.
  2. PasswordReset event fires → send reset link.
  3. User clicks link and submits new password (/reset-password).

Integration Tips

  • Customize Emails: Override default mail templates in /resources/views/vendor/ti-ext-user/emails/. Example: Copy resources/views/vendor/ti-ext-user/emails/welcome.blade.php to your project’s resources/views/ti-ext-user/emails/ and modify.

  • Extend Models: Add fields to the users or customers table via migrations, then extend the models:

    namespace App\Models;
    
    use TastyIgniter\TiExtUser\Models\Customer as BaseCustomer;
    
    class Customer extends BaseCustomer
    {
        protected $casts = array_merge(BaseCustomer::$casts, [
            'loyalty_points' => 'integer',
        ]);
    }
    
  • Override Auth Logic: Publish and modify the AuthServiceProvider:

    php artisan vendor:publish --tag=ti-ext-user-auth
    

    Then extend the boot() method in app/Providers/AuthServiceProvider.php.

  • Localization: The package supports localization. Publish translations:

    php artisan vendor:publish --tag=ti-ext-user-lang
    

    Then add your language files to resources/lang/.


Gotchas and Tips

Pitfalls

  1. Migration Conflicts:

    • Running php artisan igniter:up after custom migrations may cause conflicts. Backup your database or use --force cautiously.
    • Fix: Review the package’s migration files (/database/migrations/) before running them.
  2. Impersonation Session Issues:

    • Impersonation may not work if the admin is already logged in as a customer. Clear the session or use:
      Auth::logoutOtherDevices($request->password);
      Auth::impersonate($user);
      
    • Tip: Test impersonation in a fresh session or use Auth::onceUsingId($user->id) for one-time impersonation.
  3. Email Verification Edge Cases:

    • If email verification fails silently, check the failed_jobs table or enable debug logging:
      \Illuminate\Support\Facades\Log::channel('single')->debug('Email verification failed');
      
    • Fix: Ensure your .env has correct mail settings (MAIL_MAILER=smtp, MAIL_FROM_ADDRESS).
  4. Role/Permission Caching:

    • Permissions may not update immediately due to caching. Clear the cache after assigning roles:
      php artisan cache:clear
      
    • Tip: Use Auth::user()->refreshPermissions() in your code if needed.
  5. Password Reset Token Expiry:

    • Default token expiry is 60 minutes. Customize in config/ti-ext-user.php:
      'password_reset' => [
          'expire' => 60, // minutes
      ],
      
  6. Concurrent Impersonation:

    • Impersonating a user who is already logged in may cause conflicts. Use Auth::onceUsingId() for temporary impersonation:
      Auth::onceUsingId($user->id, function () {
          // Perform actions as the user
      });
      

Debugging

  1. Event Debugging:
    • Listen for events in AppServiceProvider to debug:
      public function boot()
      {
          \T
      
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor