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

My Form Laravel Package

niharb/my-form

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require niharb/my-form:@dev
    php artisan migrate
    

    This creates a package_users table with a default admin user (adminuser, admin@example.com, secret).

  2. Configure Auth: Update config/auth.php with the provided providers and guards for package_users and package_web.

  3. First Use Case:

    • Access the registration form at /my-form/register.
    • Access the login form at /my-form/login.
    • Test authentication by logging in with the default admin credentials.

Where to Look First

  • Package Documentation: Check the GitHub README for updates or missing details.
  • Migrations: Inspect database/migrations/ for the package_users table structure.
  • Routes: Verify /my-form/register and /my-form/login are registered in routes/web.php (likely auto-loaded by the package).

Implementation Patterns

Usage Patterns

  1. Form Integration:

    • Use the package’s built-in Blade views (if provided) or extend them:
      @extends('my-form::register')  <!-- Hypothetical view path -->
      
    • Override views by publishing them:
      php artisan vendor:publish --tag=my-form-views
      
  2. Authentication Workflow:

    • Registration: Submit data to /my-form/register (POST). The package handles validation and user creation.
    • Login: Submit credentials to /my-form/login (POST). Redirects to /my-form/dashboard (or a custom route) on success.
    • Logout: Use Auth::guard('package_web')->logout() in controllers or leverage the package’s logout route.
  3. Customization:

    • Validation Rules: Extend the package’s validation logic by overriding its RegisterController or LoginController (if exposed).
    • Middleware: Protect routes with auth:package_web:
      Route::middleware(['auth:package_web'])->group(function () {
          // Protected routes
      });
      
  4. Database Interactions:

    • Access the PackageUser model directly:
      use Niharb\MyForm\Models\PackageUser;
      $user = PackageUser::find(1);
      
    • Extend the model or create policies for authorization.

Workflows

  1. User Onboarding:

    • Redirect unauthenticated users to /my-form/register.
    • Use the package’s seeder to pre-populate test users:
      php artisan db:seed --class=MyFormSeeder
      
  2. API Integration:

    • Use the api guard (configured in auth.php) for token-based auth alongside the package’s session guard.
    • Example API route:
      Route::middleware('auth:api')->get('/user', function () {
          return Auth::user(); // Uses default Laravel user model
      });
      
  3. Multi-Auth Systems:

    • Keep the package’s auth separate from Laravel’s default users table by using guards:
      Auth::guard('package_web')->check(); // Check package auth
      Auth::check(); // Check default auth
      

Integration Tips

  • Blade Views: If the package lacks views, create custom ones in resources/views/vendor/my-form/ and extend the package’s logic.
  • Testing: Use Laravel’s actingAs with the PackageUser model:
    $this->actingAs(PackageUser::find(1), 'package_web');
    
  • Localization: Override language files by publishing them:
    php artisan vendor:publish --tag=my-form-lang
    

Gotchas and Tips

Pitfalls

  1. Default Admin Credentials:

    • The package seeds a default admin user (adminuser/secret). Change these in production or disable the seeder:
      // In DatabaseSeeder.php
      $this->call([
          // Comment out MyFormSeeder::class
      ]);
      
  2. Route Conflicts:

    • The package’s /my-form/* routes may conflict with existing routes. Use route model binding or middleware to isolate them.
  3. Model Naming:

    • The PackageUser model is non-standard. Avoid confusion by aliasing it:
      use Niharb\MyForm\Models\PackageUser as MyFormUser;
      
  4. Migration Overwrites:

    • Running php artisan migrate:fresh may reset the package_users table. Back up data or use --seed carefully.
  5. Lack of Documentation:

    • The package’s maturity is low (0 stars, no dependents). Assume undocumented behavior (e.g., no public API for custom controllers).

Debugging

  1. Auth Guard Issues:

    • Verify the package_web guard is correctly configured in auth.php. Test with:
      dd(Auth::guard('package_web')->check());
      
  2. Form Validation Errors:

    • Check the package’s validation rules (likely in Rules classes). Override them by extending the package’s controllers:
      // app/Http/Controllers/MyForm/RegisterController.php
      namespace App\Http\Controllers\MyForm;
      use Niharb\MyForm\Http\Controllers\RegisterController as BaseRegisterController;
      
      class RegisterController extends BaseRegisterController {
          protected function validator(array $data) {
              // Custom validation logic
          }
      }
      
  3. Session/Token Conflicts:

    • If using both package_web (session) and api (token) guards, ensure cookies/sessions are not shared unintentionally.

Config Quirks

  1. Guard Naming:

    • The package_web guard name is arbitrary. Rename it in auth.php if needed (e.g., myform_web).
  2. Seeder Timing:

    • The seeder runs during php artisan migrate. Disable it if you manage users manually:
      // config/my-form.php (if exists)
      'seed' => false,
      
  3. Package Updates:

    • The @dev tag suggests instability. Pin versions in composer.json:
      "niharb/my-form": "1.0.0"
      

Extension Points

  1. Custom Controllers:

    • Override the package’s controllers by binding them in AppServiceProvider:
      public function register() {
          $this->app->bind(
              \Niharb\MyForm\Http\Controllers\RegisterController::class,
              \App\Http\Controllers\MyForm\RegisterController::class
          );
      }
      
  2. Event Listeners:

    • Listen for package events (if any) or create your own:
      // Example: Listen for registration
      event(new \Niharb\MyForm\Events\UserRegistered($user));
      
  3. API Endpoints:

    • Extend the package’s auth logic for API routes by creating a custom guard or middleware:
      Route::middleware(['auth:package_web', 'api'])->get('/protected-api');
      
  4. Database Observers:

    • Attach observers to PackageUser for custom logic:
      PackageUser::observe(MyFormUserObserver::class);
      
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui