I am also having difficulty figuring out how to best override/change Vue components that come with Nova 4
Laravel Nova 4 change login layout
Good morning, I need to change the layout of the Laravel Nova 4 login screen. How could I do that?
Found a solution for this ?
Found any solution?
Now can't create a new theme in nova, it looks like it's been deleted
php artisan nova:theme example/miami-ice
Command "nova:theme" is not defined.
and this code is not working:
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\NovaServiceProviderRegistered;
use Laravel\Nova\Nova;
class ThemeServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Nova::serving(function (ServingNova $event) {
Event::listen(NovaServiceProviderRegistered::class, function ($event) {
Nova::theme(asset('/vendor/theme/theme.css'));
});
...
@jacktoncatrina , Even though Nova 4 has no blades to publish in the resource/views/vendor, you can still do it manually, you need to create resource/views/vendor/nova/auth/login.blade.php and if you want to extend the nova layouts you can. this worked for me. but when you update nova, make sure you have these files updated as well.
Hi @Shaden I've tried your approach, but with Nova 4 I am not sure what exactly should I put inside this login.blade.php, since all I could find to emulate the current login page is a /vendor/laravel/nova/resources/js/layout/Auth.vue file, which obviously is not a blade. All I want to do is to reduce the waste of space up and down of my custom logo...
@internetbug256 What you can do is pass custom auth paths in your nova.php config
// config/nova.php
'routes' => [
'login' => '/logincustom',
]
I didn't see this option in the docs, I saw it on this thread: https://github.com/laravel/nova-issues/discussions/3954
You now have complete control over the login form when you go to the /nova endpoint. You can just use plain blade if you like.
In your routes/web.php you can add the endpoint:
Route::get('/logincustom', function () {
return view('logincustom');
});
Create /resources/views/logincustom.blade.php. Here's a barebones example that I have working:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Nova Login Form</title>
</head>
<body>
<form action="{{ route('nova.login') }}" method="POST">
@csrf
<div>
<label for="email">Email Address</label>
<input id="email" type="email" name="email" autofocus required>
@error('email')
<div>{{ $message }}</div>
@enderror
</div>
<div>
<label for="password">Password</label>
<input id="password" type="password" name="password" required>
@error('password')
<div>{{ $message }}</div>
@enderror
</div>
<div>
<button type="submit">Login</button>
</div>
</form>
</body>
</html>
Notice that the form endpoint is still making use of nova's login endpoint. If you do a php artisan route:list you can see a POST request to /nova/login and the route name is nova.login.
If you want to use Tailwind, you're going to have to set it up manually within the Laravel app itself.
@drehimself what if I want to edit the login.vue file! is it possible?
@yomi +1
Thanks, @drehimself . I really didn't want to do a whole custom login form for just a space-between-logo adjustment, but seems that this is the way to go...
First copy view layout.blade.php from Nova to your app
mkdir -p resources/views/vendor/nova/auth/ && cp vendor/laravel/nova/resources/views/auth/layout.blade.php resources/views/vendor/nova/auth/
Then to file resources/views/vendor/nova/auth/layout.blade.php add css tag
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
Pay attention to the paths which file you copy. Works for me for Nova 3.
Hi there. I am back looking for maybe new ways to customize Nova 4 colors and fonts. By the way, @drehimself , thanks a lot for your tips. I finally did the custom login the way you said.
So, is there any polite (or dirty) way to customize Nova4 colors? I have complains from laptop users telling me that the font colors are too gray, too bright, lack of contrast, etc.
@internetbug256 For general panel (Doesn't work in login, sadly), I use this code in NovaServiceProvider's boot method:
Nova::style('custom-admin', public_path('nova-extra.css'));
Then, you create that file and override the classes you want. For example:
.dark .dark\:text-gray-400 {
color: rgba(255, 255, 255, 0.8);
}
.text-gray-400 {
color: rgba(0, 0, 0, 0.8);
}
This is dirty as hell, but works...
Here is my solution
I need to use the username column to log in, so I override the controller and view.
# app/Http/Controllers/NovaLoginController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\View\View;
class NovaLoginController extends \Laravel\Nova\Http\Controllers\LoginController
{
public function showLoginForm(): View
{
return view('nova.login');
}
public function username()
{
return 'username';
}
}
# app/Providers/NovaServiceProvider.php
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
// ...
protected function routes()
{
Nova::routes()
->withAuthenticationRoutes()
->withPasswordResetRoutes()
->register();
Route::namespace('Laravel\Nova\Http\Controllers')
->domain(config('nova.domain', null))
->middleware(['nova'])
->prefix(Nova::path())
->group(function (Router $router) {
$router->get('/login', [\App\Http\Controllers\NovaLoginController::class, 'showLoginForm'])->name('nova.pages.login');
$router->post('/login', [\App\Http\Controllers\NovaLoginController::class, 'login'])->name('nova.login');
});
}
# resources/views/nova/login.blade.php
<form class="space-y-6" action="{{ route('nova.login') }}" method="POST">
@csrf
@if ($errors->any())
<p class="text-center font-semibold text-red-500 my-3">
@if ($errors->has('username'))
{{ $errors->first('username') }}
@else
{{ $errors->first('password') }}
@endif
</p>
@endif
<div>
<label for="username">Username</label>
<div>
<input id="username" name="username" type="text" autocomplete="username" required value="{{ old('username') }}">
</div>
</div>
<div>
<label for="password">Password</label>
<div>
<input id="password" name="password" type="password" autocomplete="current-password" required>
</div>
</div>
<div>
<div>
<input id="remember" name="remember" type="checkbox" {{ old('remember') ? 'checked' : '' }}>
<label for="remember">Remember me</label>
</div>
</div>
<div>
<button type="submit">Sign in</button>
</div>
</form>
Please or to participate in this conversation.