Undefined variable: isModal (View: C:\xampp\htdocs\sebi\simoneb2\resources\views\livewire\beasiswa\index.blade.php)
Php Is Case Sensitive but that variable are same , and then why that erorr ??
livewire/beasiswa/index.php
{
public $beasiswas,$nama,$deskripsi, $foto, $semester_id, $users_id;
public $isModal = 0;
public function render()
{
$this->beasiswas = Beasiswa::join('semester', 'beasiswa.semester_id', '=', 'semester.id')
->join('users', 'beasiswa.users_id', '=', 'users.id')
->select('beasiswa.*', 'semester.nama AS semester', 'users.*')
->orderBy('created_at', 'DESC')->Auth::user()->get();
return view('livewire.beasiswa.index');
}
public function create()
{
$this->resetFields();
$this->openModal();
}
public function closeModal()
{
$this->isModal = false;
}
public function openModal()
{
$this->isModal = true;
}
public function resetFields()
{
$this->nama = '';
$this->deskripsi = '';
$this->foto = '';
$this->semester_id = '';
$this->users_id = '';
}
public function store()
{
//MEMBUAT VALIDASI
$validatedData = $this->validate([
'nama' => 'required|string',
'deskripsi' => 'required|string',
'foto' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'semester' => 'required'
]);
$validatedData['nama'] = $this->file->store('files', 'public');
//QUERY UNTUK MENYIMPAN / MEMPERBAHARUI DATA MENGGUNAKAN UPDATEORCREATE
//DIMANA ID MENJADI UNIQUE ID, JIKA IDNYA TERSEDIA, MAKA UPDATE DATANYA
//JIKA TIDAK, MAKA TAMBAHKAN DATA BARU
Beasiswa::updateOrCreate(['id' => $this->users_id], [
'nama' => $this->nama,
'deskripsi' => $this->deskripsi,
'foto' => $this->foto,
'semester' => $this->semester,
'id' => $this->id,
]);
//BUAT FLASH SESSION UNTUK MENAMPILKAN ALERT NOTIFIKASI
session()->flash('message', $this->users_id ? $this->nama . ' Diperbaharui': $this->nama . ' Ditambahkan');
$this->closeModal(); //TUTUP MODAL
$this->resetFields(); //DAN BERSIHKAN FIELD
}
//FUNGSI INI UNTUK MENGAMBIL DATA DARI DATABASE BERDASARKAN ID MEMBER
public function edit($id)
{
$beasiswa = Beasiswa::find($id); //BUAT QUERY UTK PENGAMBILAN DATA
//LALU ASSIGN KE DALAM MASING-MASING PROPERTI DATANYA
$this->users_id = $id;
$this->nama = $beasiswa->nama;
$this->deskripsi = $beasiswa->deskripsi;
$this->foto = $beasiswa->foto;
$this->semester_id = $beasiswa->semester_id;
$this->openModal(); //LALU BUKA MODAL
}
//FUNGSI INI UNTUK MENGHAPUS DATA
public function delete($id)
{
$beasiswa = Beasiswa::find($id); //BUAT QUERY UNTUK MENGAMBIL DATA BERDASARKAN ID
$beasiswa->delete(); //LALU HAPUS DATA
session()->flash('message', $beasiswa->nama . ' Dihapus');
}
}
index.blade.php
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Data Anggota
</h2>
@if (session()->has('message'))
@endif
{{ session('message') }}
<button wire:click="create()" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded my-3">Tambah Anggota</button>
@if($isModal)
@include('livewire.beasiswa.create')
@endif
<table class="table-fixed w-full">
<thead>
<tr class="bg-gray-100">
<th class="px-4 py-2">Nama</th>
<th class="px-4 py-2">Deskripsi</th>
<th class="px-4 py-2">Foto</th>
<th class="px-4 py-2 w-20">Semester</th>
<th class="px-4 py-2">Action</th>
</tr>
</thead>
<tbody>
@forelse($members as $row)
<tr>
<td class="border px-4 py-2">{{ $row->nama }}</td>
<td class="border px-4 py-2">{{ $row->eskripsi }}</td>
<td class="border px-4 py-2">{{ $row->foto }}</td>
<td class="border px-4 py-2">{{ $row->semester}}</td>
<td class="border px-4 py-2">
<button wire:click="edit({{ $row->id }})" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Edit</button>
<button wire:click="delete({{ $row->id }})" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">Hapus</button>
</td>
</tr>
@empty
<tr>
<td class="border px-4 py-2 text-center" colspan="5">Tidak ada data</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>