91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Barang;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class BarangController extends Controller
|
|
{
|
|
// Key untuk menyimpan data di session
|
|
private static $sessionKey = 'barang_data';
|
|
|
|
// Data barang default
|
|
private static $defaultBarangData = [
|
|
[
|
|
'id' => 1,
|
|
'nama_barang' => 'Box Subwoofer CLA 18 inc',
|
|
'kategori' => 'Speaker',
|
|
'deskripsi' => 'Box Subwoofer dengan ukuran 18 inch',
|
|
'stok' => 4,
|
|
'gambar' => 'box-subwoofer.jpg'
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'nama_barang' => 'Mixer 12,16,18 channel',
|
|
'kategori' => 'Audio Mixer',
|
|
'deskripsi' => 'Mixer audio dengan 12, 16, atau 18 channel',
|
|
'stok' => 3,
|
|
'gambar' => 'mixer.jpg'
|
|
],
|
|
[
|
|
'id' => 3,
|
|
'nama_barang' => 'Kabel',
|
|
'kategori' => 'Kabel',
|
|
'deskripsi' => 'Kabel audio berbagai ukuran',
|
|
'stok' => 30,
|
|
'gambar' => 'kabel.jpg'
|
|
],
|
|
[
|
|
'id' => 4,
|
|
'nama_barang' => 'Wired microphone (kabel)',
|
|
'kategori' => 'Microphone',
|
|
'deskripsi' => 'Microphone dengan kabel',
|
|
'stok' => 8,
|
|
'gambar' => 'wired-mic.jpg'
|
|
],
|
|
[
|
|
'id' => 5,
|
|
'nama_barang' => 'Wireless microphone (UHF/VHF)',
|
|
'kategori' => 'Microphone',
|
|
'deskripsi' => 'Microphone wireless tipe UHF/VHF',
|
|
'stok' => 6,
|
|
'gambar' => 'wireless-mic.jpg'
|
|
]
|
|
];
|
|
|
|
/**
|
|
* Mendapatkan data barang dari session atau data default jika belum ada
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getBarangData()
|
|
{
|
|
if (!Session::has(self::$sessionKey)) {
|
|
Session::put(self::$sessionKey, self::$defaultBarangData);
|
|
}
|
|
|
|
return Session::get(self::$sessionKey);
|
|
}
|
|
|
|
/**
|
|
* Menyimpan data barang ke session
|
|
*
|
|
* @param array $data
|
|
* @return void
|
|
*/
|
|
public static function saveBarangData($data)
|
|
{
|
|
Session::put(self::$sessionKey, $data);
|
|
}
|
|
|
|
/**
|
|
* Menampilkan halaman daftar barang
|
|
*/
|
|
public function index()
|
|
{
|
|
$barangs = Barang::where('status', 'aktif')->get();
|
|
return view('barang', compact('barangs'));
|
|
}
|
|
}
|