Laravel-AdminLTE: [BUG] Adding modals to a view causes error Undefined variable: errors \vendor\jeroennoten\laravel-adminlte\resources\views\components\form\input.blade.php)

Describe the bug

I’m returning a view from my controller:

return view('add.game')
    ->with(
        [
            'platforms'  => Platform::orderBy('name')->get(),
            'media'      => Medium::orderBy('name')->get(),
            'publishers' => Publisher::orderBy('name')->get(),
            'developers' => Developer::orderBy('name')->get(),
            'success'    => true,
            'message'    => 'Game added successfully!',
        ]
    );

Inside my view, I have a check that I’d thought would display a modal:

@extends('adminlte::page')
@section('title', 'Add Game')
@section('content')
    <div class="col-md-12">
        @if (isset($success))
            @if($success)
                <x-adminlte-modal id="modalGreen" title="Game Add" theme="green"
                                  icon="fas fa-bolt" size='lg' disable-animations>
                    {{$message}}
                </x-adminlte-modal>
            @else
                <x-adminlte-modal id="modalRed" title="Game Add" theme="red"
                                  icon="fas fa-bolt" size='lg' disable-animations>
                    {{$message}}
                </x-adminlte-modal>
            @endif
        @endif
        @component('components.add.game', ['platforms' => $platforms, 'media' => $media, 'publishers' => $publishers, 'developers' => $developers])
        @endcomponent
    </div>
@endsection

However, on submission, I receive the error:

Undefined variable: errors (View: \vendor\jeroennoten\laravel-adminlte\resources\views\components\form\input.blade.php)

If I remove everything inside the @if (isset($success)), the return to the view will obviously work.

Expected behavior

I’d expect that the modal would display.

Environment

Complete the next environment information.

Item Version
Laravel 8.42.1
AdminLTE 3.6
OS Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20

Most upvoted comments

Based on they documentation, that middleware should be automatically loaded if you write the routes on the routes/web.php file. Read here. I just wanted to note that there is some strange in your framework, but you can omit this. I will create a fix to ensure $errors is set before inspecting it.

Thanks again for your help. I just wish I knew what I’d done wrong for it to not work. I’ve been following the Laravel and Laravel-AdminLTE as much as humanly possible.