1

I got message Undefined variable

Undefined variable: pesan (View: C:\xampp\htdocs\webapp\resources\views\welcome.blade.php)

This my controller

...

public function index(){
  $data = DB::table('data_peminjaman')->get();
  $inventaris = DB::table('inventaris')->get();
  $posting = DB::table('artikel')->get();
  $pesan = null;
  $semuanya = ['posting' => $posting,
                'pesan' => $pesan,
                'data' => $data,
                '$inventaris' => $inventaris];
  return view('welcome', $semuanya);
}

...

This is my blade code

 @if ($pesan !=null)
     <div class="alert alert-danger">
        {{ $pesan }}
    </div>
 @endif
Shadow
  • 33,525
  • 10
  • 51
  • 64
Irsyad Nurilhaq
  • 129
  • 1
  • 6
  • 15

1 Answers1

0

Return your array this way in your controller:

return view('FOLDER_NAME.BLADE_FILE_NAME')->with($semuanya);

And then try this in your blade file:

@if(!empty($pesan))
    <div class="alert alert-danger">
        {{ $pesan }}
    </div>
@endif
Shreeraj
  • 758
  • 1
  • 9
  • 27