Auth Pages Not Getting CSS in Laravel
When you run php artisan ui vue --auth to scaffold your authentication views, Laravel generates a set of files including Login, Register, and ForgotPassword. While these new pages often render as plain HTML without styling, the welcome page might display perfectly because it relies on different assets. This discrepancy usually stems from how the View Composer or asset compilation is configured for specific routes versus the main dashboard.
Understanding the Asset Compilation Flow
In a standard Laravel setup using Vite (which npm run dev triggers), the build process compiles your CSS and JavaScript into single files, typically found in the public/build directory. The welcome page (welcome.blade.php) explicitly includes these assets via the <link> and <script> tags you identified in layouts/app.blade.php.
However, the issue arises when the authentication views inherit from a layout that fails to load these assets or if the specific route serving the login page is configured differently. When you navigate to /login, Laravel loads resources/views/auth/login.blade.php (or similar). If this view does not extend layouts/app.blade.php correctly, or if the layout itself is missing the asset inclusions for that specific context, the browser will not render the stylesheets.
Verifying View Inheritance
The most common cause for "plain HTML" auth pages is that the view file isn't properly inheriting the master layout containing the CSS links. Open resources/views/auth/login.blade.php. It should look something like this:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6">
<!-- Login Form Here -->
</div>
</div>
</div>
@endsection
If the file is empty or simply renders HTML without @extends('layouts.app'), the CSS defined in public/css/app.css will never be loaded. The welcome page likely works because it explicitly calls @yield('content') on a layout that has already included the assets, whereas the auth views might have been generated with a different structure or manually edited incorrectly during the initial setup.
Checking the Master Layout
Ensure that resources/views/layouts/app.blade.php is actually being used for these views and that it contains the necessary asset tags:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body class="font-sans antialiased">
<div class="min-h-screen bg-gray-100">
@yield('content')
</div>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
</body>
</html>
If app.blade.php is missing the <link href="{{ asset('css/app.css') }}"> tag, you must add it. Note that in newer Laravel versions with Vite, this link is often auto-generated by Blade directives like @vite(['resources/css/app.css', 'resources/js/app.js']). If you are using the older Vite syntax or a custom setup, the manual <link> tag is required.
The NPM Build Process
Sometimes the files exist in your source code but haven't been compiled into the public directory yet. Although you ran npm run dev, ensure that the build was successful and that no errors occurred during compilation. You can check if the file exists by visiting http://localhost:5173 (or your configured port) to see the Vite proxy, or simply check if public/css/app.css and public/js/app.js are present.
If you recently ran composer require laravel/ui, ensure that the UI package is installed correctly. Occasionally, conflicts between the built-in Blade components and the Vue scaffolding can lead to missing assets if the entry point isn't configured in vite.config.js.
Final Steps to Resolve
- Verify File Existence: Confirm
public/css/app.cssexists. - Check Layout Tags: Ensure
layouts/app.blade.phphas the<link>tag pointing to that CSS file. - Clear Caches: Run
php artisan view:clear,php artisan config:clear, andnpm run build(ordev) to ensure no stale data is preventing the correct assets from loading.
Once the layout correctly extends the master template and the asset links are present, the Login and Register pages will render with the same styling as your welcome page.
