I am trying to develop a local Laravel package where I can put all my blade components and views so I can include my repo in all my future applications. At this point, All things is ok except one problem: "Undefined variable $errors" in my blade. I'm using @error directive. I know the problem occurred in this section of my code but my question is why not included variable $error within the blade view of my package?
Routes:
use Adway\Hauth\Http\Controllers\HauthController;
use Illuminate\Support\Facades\Route;
Route::get('/login',[HauthController::class,'login'])->name('login');
Route::get('/logout',[HauthController::class,'logout'])->name('logout');
Route::get('/register',[HauthController::class,'register'])->name('register');
Route::post('auth/login',[HauthController::class,'loginAutenticate'])->name('hauth.login');
Route::post('auth/register',[HauthController::class,'registerAutenticate'])->name('hauth.register');
Route::middleware('auth')->group(function(){
Route::get('/dashboard',[HauthController::class,'dashboard'])->name('dashboard');
});
View:
<x-app>
<div class="p-5 border-2 border-green-500 ">
<form action="{{ route('hauth.login') }}" method="post">
@csrf
<div class="grid grid-cols-2 gap-x-8 gap-y-4">
<div class="grid grid-cols-2">
<label for="name">email:</label>
<input type="email" name="email" id="email" required>
@error('email')
<span class="bg-red-400">{{ $message }}</span>
@enderror
</div>
<div class="grid grid-cols-2">
<label for="name">password:</label>
<input type="password" name="password" id="password" required>
@error('password')
<span class="bg-red-400">{{ $message }}</span>
@enderror
</div>
<button type="submit" class="px-2 bg-green-400 max-w-min rounded-md">login</button>
</div>
</form>
</div>
</x-app>
service provider:
public function boot(): void
{
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'adway');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'hauth');
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
// Publishing is only necessary when using the CLI.
if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
}
HauthController
and this template does not use{{ $errors }}
. – Chlorate