laravel/ui
Legacy Laravel package that adds Bootstrap, Vue, or React frontend scaffolding and simple auth (login/registration) via Artisan (php artisan ui ... --auth). Works with modern Laravel, but Breeze or Jetstream are recommended for new apps.
## Getting Started
### Minimal Setup
1. **Install the package**:
```bash
composer require laravel/ui
php artisan ui bootstrap
php artisan ui vue --auth
php artisan ui react --auth
npm install
npm run dev
npm run build
php artisan ui vue --auth to generate login, registration, password reset, and email verification views, controllers, and routes.resources/views/auth/ (e.g., login.blade.php) to modify forms, validation messages, or styling.Authentication Flow:
AuthenticatesUsers trait in controllers (e.g., LoginController).handleUserLogin() or override validateLogin().RegistersUsers for registration (e.g., add custom validation in validator()).Frontend Integration:
resources/js/app.js:
import ExampleComponent from './components/ExampleComponent.vue';
Vue.component('example-component', ExampleComponent);
<example-component :data="{{ json_encode($data) }}"></example-component>
axios.post('/login', { email, password })
.then(response => { /* handle */ });
Asset Management:
vite.config.js to customize entry points or plugins.resources/sass/app.scss:
$primary: #3490dc;
@import "bootstrap/scss/bootstrap";
resources/js/auth.js) and import into app.js.Customization:
resources/views/auth/ or resources/views/layouts/.routes/web.php to add custom routes for auth middleware:
Route::middleware(['auth'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index']);
});
Testing:
actingAs() in tests:
$user = User::factory()->create();
$this->actingAs($user)->get('/dashboard');
Asset Compilation:
npm run dev fails with missing dependencies.
Fix: Run npm install first or check package.json for version conflicts.vite.config.js includes the correct entry points and run npm run dev -- --host for external access.Authentication:
AuthenticatesUsers forces "remember me" by default.
Fix: Override validateLogin() to exclude the remember field:
protected function validateLogin(Request $request) {
return $request->validate([
'email' => 'required|email',
'password' => 'required',
// Remove 'remember' from validation
]);
}
password_confirmed_at in the users table or update ConfirmsPasswords trait.Frontend:
app.js and imported correctly.
Debug: Check browser console for errors (e.g., missing dependencies).app.scss imports Bootstrap correctly and compile assets.Configuration:
ui command not found.
Fix: Ensure Laravel\Ui\UiServiceProvider is registered in config/app.php under providers.UiCommand is used:
UiCommand::macro('nextjs', function () {
// Scaffold logic
});
Performance:
npm run build for production to minify assets.const { default: Analytics } = await import('./analytics.js');
Extensibility:
AuthenticatesUsers:
trait CustomAuthenticatesUsers {
use AuthenticatesUsers {
login as private parentLogin;
}
public function login(Request $request) {
// Custom logic
$this->parentLogin($request);
}
}
UiCommand for reusable scaffolding (e.g., php artisan ui tailwind).Debugging:
@debug directive to inspect variables:
@debug($user)
created() lifecycle hook:
created() {
console.log('Props:', this.$props);
}
php artisan route:list
Versioning:
package.json to pin Bootstrap versions (e.g., "bootstrap": "^5.3.0") to avoid breaking changes.laravel/ui's supported versions table.Security:
@csrf:
<form method="POST" action="/login">
@csrf
<!-- fields -->
</form>
Hash::make() and never store plaintext passwords.Legacy Code:
AuthenticatesUsers with LoginController from Breeze and update Blade templates incrementally.webpack.mix.js to vite.config.js by following Laravel’s migration guide.
---
How can I help you explore Laravel packages today?