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).
Configure Auth:
Update config/auth.php with the provided providers and guards for package_users and package_web.
First Use Case:
/my-form/register./my-form/login.database/migrations/ for the package_users table structure./my-form/register and /my-form/login are registered in routes/web.php (likely auto-loaded by the package).Form Integration:
@extends('my-form::register') <!-- Hypothetical view path -->
php artisan vendor:publish --tag=my-form-views
Authentication Workflow:
/my-form/register (POST). The package handles validation and user creation./my-form/login (POST). Redirects to /my-form/dashboard (or a custom route) on success.Auth::guard('package_web')->logout() in controllers or leverage the package’s logout route.Customization:
RegisterController or LoginController (if exposed).auth:package_web:
Route::middleware(['auth:package_web'])->group(function () {
// Protected routes
});
Database Interactions:
PackageUser model directly:
use Niharb\MyForm\Models\PackageUser;
$user = PackageUser::find(1);
User Onboarding:
/my-form/register.php artisan db:seed --class=MyFormSeeder
API Integration:
api guard (configured in auth.php) for token-based auth alongside the package’s session guard.Route::middleware('auth:api')->get('/user', function () {
return Auth::user(); // Uses default Laravel user model
});
Multi-Auth Systems:
users table by using guards:
Auth::guard('package_web')->check(); // Check package auth
Auth::check(); // Check default auth
resources/views/vendor/my-form/ and extend the package’s logic.actingAs with the PackageUser model:
$this->actingAs(PackageUser::find(1), 'package_web');
php artisan vendor:publish --tag=my-form-lang
Default Admin Credentials:
adminuser/secret). Change these in production or disable the seeder:
// In DatabaseSeeder.php
$this->call([
// Comment out MyFormSeeder::class
]);
Route Conflicts:
/my-form/* routes may conflict with existing routes. Use route model binding or middleware to isolate them.Model Naming:
PackageUser model is non-standard. Avoid confusion by aliasing it:
use Niharb\MyForm\Models\PackageUser as MyFormUser;
Migration Overwrites:
php artisan migrate:fresh may reset the package_users table. Back up data or use --seed carefully.Lack of Documentation:
Auth Guard Issues:
package_web guard is correctly configured in auth.php. Test with:
dd(Auth::guard('package_web')->check());
Form Validation Errors:
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
}
}
Session/Token Conflicts:
package_web (session) and api (token) guards, ensure cookies/sessions are not shared unintentionally.Guard Naming:
package_web guard name is arbitrary. Rename it in auth.php if needed (e.g., myform_web).Seeder Timing:
php artisan migrate. Disable it if you manage users manually:
// config/my-form.php (if exists)
'seed' => false,
Package Updates:
@dev tag suggests instability. Pin versions in composer.json:
"niharb/my-form": "1.0.0"
Custom Controllers:
AppServiceProvider:
public function register() {
$this->app->bind(
\Niharb\MyForm\Http\Controllers\RegisterController::class,
\App\Http\Controllers\MyForm\RegisterController::class
);
}
Event Listeners:
// Example: Listen for registration
event(new \Niharb\MyForm\Events\UserRegistered($user));
API Endpoints:
Route::middleware(['auth:package_web', 'api'])->get('/protected-api');
Database Observers:
PackageUser for custom logic:
PackageUser::observe(MyFormUserObserver::class);
How can I help you explore Laravel packages today?