This commit is contained in:
commit
402838d3bb
|
@ -0,0 +1,66 @@
|
|||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_TIMEZONE=UTC
|
||||
APP_URL=http://localhost
|
||||
|
||||
APP_LOCALE=en
|
||||
APP_FALLBACK_LOCALE=en
|
||||
APP_FAKER_LOCALE=en_US
|
||||
|
||||
APP_MAINTENANCE_DRIVER=file
|
||||
# APP_MAINTENANCE_STORE=database
|
||||
|
||||
PHP_CLI_SERVER_WORKERS=4
|
||||
|
||||
BCRYPT_ROUNDS=12
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_STACK=single
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=sqlite
|
||||
# DB_HOST=127.0.0.1
|
||||
# DB_PORT=3306
|
||||
# DB_DATABASE=laravel
|
||||
# DB_USERNAME=root
|
||||
# DB_PASSWORD=
|
||||
|
||||
SESSION_DRIVER=database
|
||||
SESSION_LIFETIME=120
|
||||
SESSION_ENCRYPT=false
|
||||
SESSION_PATH=/
|
||||
SESSION_DOMAIN=null
|
||||
|
||||
BROADCAST_CONNECTION=log
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=database
|
||||
|
||||
CACHE_STORE=database
|
||||
CACHE_PREFIX=
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_CLIENT=phpredis
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=log
|
||||
MAIL_SCHEME=null
|
||||
MAIL_HOST=127.0.0.1
|
||||
MAIL_PORT=2525
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
|
@ -0,0 +1,11 @@
|
|||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
|
@ -0,0 +1,23 @@
|
|||
/.phpunit.cache
|
||||
/node_modules
|
||||
/public/build
|
||||
/public/hot
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/storage/pail
|
||||
/vendor
|
||||
.env
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpactor.json
|
||||
.phpunit.result.cache
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
/auth.json
|
||||
/.fleet
|
||||
/.idea
|
||||
/.nova
|
||||
/.vscode
|
||||
/.zed
|
|
@ -0,0 +1,66 @@
|
|||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
||||
</p>
|
||||
|
||||
## About Laravel
|
||||
|
||||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
|
||||
|
||||
- [Simple, fast routing engine](https://laravel.com/docs/routing).
|
||||
- [Powerful dependency injection container](https://laravel.com/docs/container).
|
||||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
|
||||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
|
||||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
|
||||
- [Robust background job processing](https://laravel.com/docs/queues).
|
||||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
|
||||
|
||||
Laravel is accessible, powerful, and provides tools required for large, robust applications.
|
||||
|
||||
## Learning Laravel
|
||||
|
||||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
|
||||
|
||||
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
|
||||
|
||||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
|
||||
|
||||
## Laravel Sponsors
|
||||
|
||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
|
||||
|
||||
### Premium Partners
|
||||
|
||||
- **[Vehikl](https://vehikl.com/)**
|
||||
- **[Tighten Co.](https://tighten.co)**
|
||||
- **[WebReinvent](https://webreinvent.com/)**
|
||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
||||
- **[64 Robots](https://64robots.com)**
|
||||
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
|
||||
- **[Cyber-Duck](https://cyber-duck.co.uk)**
|
||||
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
|
||||
- **[Jump24](https://jump24.co.uk)**
|
||||
- **[Redberry](https://redberry.international/laravel/)**
|
||||
- **[Active Logic](https://activelogic.com)**
|
||||
- **[byte5](https://byte5.de)**
|
||||
- **[OP.GG](https://op.gg)**
|
||||
|
||||
## Contributing
|
||||
|
||||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
|
||||
|
||||
## Security Vulnerabilities
|
||||
|
||||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
|
||||
|
||||
## License
|
||||
|
||||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Barang;
|
||||
use App\Models\Transaksi;
|
||||
use App\Models\Pesanan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function dashboard()
|
||||
{
|
||||
// Get total counts
|
||||
$totalUsers = User::count();
|
||||
$totalBarang = Barang::count();
|
||||
$totalTransaksi = Transaksi::count();
|
||||
$totalPendapatan = Transaksi::where('status_pembayaran', 'dibayar')->sum('total_pembayaran');
|
||||
|
||||
// Get recent users
|
||||
$recentUsers = User::latest()
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
// Get pesanan data
|
||||
$pesanan = Pesanan::with(['barang'])
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
// Get recent transactions
|
||||
$recentTransaksi = Transaksi::with(['user', 'pesanan'])
|
||||
->latest()
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
return view('admin.dashboardadmin', compact(
|
||||
'totalUsers',
|
||||
'totalBarang',
|
||||
'totalTransaksi',
|
||||
'totalPendapatan',
|
||||
'recentUsers',
|
||||
'recentTransaksi',
|
||||
'pesanan'
|
||||
));
|
||||
}
|
||||
|
||||
public function settings()
|
||||
{
|
||||
return view('admin.settings');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Banner;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class BannerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$banners = Banner::orderBy('urutan')->get();
|
||||
return view('admin.banners.index', compact('banners'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.banners.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'judul' => 'required|string|max:255',
|
||||
'deskripsi' => 'nullable|string',
|
||||
'gambar' => 'required|image|max:2048',
|
||||
'url' => 'nullable|string|max:255',
|
||||
'aktif' => 'required|boolean',
|
||||
'tanggal_mulai' => 'nullable|date',
|
||||
'tanggal_selesai' => 'nullable|date|after_or_equal:tanggal_mulai',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
// Otomatisasi urutan
|
||||
$lastBanner = Banner::orderBy('urutan', 'desc')->first();
|
||||
$data['urutan'] = $lastBanner ? $lastBanner->urutan + 1 : 1;
|
||||
|
||||
// Menangani tanggal kosong
|
||||
if (empty($data['tanggal_mulai'])) {
|
||||
$data['tanggal_mulai'] = null;
|
||||
}
|
||||
|
||||
if (empty($data['tanggal_selesai'])) {
|
||||
$data['tanggal_selesai'] = null;
|
||||
}
|
||||
|
||||
if ($request->hasFile('gambar')) {
|
||||
$data['gambar'] = $request->file('gambar')->store('banners', 'public');
|
||||
}
|
||||
|
||||
Banner::create($data);
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Banner berhasil ditambahkan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Banner $banner)
|
||||
{
|
||||
return view('admin.banners.show', compact('banner'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Banner $banner)
|
||||
{
|
||||
return view('admin.banners.edit', compact('banner'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Banner $banner)
|
||||
{
|
||||
$request->validate([
|
||||
'judul' => 'required|string|max:255',
|
||||
'deskripsi' => 'nullable|string',
|
||||
'gambar' => 'nullable|image|max:2048',
|
||||
'url' => 'nullable|string|max:255',
|
||||
'urutan' => 'nullable|integer|min:1',
|
||||
'tanggal_mulai' => 'nullable|date',
|
||||
'tanggal_selesai' => 'nullable|date|after_or_equal:tanggal_mulai',
|
||||
'aktif' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
// Menangani tanggal kosong
|
||||
if (empty($data['tanggal_mulai'])) {
|
||||
$data['tanggal_mulai'] = null;
|
||||
}
|
||||
|
||||
if (empty($data['tanggal_selesai'])) {
|
||||
$data['tanggal_selesai'] = null;
|
||||
}
|
||||
|
||||
if ($request->hasFile('gambar')) {
|
||||
// Hapus gambar lama jika ada
|
||||
if ($banner->gambar) {
|
||||
Storage::disk('public')->delete($banner->gambar);
|
||||
}
|
||||
|
||||
$data['gambar'] = $request->file('gambar')->store('banners', 'public');
|
||||
}
|
||||
|
||||
$banner->update($data);
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Banner berhasil diperbarui');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Banner $banner)
|
||||
{
|
||||
// Hapus gambar jika ada
|
||||
if ($banner->gambar) {
|
||||
Storage::disk('public')->delete($banner->gambar);
|
||||
}
|
||||
|
||||
$banner->delete();
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Banner berhasil dihapus');
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle status banner
|
||||
*/
|
||||
public function toggleStatus(Banner $banner)
|
||||
{
|
||||
$banner->aktif = !$banner->aktif;
|
||||
$banner->save();
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Status banner berhasil diubah');
|
||||
}
|
||||
|
||||
/**
|
||||
* Move banner up in order
|
||||
*/
|
||||
public function moveUp(Banner $banner)
|
||||
{
|
||||
$prevBanner = Banner::where('urutan', '<', $banner->urutan)
|
||||
->orderBy('urutan', 'desc')
|
||||
->first();
|
||||
|
||||
if ($prevBanner) {
|
||||
// Swap positions
|
||||
$tempUrutan = $prevBanner->urutan;
|
||||
$prevBanner->urutan = $banner->urutan;
|
||||
$banner->urutan = $tempUrutan;
|
||||
|
||||
$prevBanner->save();
|
||||
$banner->save();
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Urutan banner berhasil diubah');
|
||||
}
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('info', 'Banner sudah berada di urutan teratas');
|
||||
}
|
||||
|
||||
/**
|
||||
* Move banner down in order
|
||||
*/
|
||||
public function moveDown(Banner $banner)
|
||||
{
|
||||
$nextBanner = Banner::where('urutan', '>', $banner->urutan)
|
||||
->orderBy('urutan', 'asc')
|
||||
->first();
|
||||
|
||||
if ($nextBanner) {
|
||||
// Swap positions
|
||||
$tempUrutan = $nextBanner->urutan;
|
||||
$nextBanner->urutan = $banner->urutan;
|
||||
$banner->urutan = $tempUrutan;
|
||||
|
||||
$nextBanner->save();
|
||||
$banner->save();
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('success', 'Urutan banner berhasil diubah');
|
||||
}
|
||||
|
||||
return redirect()->route('admin.banners.index')->with('info', 'Banner sudah berada di urutan terbawah');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Barang;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class BarangController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware(\App\Http\Middleware\CheckRole::class . ':admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$barang = Barang::latest()->get();
|
||||
return view('admin.barang.index', compact('barang'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.barang.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required|string|max:255',
|
||||
'deskripsi' => 'required|string',
|
||||
'harga' => 'required|numeric|min:0',
|
||||
'stok' => 'required|integer|min:0',
|
||||
'kategori' => 'required|string|max:100',
|
||||
'gambar' => 'required|image|mimes:jpeg,png,jpg|max:2048',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'nama_barang' => $request->nama,
|
||||
'deskripsi' => $request->deskripsi,
|
||||
'harga' => $request->harga,
|
||||
'stok' => $request->stok,
|
||||
'kategori' => $request->kategori,
|
||||
'slug' => Str::slug($request->nama) . '-' . Str::random(5),
|
||||
];
|
||||
|
||||
if ($request->hasFile('gambar')) {
|
||||
$gambar = $request->file('gambar');
|
||||
// Simpan dengan nama asli
|
||||
$fileName = $gambar->getClientOriginalName();
|
||||
$path = $gambar->storeAs('products', $fileName, 'public');
|
||||
$data['gambar'] = $path;
|
||||
}
|
||||
|
||||
Barang::create($data);
|
||||
|
||||
return redirect()->route('admin.barang.index')
|
||||
->with('success', 'Barang berhasil ditambahkan');
|
||||
}
|
||||
|
||||
public function show(Barang $barang)
|
||||
{
|
||||
return view('admin.barang.show', compact('barang'));
|
||||
}
|
||||
|
||||
public function edit(Barang $barang)
|
||||
{
|
||||
return view('admin.barang.edit', compact('barang'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Barang $barang)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required|string|max:255',
|
||||
'deskripsi' => 'required|string',
|
||||
'harga' => 'required|numeric|min:0',
|
||||
'stok' => 'required|integer|min:0',
|
||||
'kategori' => 'required|string|max:100',
|
||||
'gambar' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'nama_barang' => $request->nama,
|
||||
'deskripsi' => $request->deskripsi,
|
||||
'harga' => $request->harga,
|
||||
'stok' => $request->stok,
|
||||
'kategori' => $request->kategori,
|
||||
];
|
||||
|
||||
if ($request->hasFile('gambar')) {
|
||||
// Hapus gambar lama jika ada
|
||||
if ($barang->gambar) {
|
||||
Storage::disk('public')->delete($barang->gambar);
|
||||
}
|
||||
|
||||
$data['gambar'] = $request->file('gambar')->store('products', 'public');
|
||||
}
|
||||
|
||||
$barang->update($data);
|
||||
|
||||
return redirect()->route('admin.barang.index')
|
||||
->with('success', 'Barang berhasil diupdate');
|
||||
}
|
||||
|
||||
public function destroy(Barang $barang)
|
||||
{
|
||||
// Hapus gambar jika ada
|
||||
if ($barang->gambar) {
|
||||
Storage::disk('public')->delete($barang->gambar);
|
||||
}
|
||||
|
||||
$barang->delete();
|
||||
return redirect()->route('admin.barang.index')
|
||||
->with('success', 'Barang berhasil dihapus');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Barang;
|
||||
use App\Models\Pesanan;
|
||||
use App\Models\Transaksi;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware(\App\Http\Middleware\CheckRole::class . ':admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Statistik Dasar
|
||||
$totalPengguna = User::count();
|
||||
$totalBarang = Barang::count();
|
||||
$totalPesanan = Pesanan::count();
|
||||
$totalPendapatan = Transaksi::where('status', 'dibayar')
|
||||
->sum('total_pembayaran');
|
||||
|
||||
// Pesanan Terbaru
|
||||
$pesananTerbaru = Pesanan::with('user')
|
||||
->latest()
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
// Produk Terlaris
|
||||
$produkTerlaris = Barang::select('barang.*', DB::raw('COUNT(pesanan.id) as total_terjual'))
|
||||
->leftJoin('pesanan', 'barang.id', '=', 'pesanan.barang_id')
|
||||
->where(function ($query) {
|
||||
$query->whereNull('pesanan.status')
|
||||
->orWhere('pesanan.status', '!=', 'cancelled');
|
||||
})
|
||||
->groupBy('barang.id')
|
||||
->orderBy('total_terjual', 'desc')
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
// Data aktivitas
|
||||
$aktivitasTerbaru = collect();
|
||||
|
||||
// Aktivitas pesanan terbaru
|
||||
$pesananAktivitas = Pesanan::with('user')
|
||||
->latest()
|
||||
->take(3)
|
||||
->get()
|
||||
->map(function ($pesanan) {
|
||||
return (object)[
|
||||
'type' => 'order',
|
||||
'description' => "Pesanan baru #{$pesanan->id} dari {$pesanan->user->nama}",
|
||||
'created_at' => $pesanan->created_at
|
||||
];
|
||||
});
|
||||
|
||||
// Aktivitas transaksi terbaru
|
||||
$transaksiAktivitas = Transaksi::with('user')
|
||||
->latest()
|
||||
->take(3)
|
||||
->get()
|
||||
->map(function ($transaksi) {
|
||||
return (object)[
|
||||
'type' => 'payment',
|
||||
'description' => "Pembayaran sebesar Rp " . number_format($transaksi->total_pembayaran, 0, ',', '.') . " dari {$transaksi->user->nama}",
|
||||
'created_at' => $transaksi->created_at
|
||||
];
|
||||
});
|
||||
|
||||
// Aktivitas user terbaru
|
||||
$userAktivitas = User::latest()
|
||||
->take(3)
|
||||
->get()
|
||||
->map(function ($user) {
|
||||
return (object)[
|
||||
'type' => 'user',
|
||||
'description' => "Pengguna baru terdaftar: {$user->nama}",
|
||||
'created_at' => $user->created_at
|
||||
];
|
||||
});
|
||||
|
||||
// Gabungkan semua aktivitas
|
||||
$aktivitasTerbaru = $pesananAktivitas->concat($transaksiAktivitas)
|
||||
->concat($userAktivitas)
|
||||
->sortByDesc('created_at')
|
||||
->take(5);
|
||||
|
||||
return view('admin.dashboard', compact(
|
||||
'totalPengguna',
|
||||
'totalBarang',
|
||||
'totalPesanan',
|
||||
'totalPendapatan',
|
||||
'pesananTerbaru',
|
||||
'produkTerlaris',
|
||||
'aktivitasTerbaru'
|
||||
));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,205 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\FlashSale;
|
||||
use App\Models\FlashSaleItem;
|
||||
use App\Models\Barang;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FlashSaleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$flashSales = FlashSale::orderBy('waktu_mulai', 'desc')->get();
|
||||
return view('admin.flash-sales.index', compact('flashSales'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.flash-sales.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required|string|max:255',
|
||||
'deskripsi' => 'nullable|string',
|
||||
'banner' => 'nullable|image|max:2048',
|
||||
'waktu_mulai' => 'required|date',
|
||||
'waktu_selesai' => 'required|date|after:waktu_mulai',
|
||||
'aktif' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
if ($request->hasFile('banner')) {
|
||||
$data['banner'] = $request->file('banner')->store('flash-sales', 'public');
|
||||
}
|
||||
|
||||
$flashSale = FlashSale::create($data);
|
||||
|
||||
return redirect()->route('admin.flash-sales.index')->with('success', 'Flash sale berhasil ditambahkan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(FlashSale $flashSale)
|
||||
{
|
||||
return view('admin.flash-sales.show', compact('flashSale'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(FlashSale $flashSale)
|
||||
{
|
||||
return view('admin.flash-sales.edit', compact('flashSale'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, FlashSale $flashSale)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required|string|max:255',
|
||||
'deskripsi' => 'nullable|string',
|
||||
'banner' => 'nullable|image|max:2048',
|
||||
'waktu_mulai' => 'required|date',
|
||||
'waktu_selesai' => 'required|date|after:waktu_mulai',
|
||||
'aktif' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
if ($request->hasFile('banner')) {
|
||||
// Hapus banner lama jika ada
|
||||
if ($flashSale->banner) {
|
||||
Storage::disk('public')->delete($flashSale->banner);
|
||||
}
|
||||
|
||||
$data['banner'] = $request->file('banner')->store('flash-sales', 'public');
|
||||
}
|
||||
|
||||
$flashSale->update($data);
|
||||
|
||||
return redirect()->route('admin.flash-sales.index')->with('success', 'Flash sale berhasil diperbarui');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(FlashSale $flashSale)
|
||||
{
|
||||
// Hapus banner jika ada
|
||||
if ($flashSale->banner) {
|
||||
Storage::disk('public')->delete($flashSale->banner);
|
||||
}
|
||||
|
||||
// Hapus semua item flash sale terkait
|
||||
$flashSale->items()->delete();
|
||||
|
||||
$flashSale->delete();
|
||||
|
||||
return redirect()->route('admin.flash-sales.index')->with('success', 'Flash sale berhasil dihapus');
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle status flash sale
|
||||
*/
|
||||
public function toggleStatus(FlashSale $flashSale)
|
||||
{
|
||||
$flashSale->aktif = !$flashSale->aktif;
|
||||
$flashSale->save();
|
||||
|
||||
return redirect()->route('admin.flash-sales.index')->with('success', 'Status flash sale berhasil diubah');
|
||||
}
|
||||
|
||||
/**
|
||||
* Menampilkan halaman daftar item flash sale
|
||||
*/
|
||||
public function showItems(FlashSale $flashSale)
|
||||
{
|
||||
$barangs = Barang::whereDoesntHave('flashSaleItems', function($query) use ($flashSale) {
|
||||
$query->where('flash_sale_id', $flashSale->id);
|
||||
})->get();
|
||||
|
||||
return view('admin.flash-sales.items', compact('flashSale', 'barangs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Menambahkan item ke flash sale
|
||||
*/
|
||||
public function storeItem(Request $request, FlashSale $flashSale)
|
||||
{
|
||||
$request->validate([
|
||||
'barang_id' => 'required|exists:barangs,id',
|
||||
'harga_flash_sale' => 'required|numeric|min:0',
|
||||
'persentase_diskon' => 'nullable|numeric|min:0|max:100',
|
||||
'stok_flash_sale' => 'required|integer|min:1',
|
||||
'aktif' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
$data['flash_sale_id'] = $flashSale->id;
|
||||
$data['stok_terjual'] = 0;
|
||||
|
||||
// Hitung persentase diskon jika tidak diisi
|
||||
if (empty($data['persentase_diskon'])) {
|
||||
$barang = Barang::find($data['barang_id']);
|
||||
$data['persentase_diskon'] = round((($barang->harga - $data['harga_flash_sale']) / $barang->harga) * 100);
|
||||
}
|
||||
|
||||
FlashSaleItem::create($data);
|
||||
|
||||
return redirect()->route('admin.flash-sales.items', $flashSale)->with('success', 'Item berhasil ditambahkan ke flash sale');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update item flash sale
|
||||
*/
|
||||
public function updateItem(Request $request, FlashSaleItem $flashSaleItem)
|
||||
{
|
||||
$request->validate([
|
||||
'harga_flash_sale' => 'required|numeric|min:0',
|
||||
'persentase_diskon' => 'required|numeric|min:0|max:100',
|
||||
'stok_flash_sale' => 'required|integer|min:' . $flashSaleItem->stok_terjual,
|
||||
'aktif' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$flashSaleItem->update($request->all());
|
||||
|
||||
return redirect()->route('admin.flash-sales.items', $flashSaleItem->flash_sale_id)->with('success', 'Item flash sale berhasil diperbarui');
|
||||
}
|
||||
|
||||
public function destroyItem(FlashSaleItem $flashSaleItem)
|
||||
{
|
||||
$flashSaleId = $flashSaleItem->flash_sale_id;
|
||||
$flashSaleItem->delete();
|
||||
return redirect()->route('admin.flash-sales.items', $flashSaleId)->with('success', 'Item flash sale berhasil dihapus');
|
||||
}
|
||||
|
||||
public function getItemData(FlashSaleItem $flashSaleItem)
|
||||
{
|
||||
return response()->json([
|
||||
'id' => $flashSaleItem->id,
|
||||
'harga_flash_sale' => $flashSaleItem->harga_flash_sale,
|
||||
'persentase_diskon' => $flashSaleItem->persentase_diskon,
|
||||
'stok_flash_sale' => $flashSaleItem->stok_flash_sale,
|
||||
'aktif' => $flashSaleItem->aktif
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Barang;
|
||||
use App\Models\Pesanan;
|
||||
use App\Models\Transaksi;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class LaporanController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware(\App\Http\Middleware\CheckRole::class . ':admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$totalPendapatanBulanIni = Transaksi::where('status', 'completed')
|
||||
->whereMonth('created_at', Carbon::now()->month)
|
||||
->whereYear('created_at', Carbon::now()->year)
|
||||
->sum('total_pembayaran');
|
||||
|
||||
$totalPendapatanTahunIni = Transaksi::where('status', 'completed')
|
||||
->whereYear('created_at', Carbon::now()->year)
|
||||
->sum('total_pembayaran');
|
||||
|
||||
$totalPesananBulanIni = Pesanan::whereMonth('created_at', Carbon::now()->month)
|
||||
->whereYear('created_at', Carbon::now()->year)
|
||||
->count();
|
||||
|
||||
$totalPelanggan = User::where('role', 'customer')->count();
|
||||
|
||||
return view('admin.laporan.index', compact(
|
||||
'totalPendapatanBulanIni',
|
||||
'totalPendapatanTahunIni',
|
||||
'totalPesananBulanIni',
|
||||
'totalPelanggan'
|
||||
));
|
||||
}
|
||||
|
||||
public function generate(Request $request)
|
||||
{
|
||||
$jenis = $request->input('jenis', 'transaksi');
|
||||
$periode = $request->input('periode', 'bulan-ini');
|
||||
$tanggalMulai = $request->has('tanggal_mulai') ? $request->input('tanggal_mulai') : null;
|
||||
$tanggalSelesai = $request->has('tanggal_selesai') ? $request->input('tanggal_selesai') : null;
|
||||
|
||||
// Menentukan range tanggal berdasarkan periode
|
||||
switch ($periode) {
|
||||
case 'hari-ini':
|
||||
$startDate = Carbon::today();
|
||||
$endDate = Carbon::today()->endOfDay();
|
||||
break;
|
||||
case 'minggu-ini':
|
||||
$startDate = Carbon::now()->startOfWeek();
|
||||
$endDate = Carbon::now()->endOfWeek();
|
||||
break;
|
||||
case 'bulan-ini':
|
||||
$startDate = Carbon::now()->startOfMonth();
|
||||
$endDate = Carbon::now()->endOfMonth();
|
||||
break;
|
||||
case 'custom':
|
||||
$startDate = $tanggalMulai ? Carbon::parse($tanggalMulai) : Carbon::now()->startOfMonth();
|
||||
$endDate = $tanggalSelesai ? Carbon::parse($tanggalSelesai)->endOfDay() : Carbon::now()->endOfMonth();
|
||||
break;
|
||||
default:
|
||||
$startDate = Carbon::now()->startOfMonth();
|
||||
$endDate = Carbon::now()->endOfMonth();
|
||||
}
|
||||
|
||||
if ($jenis == 'transaksi') {
|
||||
$data = Transaksi::with(['user', 'pesanan.barang'])
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->where('status', 'dibayar')
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
$totalPendapatan = $data->where('status', 'dibayar')->sum('total_pembayaran');
|
||||
$totalTransaksi = $data->count();
|
||||
$statusTransaksi = [
|
||||
'pending' => $data->where('status', 'pending')->count(),
|
||||
'paid' => $data->where('status', 'paid')->count(),
|
||||
'completed' => $data->where('status', 'completed')->count(),
|
||||
'cancelled' => $data->where('status', 'cancelled')->count(),
|
||||
];
|
||||
|
||||
return view('admin.laporan.generate', compact(
|
||||
'data',
|
||||
'jenis',
|
||||
'periode',
|
||||
'startDate',
|
||||
'endDate',
|
||||
'totalPendapatan',
|
||||
'totalTransaksi',
|
||||
'statusTransaksi'
|
||||
));
|
||||
} else {
|
||||
// Laporan Barang
|
||||
$data = Barang::withCount(['pesanan' => function ($query) use ($startDate, $endDate) {
|
||||
$query->whereBetween('created_at', [$startDate, $endDate])
|
||||
->where('status', '!=', 'cancelled');
|
||||
}])
|
||||
->orderByDesc('pesanan_count')
|
||||
->get();
|
||||
|
||||
$totalBarang = $data->count();
|
||||
$totalTerjual = $data->sum('pesanan_count');
|
||||
$totalNilai = $data->sum(function($item) {
|
||||
return $item->pesanan_count * $item->harga;
|
||||
});
|
||||
|
||||
return view('admin.laporan.generate', compact(
|
||||
'data',
|
||||
'jenis',
|
||||
'periode',
|
||||
'startDate',
|
||||
'endDate',
|
||||
'totalBarang',
|
||||
'totalTerjual',
|
||||
'totalNilai'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function penjualan(Request $request)
|
||||
{
|
||||
$tahun = $request->input('tahun', Carbon::now()->year);
|
||||
$bulan = $request->input('bulan', Carbon::now()->month);
|
||||
|
||||
$transaksi = Transaksi::where('status', 'completed')
|
||||
->when($bulan !== 'all', function ($query) use ($bulan) {
|
||||
return $query->whereMonth('created_at', $bulan);
|
||||
})
|
||||
->when($tahun, function ($query) use ($tahun) {
|
||||
return $query->whereYear('created_at', $tahun);
|
||||
})
|
||||
->with(['user', 'pesanan'])
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
$pendapatanPerHari = Transaksi::where('status', 'completed')
|
||||
->when($bulan !== 'all', function ($query) use ($bulan) {
|
||||
return $query->whereMonth('created_at', $bulan);
|
||||
})
|
||||
->when($tahun, function ($query) use ($tahun) {
|
||||
return $query->whereYear('created_at', $tahun);
|
||||
})
|
||||
->select(DB::raw('DATE(created_at) as tanggal'), DB::raw('SUM(total_pembayaran) as total'))
|
||||
->groupBy('tanggal')
|
||||
->orderBy('tanggal')
|
||||
->get();
|
||||
|
||||
return view('admin.laporan.penjualan', compact('transaksi', 'pendapatanPerHari', 'tahun', 'bulan'));
|
||||
}
|
||||
|
||||
public function stok()
|
||||
{
|
||||
$barang = Barang::orderBy('stok')->get();
|
||||
|
||||
$kategoriCount = Barang::select('kategori', DB::raw('count(*) as total'))
|
||||
->groupBy('kategori')
|
||||
->orderBy('total', 'desc')
|
||||
->get();
|
||||
|
||||
return view('admin.laporan.stok', compact('barang', 'kategoriCount'));
|
||||
}
|
||||
|
||||
public function transaksi(Request $request)
|
||||
{
|
||||
$status = $request->input('status', 'all');
|
||||
$startDate = $request->input('start_date');
|
||||
$endDate = $request->input('end_date');
|
||||
|
||||
$transaksi = Transaksi::with(['user', 'pesanan'])
|
||||
->when($status !== 'all', function ($query) use ($status) {
|
||||
return $query->where('status', $status);
|
||||
})
|
||||
->when($startDate, function ($query) use ($startDate) {
|
||||
return $query->whereDate('created_at', '>=', $startDate);
|
||||
})
|
||||
->when($endDate, function ($query) use ($endDate) {
|
||||
return $query->whereDate('created_at', '<=', $endDate);
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
$statusCount = [
|
||||
'pending' => Transaksi::where('status', 'pending')->count(),
|
||||
'paid' => Transaksi::where('status', 'paid')->count(),
|
||||
'completed' => Transaksi::where('status', 'completed')->count(),
|
||||
'cancelled' => Transaksi::where('status', 'cancelled')->count(),
|
||||
];
|
||||
|
||||
return view('admin.laporan.transaksi', compact('transaksi', 'statusCount', 'status', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function download(Request $request)
|
||||
{
|
||||
$jenis = $request->input('jenis', 'transaksi');
|
||||
$tanggal_mulai = $request->input('tanggal_mulai');
|
||||
$tanggal_selesai = $request->input('tanggal_selesai');
|
||||
|
||||
$startDate = Carbon::parse($tanggal_mulai);
|
||||
$endDate = Carbon::parse($tanggal_selesai)->endOfDay();
|
||||
|
||||
if ($jenis == 'transaksi') {
|
||||
$data = Transaksi::with(['user', 'pesanan.barang'])
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->where('status', 'dibayar')
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
$totalPendapatan = $data->where('status', 'dibayar')->sum('total_pembayaran');
|
||||
$totalTransaksi = $data->count();
|
||||
|
||||
$filename = 'laporan_' . $jenis . '_' . $startDate->format('dmY') . '_' . $endDate->format('dmY') . '.html';
|
||||
|
||||
return response()
|
||||
->view('admin.laporan.pdf', compact(
|
||||
'jenis',
|
||||
'tanggal_mulai',
|
||||
'tanggal_selesai',
|
||||
'transaksi',
|
||||
'totalPendapatan',
|
||||
'totalTransaksi'
|
||||
))
|
||||
->header('Content-Type', 'text/html')
|
||||
->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||
} else {
|
||||
// Laporan Barang
|
||||
$barang = Barang::withCount(['pesanan' => function ($query) use ($startDate, $endDate) {
|
||||
$query->whereBetween('created_at', [$startDate, $endDate]);
|
||||
}])
|
||||
->orderByDesc('pesanan_count')
|
||||
->get();
|
||||
|
||||
$filename = 'laporan_' . $jenis . '_' . $startDate->format('dmY') . '_' . $endDate->format('dmY') . '.html';
|
||||
|
||||
return response()
|
||||
->view('admin.laporan.pdf', compact(
|
||||
'jenis',
|
||||
'tanggal_mulai',
|
||||
'tanggal_selesai',
|
||||
'barang'
|
||||
))
|
||||
->header('Content-Type', 'text/html')
|
||||
->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Pesanan;
|
||||
use Illuminate\Http\Request;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
|
||||
class PesananController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware(\App\Http\Middleware\CheckRole::class . ':admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$query = Pesanan::with(['user', 'barang']);
|
||||
|
||||
// Filter berdasarkan tanggal
|
||||
if (request('start_date')) {
|
||||
$query->whereDate('created_at', '>=', request('start_date'));
|
||||
}
|
||||
if (request('end_date')) {
|
||||
$query->whereDate('created_at', '<=', request('end_date'));
|
||||
}
|
||||
|
||||
// Filter berdasarkan status
|
||||
if (request('status')) {
|
||||
$query->where('status', request('status'));
|
||||
}
|
||||
|
||||
$pesanan = $query->latest()->paginate(10);
|
||||
return view('admin.pesanan.index', compact('pesanan'));
|
||||
}
|
||||
|
||||
public function show(Pesanan $pesanan)
|
||||
{
|
||||
$pesanan->load(['user', 'barang']);
|
||||
return view('admin.pesanan.show', compact('pesanan'));
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request, Pesanan $pesanan)
|
||||
{
|
||||
$request->validate([
|
||||
'status' => 'required|in:pending,diproses,dikirim,selesai,dibatalkan',
|
||||
]);
|
||||
|
||||
$pesanan->update([
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.pesanan.show', $pesanan)
|
||||
->with('success', 'Status pesanan berhasil diperbarui');
|
||||
}
|
||||
|
||||
public function cetakResi(Pesanan $pesanan)
|
||||
{
|
||||
$pdf = PDF::loadView('admin.pesanan.resi', compact('pesanan'));
|
||||
return $pdf->stream('resi-' . $pesanan->id . '.pdf');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Transaksi;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TransaksiController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware(\App\Http\Middleware\CheckRole::class . ':admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$transaksi = Transaksi::with(['user', 'pesanan'])->latest()->get();
|
||||
return view('admin.transaksi.index', compact('transaksi'));
|
||||
}
|
||||
|
||||
public function show(Transaksi $transaksi)
|
||||
{
|
||||
$transaksi->load(['user', 'pesanan']);
|
||||
return view('admin.transaksi.show', compact('transaksi'));
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request, Transaksi $transaksi)
|
||||
{
|
||||
$request->validate([
|
||||
'status' => 'required|in:pending,paid,completed,cancelled',
|
||||
]);
|
||||
|
||||
$transaksi->update([
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
// Jika transaksi selesai, update status pesanan juga
|
||||
if ($request->status === 'completed') {
|
||||
$transaksi->pesanan->update([
|
||||
'status' => 'completed',
|
||||
]);
|
||||
}
|
||||
|
||||
// Jika transaksi dibatalkan, update status pesanan juga
|
||||
if ($request->status === 'cancelled') {
|
||||
$transaksi->pesanan->update([
|
||||
'status' => 'cancelled',
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.transaksi.show', $transaksi)
|
||||
->with('success', 'Status transaksi berhasil diperbarui');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware(\App\Http\Middleware\CheckRole::class . ':admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$users = User::latest()->get();
|
||||
return view('admin.users.index', compact('users'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.users.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|string|max:255|unique:users',
|
||||
'nama' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:8',
|
||||
'role' => 'required|in:admin,customer',
|
||||
]);
|
||||
|
||||
User::create([
|
||||
'username' => $request->username,
|
||||
'nama' => $request->nama,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
'role' => $request->role,
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.users.index')
|
||||
->with('success', 'User berhasil ditambahkan');
|
||||
}
|
||||
|
||||
public function show(User $user)
|
||||
{
|
||||
return view('admin.users.show', compact('user'));
|
||||
}
|
||||
|
||||
public function edit(User $user)
|
||||
{
|
||||
return view('admin.users.edit', compact('user'));
|
||||
}
|
||||
|
||||
public function update(Request $request, User $user)
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|string|max:255|unique:users,username,' . $user->id,
|
||||
'nama' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users,email,' . $user->id,
|
||||
'role' => 'required|in:admin,customer',
|
||||
]);
|
||||
|
||||
$user->update([
|
||||
'username' => $request->username,
|
||||
'nama' => $request->nama,
|
||||
'email' => $request->email,
|
||||
'role' => $request->role,
|
||||
]);
|
||||
|
||||
if ($request->filled('password')) {
|
||||
$user->update([
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.users.index')
|
||||
->with('success', 'User berhasil diupdate');
|
||||
}
|
||||
|
||||
public function destroy(User $user)
|
||||
{
|
||||
$user->delete();
|
||||
return redirect()->route('admin.users.index')
|
||||
->with('success', 'User berhasil dihapus');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function showLinkRequestForm()
|
||||
{
|
||||
return View::make('auth.passwords.email');
|
||||
}
|
||||
|
||||
public function sendResetLinkEmail(Request $request)
|
||||
{
|
||||
Log::info('Reset Password Request Started', [
|
||||
'email' => $request->email,
|
||||
'request_url' => $request->fullUrl(),
|
||||
'request_method' => $request->method()
|
||||
]);
|
||||
|
||||
try {
|
||||
$request->validate([
|
||||
'email' => ['required', 'email', 'exists:users,email'],
|
||||
]);
|
||||
|
||||
$user = User::where('email', $request->email)->first();
|
||||
|
||||
if (!$user) {
|
||||
Log::error('Email not found', [
|
||||
'email' => $request->email
|
||||
]);
|
||||
return Redirect::back()->withErrors([
|
||||
'email' => ['Email tidak ditemukan dalam sistem kami.'],
|
||||
]);
|
||||
}
|
||||
|
||||
// Generate token reset password
|
||||
$token = Str::random(64);
|
||||
$expiresAt = now()->addHours(24);
|
||||
|
||||
Log::info('Generated reset token', [
|
||||
'email' => $user->email,
|
||||
'token' => $token,
|
||||
'expires_at' => $expiresAt
|
||||
]);
|
||||
|
||||
// Update user dengan token baru
|
||||
$user->reset_password_token = $token;
|
||||
$user->reset_password_expires_at = $expiresAt;
|
||||
$user->save();
|
||||
|
||||
// Verifikasi update berhasil
|
||||
$userAfterUpdate = User::where('email', $user->email)
|
||||
->where('reset_password_token', $token)
|
||||
->first();
|
||||
|
||||
Log::info('Update Result', [
|
||||
'token_stored' => $userAfterUpdate ? $userAfterUpdate->reset_password_token : null,
|
||||
'expires_at_stored' => $userAfterUpdate ? $userAfterUpdate->reset_password_expires_at : null
|
||||
]);
|
||||
|
||||
// Kirim email dengan link reset password
|
||||
Mail::send('auth.passwords.reset-link', ['token' => $token, 'email' => $user->email], function($message) use($user) {
|
||||
$message->to($user->email);
|
||||
$message->subject('Reset Password - DJEE Elektronik');
|
||||
});
|
||||
|
||||
return Redirect::back()->with('status', 'Link reset password telah dikirim ke email Anda. Silakan cek inbox atau folder spam Anda.');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error during password reset request', [
|
||||
'email' => $request->email,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return Redirect::back()->withErrors(['email' => 'Terjadi kesalahan saat memproses permintaan reset password.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function showResetForm($token, $email)
|
||||
{
|
||||
Log::info('Reset Password Form Access', [
|
||||
'email' => $email,
|
||||
'token' => $token,
|
||||
'current_time' => now(),
|
||||
'request_url' => request()->fullUrl()
|
||||
]);
|
||||
|
||||
try {
|
||||
$user = User::where('email', $email)
|
||||
->where('reset_password_token', $token)
|
||||
->where('reset_password_expires_at', '>', now())
|
||||
->first();
|
||||
|
||||
Log::info('Reset Password Query Result', [
|
||||
'user_found' => $user ? true : false,
|
||||
'expires_at' => $user ? $user->reset_password_expires_at : null,
|
||||
'stored_token' => $user ? $user->reset_password_token : null
|
||||
]);
|
||||
|
||||
if (!$user) {
|
||||
Log::error('Invalid or expired reset token', [
|
||||
'email' => $email,
|
||||
'token' => $token
|
||||
]);
|
||||
return Redirect::route('password.request')
|
||||
->withErrors(['email' => 'Link reset password tidak valid atau sudah kadaluarsa.']);
|
||||
}
|
||||
|
||||
return View::make('auth.passwords.reset', [
|
||||
'token' => $token,
|
||||
'email' => $email
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error showing reset form', [
|
||||
'email' => $email,
|
||||
'token' => $token,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return Redirect::route('password.request')
|
||||
->withErrors(['email' => 'Terjadi kesalahan saat memproses permintaan reset password.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function reset(Request $request)
|
||||
{
|
||||
Log::info('Reset Password Attempt', [
|
||||
'email' => $request->email,
|
||||
'token' => $request->token,
|
||||
'current_time' => now(),
|
||||
'request_url' => $request->fullUrl()
|
||||
]);
|
||||
|
||||
try {
|
||||
$request->validate([
|
||||
'token' => 'required',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required|min:8|confirmed',
|
||||
]);
|
||||
|
||||
$user = User::where('email', $request->email)
|
||||
->where('reset_password_token', $request->token)
|
||||
->where('reset_password_expires_at', '>', now())
|
||||
->first();
|
||||
|
||||
Log::info('Reset Password Query Result', [
|
||||
'user_found' => $user ? true : false,
|
||||
'expires_at' => $user ? $user->reset_password_expires_at : null
|
||||
]);
|
||||
|
||||
if (!$user) {
|
||||
Log::error('Invalid or expired reset token during reset', [
|
||||
'email' => $request->email,
|
||||
'token' => $request->token
|
||||
]);
|
||||
return Redirect::back()->withErrors(['email' => 'Link reset password tidak valid atau sudah kadaluarsa.']);
|
||||
}
|
||||
|
||||
// Update password dan hapus token
|
||||
$user->password = Hash::make($request->password);
|
||||
$user->reset_password_token = null;
|
||||
$user->reset_password_expires_at = null;
|
||||
$user->save();
|
||||
|
||||
Log::info('Password reset successful', [
|
||||
'email' => $user->email
|
||||
]);
|
||||
|
||||
return Redirect::route('login')
|
||||
->with('status', 'Password Anda berhasil diubah. Silakan login dengan password baru Anda.');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error during password reset', [
|
||||
'email' => $request->email,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return Redirect::back()->withErrors(['email' => 'Terjadi kesalahan saat mereset password.']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Models\User;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
// Menampilkan form login
|
||||
public function showLoginForm()
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
// Memproses login
|
||||
public function login(Request $request)
|
||||
{
|
||||
// Validasi input
|
||||
$credentials = $request->validate([
|
||||
'username' => ['required', 'string'],
|
||||
'password' => ['required', 'string'],
|
||||
]);
|
||||
|
||||
// Coba login
|
||||
if (Auth::attempt($credentials)) {
|
||||
$user = Auth::user();
|
||||
|
||||
// Cek apakah email sudah diverifikasi
|
||||
if (!$user->is_verified) {
|
||||
Auth::logout();
|
||||
return redirect()->route('login')
|
||||
->with('error', 'Email Anda belum diverifikasi. Silakan cek email Anda untuk link verifikasi. Jika Anda belum menerima email verifikasi, silakan klik link di bawah untuk mengirim ulang.')
|
||||
->with('show_resend', true);
|
||||
}
|
||||
|
||||
// Regenerate session
|
||||
$request->session()->regenerate();
|
||||
|
||||
// Redirect berdasarkan role user
|
||||
if (Auth::user()->role === 'admin') {
|
||||
return redirect()->route('admin.dashboard');
|
||||
}
|
||||
|
||||
// Jika bukan admin, redirect ke dashboard biasa
|
||||
return redirect()->intended(route('dashboard'));
|
||||
}
|
||||
|
||||
// Jika gagal, tampilkan error
|
||||
throw ValidationException::withMessages([
|
||||
'username' => ['Username atau password salah.'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
// 1. Logout user
|
||||
Auth::logout();
|
||||
|
||||
// 2. Invalidate session
|
||||
$request->session()->invalidate();
|
||||
|
||||
// 3. Regenerate CSRF token
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
// 4. Redirect ke login
|
||||
return redirect()->route('login');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required|string|max:255',
|
||||
'username' => 'required|string|max:255|unique:users',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
'nomor_telp' => 'required|string|max:20',
|
||||
'alamat' => 'required|string|max:191',
|
||||
]);
|
||||
|
||||
try {
|
||||
$user = User::create([
|
||||
'nama' => $request->nama,
|
||||
'username' => $request->username,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
'nomor_telp' => $request->nomor_telp,
|
||||
'alamat' => $request->alamat,
|
||||
'role' => 'customer',
|
||||
'verification_token' => Str::random(64),
|
||||
'is_verified' => 0
|
||||
]);
|
||||
|
||||
// Log untuk debug
|
||||
Log::info('User registered successfully', [
|
||||
'user_id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'verification_token' => $user->verification_token
|
||||
]);
|
||||
|
||||
// Kirim email verifikasi
|
||||
$verificationUrl = route('verification.verify', ['token' => $user->verification_token]);
|
||||
Log::info('Generated verification URL', [
|
||||
'url' => $verificationUrl,
|
||||
'token' => $user->verification_token
|
||||
]);
|
||||
|
||||
Mail::send('emails.verify', ['url' => $verificationUrl], function($message) use ($user) {
|
||||
$message->to($user->email);
|
||||
$message->subject('Verifikasi Email');
|
||||
});
|
||||
|
||||
Log::info('Verification email sent', [
|
||||
'user_id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'verification_url' => $verificationUrl
|
||||
]);
|
||||
|
||||
return redirect()->route('login')->with('success', 'Registrasi berhasil! Silakan cek email Anda untuk verifikasi.');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Registration failed', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
return back()->withErrors(['error' => 'Terjadi kesalahan saat registrasi. Silakan coba lagi.']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class VerificationController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
return View::make('auth.verify-email');
|
||||
}
|
||||
|
||||
public function verify(Request $request, $token)
|
||||
{
|
||||
Log::info('Verification attempt started', [
|
||||
'token' => $token,
|
||||
'request_url' => $request->fullUrl(),
|
||||
'request_method' => $request->method(),
|
||||
'request_headers' => $request->headers->all()
|
||||
]);
|
||||
|
||||
try {
|
||||
// Cari user berdasarkan token
|
||||
$user = User::where('verification_token', $token)->first();
|
||||
|
||||
if (!$user) {
|
||||
Log::error('Invalid verification token', [
|
||||
'token' => $token,
|
||||
'request_url' => $request->fullUrl()
|
||||
]);
|
||||
return Redirect::to('/')->with('error', 'Token verifikasi tidak valid.');
|
||||
}
|
||||
|
||||
Log::info('User found for verification', [
|
||||
'user_id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'is_verified' => $user->is_verified
|
||||
]);
|
||||
|
||||
// Update status verifikasi
|
||||
$user->is_verified = 1;
|
||||
$user->verification_token = null; // Hapus token setelah digunakan
|
||||
$user->save();
|
||||
|
||||
Log::info('Email verified successfully', [
|
||||
'user_id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'is_verified' => $user->is_verified
|
||||
]);
|
||||
|
||||
// Login user
|
||||
Auth::login($user);
|
||||
|
||||
return Redirect::to('/')->with('status', 'Email berhasil diverifikasi!');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error during email verification', [
|
||||
'token' => $token,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return Redirect::to('/')->with('error', 'Terjadi kesalahan saat verifikasi email.');
|
||||
}
|
||||
}
|
||||
|
||||
public function resend(Request $request)
|
||||
{
|
||||
if ($request->user()->is_verified) {
|
||||
return Redirect::to('/');
|
||||
}
|
||||
|
||||
// Generate token baru
|
||||
$token = Str::random(64);
|
||||
$request->user()->verification_token = $token;
|
||||
$request->user()->save();
|
||||
|
||||
// Kirim email dengan token baru
|
||||
$verificationUrl = url("/email/verify/{$token}");
|
||||
|
||||
// Kirim email (gunakan sistem email yang sudah ada)
|
||||
\Mail::send('emails.verify', ['url' => $verificationUrl], function($message) use ($request) {
|
||||
$message->to($request->user()->email);
|
||||
$message->subject('Verifikasi Email');
|
||||
});
|
||||
|
||||
return Redirect::back()->with('status', 'Link verifikasi baru telah dikirim ke email Anda.');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Barang;
|
||||
use App\Models\Pesanan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BarangController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth')->except(['index', 'show']);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Barang::latest();
|
||||
|
||||
if ($request->has('kategori')) {
|
||||
$query->where('kategori', $request->kategori);
|
||||
}
|
||||
|
||||
if ($request->has('search')) {
|
||||
$searchTerm = $request->search;
|
||||
$query->where(function($q) use ($searchTerm) {
|
||||
$q->where('nama_barang', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('deskripsi', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('kategori', 'LIKE', "%{$searchTerm}%");
|
||||
});
|
||||
}
|
||||
|
||||
$barang = $query->get();
|
||||
return view('barang.index', compact('barang'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('barang.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'barang_id' => 'required|exists:barang,id',
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
'catatan' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$barang = Barang::findOrFail($request->barang_id);
|
||||
|
||||
// Cek stok
|
||||
if ($barang->stok < $request->jumlah) {
|
||||
return back()->with('error', 'Stok tidak mencukupi');
|
||||
}
|
||||
|
||||
// Buat pesanan
|
||||
$pesanan = Pesanan::create([
|
||||
'user_id' => auth()->id(),
|
||||
'barang_id' => $request->barang_id,
|
||||
'jumlah' => $request->jumlah,
|
||||
'total_harga' => $barang->harga * $request->jumlah,
|
||||
'status' => 'pending',
|
||||
'catatan' => $request->catatan,
|
||||
]);
|
||||
|
||||
// Kurangi stok
|
||||
$barang->update([
|
||||
'stok' => $barang->stok - $request->jumlah
|
||||
]);
|
||||
|
||||
return redirect()->route('pesanan.show', $pesanan)
|
||||
->with('success', 'Pesanan berhasil dibuat');
|
||||
}
|
||||
|
||||
public function show(Barang $barang)
|
||||
{
|
||||
return view('barang.show', compact('barang'));
|
||||
}
|
||||
|
||||
public function edit(Barang $barang)
|
||||
{
|
||||
return view('barang.edit', compact('barang'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Barang $barang)
|
||||
{
|
||||
$request->validate([
|
||||
'nama_barang' => 'required|string|max:255',
|
||||
'deskripsi' => 'nullable|string',
|
||||
'harga' => 'required|numeric|min:0',
|
||||
'stok' => 'required|integer|min:0',
|
||||
'kategori' => 'required|string|in:Lampu,Kipas,Kulkas,TV,Magic Com,Mesin Cuci,Kompor',
|
||||
'gambar' => 'nullable|image|mimes:jpeg,png,jpg|max:2048'
|
||||
]);
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
if ($request->hasFile('gambar')) {
|
||||
// Delete old image
|
||||
if ($barang->gambar) {
|
||||
Storage::disk('public')->delete($barang->gambar);
|
||||
}
|
||||
|
||||
$gambar = $request->file('gambar');
|
||||
// Simpan dengan nama asli
|
||||
$fileName = $gambar->getClientOriginalName();
|
||||
// Pastikan nama file tidak ada spasi dan karakter khusus
|
||||
$fileName = preg_replace('/[^A-Za-z0-9\-\_\.]/', '', $fileName);
|
||||
$path = $gambar->storeAs('products', $fileName, 'public');
|
||||
$data['gambar'] = $path;
|
||||
}
|
||||
|
||||
$barang->update($data);
|
||||
return redirect()->route('barang.index')->with('success', 'Barang berhasil diperbarui');
|
||||
}
|
||||
|
||||
public function destroy(Barang $barang)
|
||||
{
|
||||
if ($barang->gambar) {
|
||||
Storage::disk('public')->delete($barang->gambar);
|
||||
}
|
||||
|
||||
$barang->delete();
|
||||
return redirect()->route('barang.index')->with('success', 'Barang berhasil dihapus');
|
||||
}
|
||||
|
||||
public function checkout(Request $request)
|
||||
{
|
||||
// Cek role user
|
||||
if (Auth::user()->role !== 'customer') {
|
||||
return back()->with('error', 'Anda tidak memiliki akses untuk melakukan checkout');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'barang_id' => 'required|exists:barang,id',
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
'catatan' => 'nullable|string'
|
||||
]);
|
||||
|
||||
$barang = Barang::findOrFail($request->barang_id);
|
||||
|
||||
// Cek stok
|
||||
if ($barang->stok < $request->jumlah) {
|
||||
return back()->with('error', 'Stok tidak mencukupi');
|
||||
}
|
||||
|
||||
$total = $barang->harga * $request->jumlah;
|
||||
|
||||
// Buat pesanan langsung
|
||||
$pesanan = Pesanan::create([
|
||||
'user_id' => Auth::id(),
|
||||
'barang_id' => $request->barang_id,
|
||||
'jumlah' => $request->jumlah,
|
||||
'total_harga' => $total,
|
||||
'status' => 'pending',
|
||||
'catatan' => $request->catatan
|
||||
]);
|
||||
|
||||
// Kurangi stok
|
||||
$barang->update([
|
||||
'stok' => $barang->stok - $request->jumlah
|
||||
]);
|
||||
|
||||
return redirect()->route('pesanan.show', $pesanan)
|
||||
->with('success', 'Pesanan berhasil dibuat');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Barang;
|
||||
use App\Models\Pesanan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'barang_id' => 'required|exists:barang,id',
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$barang = Barang::findOrFail($request->barang_id);
|
||||
|
||||
if ($barang->stok < $request->jumlah) {
|
||||
return redirect()->back()->with('error', 'Stok tidak mencukupi');
|
||||
}
|
||||
|
||||
$total = $barang->harga * $request->jumlah;
|
||||
|
||||
return view('checkout.index', compact('barang', 'total'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'barang_id' => 'required|exists:barang,id',
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
'alamat' => 'required|string',
|
||||
'metode_pembayaran' => 'required|in:transfer_bank,e_wallet',
|
||||
'catatan' => 'nullable|string',
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$barang = Barang::findOrFail($request->barang_id);
|
||||
|
||||
if ($barang->stok < $request->jumlah) {
|
||||
throw new \Exception('Stok tidak mencukupi');
|
||||
}
|
||||
|
||||
$total = $barang->harga * $request->jumlah;
|
||||
|
||||
$pesanan = Pesanan::create([
|
||||
'user_id' => Auth::id(),
|
||||
'barang_id' => $barang->id,
|
||||
'jumlah' => $request->jumlah,
|
||||
'total_harga' => $total,
|
||||
'status' => 'menunggu_pembayaran',
|
||||
'alamat_pengiriman' => $request->alamat,
|
||||
'metode_pembayaran' => $request->metode_pembayaran,
|
||||
'catatan' => $request->catatan,
|
||||
]);
|
||||
|
||||
$barang->update([
|
||||
'stok' => $barang->stok - $request->jumlah
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('pesanan.show', $pesanan->id)
|
||||
->with('success', 'Pesanan berhasil dibuat. Silakan lakukan pembayaran.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return redirect()->back()
|
||||
->with('error', 'Terjadi kesalahan: ' . $e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Barang;
|
||||
use App\Models\Pesanan;
|
||||
use App\Models\Transaksi;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\Banner;
|
||||
use App\Models\FlashSale;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// Pastikan user sudah login
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Get user's data
|
||||
$user = Auth::user();
|
||||
|
||||
// Get statistics
|
||||
$totalBarang = Barang::count();
|
||||
$totalPesanan = Pesanan::where('user_id', $user->id)->count();
|
||||
$totalTransaksi = Transaksi::where('user_id', $user->id)->count();
|
||||
|
||||
// Get recent orders
|
||||
$pesanan = Pesanan::with(['barang'])
|
||||
->where('user_id', $user->id)
|
||||
->latest()
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
// Get pending orders count
|
||||
$pesananPending = Pesanan::where('user_id', $user->id)
|
||||
->where('status', 'pending')
|
||||
->count();
|
||||
|
||||
// $banners = Banner::where('aktif', true)
|
||||
// ->orderBy('urutan', 'asc')
|
||||
// ->get();
|
||||
|
||||
// $activeFlashSale = FlashSale::with(['items' => function($query) {
|
||||
// $query->where('aktif', true)
|
||||
// ->whereHas('barang');
|
||||
// }, 'items.barang'])
|
||||
// ->where('aktif', true)
|
||||
// ->whereDate('waktu_mulai', '<=', Carbon::now())
|
||||
// ->whereDate('waktu_selesai', '>=', Carbon::now())
|
||||
// ->first();
|
||||
|
||||
return view('dashboard.index', compact(
|
||||
'totalBarang',
|
||||
'totalPesanan',
|
||||
'totalTransaksi',
|
||||
'pesanan',
|
||||
'pesananPending'
|
||||
));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,682 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Barang;
|
||||
use App\Models\Keranjang;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class KeranjangController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display keranjang belanja user
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$items = Keranjang::with('barang')
|
||||
->where('user_id', Auth::id())
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
$total = $items->sum('total_harga');
|
||||
|
||||
// Jika ini adalah request verifikasi, kirim respons khusus tanpa view
|
||||
if ($request->has('verify')) {
|
||||
// Kirim data sebagai JSON jika diminta
|
||||
if ($request->ajax()) {
|
||||
return response()->json([
|
||||
'items' => $items->map(function($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'jumlah' => $item->jumlah,
|
||||
'total_harga' => $item->total_harga,
|
||||
'harga_satuan' => $item->barang->harga
|
||||
];
|
||||
}),
|
||||
'total' => $total,
|
||||
'timestamp' => now()->timestamp
|
||||
]);
|
||||
}
|
||||
|
||||
// Jika bukan request AJAX, kirim respons sederhana
|
||||
return response('OK', 200);
|
||||
}
|
||||
|
||||
return view('keranjang.index', compact('items', 'total'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tambah item ke keranjang
|
||||
*/
|
||||
public function tambah(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'barang_id' => 'required|exists:barang,id',
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$barang = Barang::findOrFail($request->barang_id);
|
||||
|
||||
// Validasi stok
|
||||
if ($request->jumlah > $barang->stok) {
|
||||
return redirect()->back()
|
||||
->with('error', 'Jumlah melebihi stok yang tersedia');
|
||||
}
|
||||
|
||||
// Cek jika barang sudah ada di keranjang
|
||||
$item = Keranjang::where('user_id', Auth::id())
|
||||
->where('barang_id', $request->barang_id)
|
||||
->first();
|
||||
|
||||
if ($item) {
|
||||
// Update jumlah dan total harga
|
||||
$newJumlah = $item->jumlah + $request->jumlah;
|
||||
|
||||
// Cek stok sekali lagi
|
||||
if ($newJumlah > $barang->stok) {
|
||||
return redirect()->back()
|
||||
->with('error', 'Total jumlah melebihi stok yang tersedia');
|
||||
}
|
||||
|
||||
$item->jumlah = $newJumlah;
|
||||
$item->total_harga = $barang->harga * $newJumlah;
|
||||
$item->save();
|
||||
} else {
|
||||
// Buat item baru di keranjang
|
||||
Keranjang::create([
|
||||
'user_id' => Auth::id(),
|
||||
'barang_id' => $request->barang_id,
|
||||
'jumlah' => $request->jumlah,
|
||||
'total_harga' => $barang->harga * $request->jumlah,
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('success', 'Barang berhasil ditambahkan ke keranjang');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update jumlah item di keranjang
|
||||
*/
|
||||
public function update(Request $request, Keranjang $keranjang)
|
||||
{
|
||||
// Logging untuk debugging request method
|
||||
\Log::debug('Update Keranjang Request: ', [
|
||||
'method' => $request->method(),
|
||||
'real_method' => $request->getRealMethod(),
|
||||
'has_method_field' => $request->has('_method'),
|
||||
'method_field' => $request->input('_method'),
|
||||
'route' => $request->route()->getName(),
|
||||
'item_id' => $keranjang->id,
|
||||
'user_id' => Auth::id()
|
||||
]);
|
||||
|
||||
$request->validate([
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
// Validasi kepemilikan dengan logging
|
||||
if ($keranjang->user_id !== Auth::id()) {
|
||||
\Log::warning('Akses tidak sah: User '.Auth::id().' mencoba mengakses keranjang '.$keranjang->id.' milik user '.$keranjang->user_id);
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => false, 'message' => 'Tidak diizinkan'], 403);
|
||||
}
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$barang = $keranjang->barang;
|
||||
|
||||
// Validasi stok
|
||||
if ($request->jumlah > $barang->stok) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => false, 'message' => 'Jumlah melebihi stok yang tersedia']);
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', 'Jumlah melebihi stok yang tersedia');
|
||||
}
|
||||
|
||||
// Deteksi apakah ini request konfirmasi
|
||||
$isConfirm = $request->has('is_confirm_submit');
|
||||
|
||||
// Prioritaskan request konfirmasi atau nonaktifkan cache di browser
|
||||
// Pastikan perubahan tersimpan ke database dalam semua kasus
|
||||
$keranjang->jumlah = $request->jumlah;
|
||||
$keranjang->total_harga = $barang->harga * $request->jumlah;
|
||||
$result = $keranjang->save();
|
||||
|
||||
// Log untuk debugging
|
||||
\Log::info('Keranjang diupdate: ID=' . $keranjang->id .
|
||||
', Jumlah=' . $request->jumlah .
|
||||
', IsConfirm=' . ($isConfirm ? 'Ya' : 'Tidak') .
|
||||
', Hasil=' . ($result ? 'Sukses' : 'Gagal'));
|
||||
|
||||
// Handle jika ini adalah iframe request
|
||||
if ($request->has('is_js_request')) {
|
||||
// Kembalikan HTML minimal untuk iframe
|
||||
return response('<html><body><script>parent.postMessage("update_success", "*");</script></body></html>');
|
||||
}
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Keranjang berhasil diperbarui',
|
||||
'total_harga' => $keranjang->total_harga,
|
||||
'jumlah' => $keranjang->jumlah
|
||||
]);
|
||||
}
|
||||
|
||||
// Jika ini request konfirmasi, buat respons khusus yang mengindikasikan sukses
|
||||
if ($isConfirm) {
|
||||
return response()->json(['success' => true, 'confirmed' => true]);
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('success', 'Keranjang berhasil diperbarui');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus item dari keranjang
|
||||
*/
|
||||
public function hapus(Request $request, Keranjang $keranjang)
|
||||
{
|
||||
try {
|
||||
// Debug logging
|
||||
\Log::debug('Mencoba menghapus keranjang: ID=' . $keranjang->id .
|
||||
', Auth::id()=' . Auth::id() .
|
||||
', keranjang->user_id=' . $keranjang->user_id .
|
||||
', sama=' . ((Auth::id() === $keranjang->user_id) ? 'Ya' : 'Tidak'));
|
||||
|
||||
// Log semua parameter request
|
||||
\Log::debug('Request data: ' . json_encode($request->all()));
|
||||
|
||||
// Validasi kepemilikan dengan logging
|
||||
if ($keranjang->user_id !== Auth::id()) {
|
||||
\Log::warning('Akses tidak sah: User '.Auth::id().' mencoba menghapus keranjang '.$keranjang->id.' milik user '.$keranjang->user_id);
|
||||
|
||||
if ($request->ajax() || $request->has('is_js_request')) {
|
||||
return response('<html><body><script>parent.postMessage("delete_error", "*");</script></body></html>');
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Anda tidak memiliki izin untuk menghapus item ini');
|
||||
}
|
||||
|
||||
// Simpan informasi untuk log
|
||||
$id = $keranjang->id;
|
||||
$userId = $keranjang->user_id;
|
||||
|
||||
// Hapus item dari keranjang
|
||||
$result = $keranjang->delete();
|
||||
|
||||
// Log untuk debugging
|
||||
\Log::info('Keranjang dihapus: ID=' . $id .
|
||||
', User=' . $userId .
|
||||
', Route=' . $request->route()->getName() .
|
||||
', Method=' . $request->method() .
|
||||
', Hasil=' . ($result ? 'Sukses' : 'Gagal'));
|
||||
|
||||
// Handle jika ini adalah iframe request
|
||||
if ($request->has('is_js_request') || $request->has('_ts')) {
|
||||
// Kembalikan HTML minimal untuk iframe
|
||||
return response('<html><body><script>parent.postMessage("delete_success", "*");</script></body></html>');
|
||||
}
|
||||
|
||||
// Jika ini adalah request AJAX
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => true, 'message' => 'Item berhasil dihapus']);
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('success', 'Item berhasil dihapus dari keranjang');
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Error saat menghapus keranjang: ' . $e->getMessage());
|
||||
|
||||
// Handle jika ini adalah iframe request
|
||||
if ($request->has('is_js_request') || $request->has('_ts')) {
|
||||
// Kembalikan HTML minimal untuk iframe dengan pesan error
|
||||
return response('<html><body><script>parent.postMessage("delete_error", "*");</script></body></html>');
|
||||
}
|
||||
|
||||
// Jika ini adalah request AJAX
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal menghapus item: ' . $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Gagal menghapus item: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kosongkan keranjang
|
||||
*/
|
||||
public function kosongkan()
|
||||
{
|
||||
Keranjang::where('user_id', Auth::id())->delete();
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('success', 'Keranjang berhasil dikosongkan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout semua item di keranjang
|
||||
*/
|
||||
public function checkout(Request $request)
|
||||
{
|
||||
// Jika ada parameter selected_items, gunakan itu (bisa dari GET)
|
||||
if ($request->has('selected_items')) {
|
||||
return $this->checkoutSelected($request);
|
||||
}
|
||||
|
||||
// Jika tidak ada parameter, cek session untuk item terpilih
|
||||
if (session()->has('selected_keranjang_items')) {
|
||||
$selectedIds = session('selected_keranjang_items');
|
||||
$items = Keranjang::with('barang')
|
||||
->where('user_id', Auth::id())
|
||||
->whereIn('id', $selectedIds)
|
||||
->get();
|
||||
|
||||
if ($items->isNotEmpty()) {
|
||||
$total = $items->sum('total_harga');
|
||||
$total_weight = $items->sum(function($item) {
|
||||
return $item->barang->berat * $item->jumlah;
|
||||
});
|
||||
return view('keranjang.checkout', compact('items', 'total', 'selectedIds', 'total_weight'));
|
||||
}
|
||||
}
|
||||
|
||||
// Default: checkout semua item
|
||||
$items = Keranjang::with('barang')
|
||||
->where('user_id', Auth::id())
|
||||
->get();
|
||||
|
||||
if ($items->isEmpty()) {
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Keranjang Anda kosong');
|
||||
}
|
||||
|
||||
$total = $items->sum('total_harga');
|
||||
$total_weight = $items->sum(function($item) {
|
||||
return $item->barang->berat * $item->jumlah;
|
||||
});
|
||||
|
||||
return view('keranjang.checkout', compact('items', 'total', 'total_weight'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout semua item terpilih di keranjang
|
||||
*/
|
||||
public function checkoutSelected(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'selected_items' => 'required|array',
|
||||
'selected_items.*' => 'exists:keranjang,id',
|
||||
'jumlah' => 'nullable|array',
|
||||
]);
|
||||
|
||||
$selectedIds = $request->selected_items;
|
||||
$items = Keranjang::with('barang')
|
||||
->where('user_id', Auth::id())
|
||||
->whereIn('id', $selectedIds)
|
||||
->get();
|
||||
|
||||
if ($items->isEmpty()) {
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Tidak ada item yang dipilih');
|
||||
}
|
||||
|
||||
// Update jumlah item jika ada perubahan
|
||||
if ($request->has('jumlah')) {
|
||||
foreach ($items as $item) {
|
||||
if (isset($request->jumlah[$item->id]) && $request->jumlah[$item->id] != $item->jumlah) {
|
||||
// Validasi stok
|
||||
if ($request->jumlah[$item->id] > $item->barang->stok) {
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Jumlah ' . $item->barang->nama_barang . ' melebihi stok yang tersedia');
|
||||
}
|
||||
|
||||
// Update jumlah dan total harga
|
||||
$item->jumlah = $request->jumlah[$item->id];
|
||||
$item->total_harga = $item->barang->harga * $item->jumlah;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$total = $items->sum('total_harga');
|
||||
$total_weight = $items->sum(function($item) {
|
||||
return $item->barang->berat * $item->jumlah;
|
||||
});
|
||||
|
||||
return view('keranjang.checkout', compact('items', 'total', 'selectedIds', 'total_weight'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus item terpilih dari keranjang
|
||||
*/
|
||||
public function hapusSelected(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'selected_items' => 'required|array',
|
||||
'selected_items.*' => 'exists:keranjang,id',
|
||||
]);
|
||||
|
||||
$count = Keranjang::where('user_id', Auth::id())
|
||||
->whereIn('id', $request->selected_items)
|
||||
->delete();
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('success', $count . ' item berhasil dihapus dari keranjang');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus item dari keranjang dengan ID manual
|
||||
*/
|
||||
public function hapusManual(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'id' => 'required|integer|exists:keranjang,id',
|
||||
]);
|
||||
|
||||
$id = $request->input('id');
|
||||
|
||||
// Ambil keranjang berdasarkan ID dan user_id
|
||||
$keranjang = Keranjang::where('id', $id)
|
||||
->where('user_id', Auth::id())
|
||||
->first();
|
||||
|
||||
if (!$keranjang) {
|
||||
\Log::warning('Akses tidak sah: User '.Auth::id().' mencoba menghapus keranjang '.$id.' yang tidak ditemukan atau bukan miliknya');
|
||||
|
||||
if ($request->ajax() || $request->has('is_js_request')) {
|
||||
return response('<html><body><script>parent.postMessage("delete_error", "*");</script></body></html>');
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Item tidak ditemukan atau bukan milik Anda');
|
||||
}
|
||||
|
||||
// Debug logging
|
||||
\Log::debug('Hapus Manual: ID=' . $keranjang->id .
|
||||
', Auth::id()=' . Auth::id() .
|
||||
', keranjang->user_id=' . $keranjang->user_id);
|
||||
|
||||
// Hapus item dari keranjang
|
||||
$result = $keranjang->delete();
|
||||
|
||||
// Log untuk debugging
|
||||
\Log::info('Keranjang dihapus (manual): ID=' . $id .
|
||||
', User=' . Auth::id() .
|
||||
', Method=' . $request->method() .
|
||||
', Hasil=' . ($result ? 'Sukses' : 'Gagal'));
|
||||
|
||||
// Handle jika ini adalah iframe request
|
||||
if ($request->has('is_js_request') || $request->has('_ts')) {
|
||||
// Kembalikan HTML minimal untuk iframe
|
||||
return response('<html><body><script>parent.postMessage("delete_success", "*");</script></body></html>');
|
||||
}
|
||||
|
||||
// Jika ini adalah request AJAX
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => true, 'message' => 'Item berhasil dihapus']);
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('success', 'Item berhasil dihapus dari keranjang');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Error saat menghapus keranjang manual: ' . $e->getMessage());
|
||||
|
||||
// Handle jika ini adalah iframe request
|
||||
if ($request->has('is_js_request') || $request->has('_ts')) {
|
||||
// Kembalikan HTML minimal untuk iframe dengan pesan error
|
||||
return response('<html><body><script>parent.postMessage("delete_error", "*");</script></body></html>');
|
||||
}
|
||||
|
||||
// Jika ini adalah request AJAX
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => false, 'message' => 'Gagal menghapus item: ' . $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Gagal menghapus item: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus item dari keranjang secara langsung dengan debugging total
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function hapusDirect(Request $request)
|
||||
{
|
||||
// Set header content type untuk memastikan respons JSON yang benar
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
\Log::debug('====== DEBUG HAPUS DIRECT MULAI ======');
|
||||
\Log::debug('User ID dari Auth: ' . Auth::id());
|
||||
|
||||
// Tangani semua jenis request (JSON atau form)
|
||||
if ($request->isJson()) {
|
||||
$data = $request->json()->all();
|
||||
\Log::debug('Request adalah JSON: ' . json_encode($data));
|
||||
} else {
|
||||
$data = $request->all();
|
||||
\Log::debug('Request adalah form data: ' . json_encode($data));
|
||||
}
|
||||
|
||||
// Validasi minimal
|
||||
$id = $data['id'] ?? null;
|
||||
if (!$id) {
|
||||
\Log::debug('ID tidak ditemukan dalam request');
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID tidak valid'
|
||||
], 400);
|
||||
}
|
||||
|
||||
\Log::debug('ID keranjang untuk dihapus: ' . $id);
|
||||
|
||||
try {
|
||||
// Hapus item dengan query builder untuk menghindari masalah model binding
|
||||
$result = \DB::table('keranjang')->where('id', $id)->delete();
|
||||
\Log::debug('Hasil penghapusan dengan query builder: ' . ($result ? 'BERHASIL' : 'GAGAL'));
|
||||
} catch (\Exception $dbException) {
|
||||
\Log::error('Database error: ' . $dbException->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Database error: ' . $dbException->getMessage(),
|
||||
'error_type' => 'database_error'
|
||||
], 500);
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
\Log::debug('====== DEBUG HAPUS DIRECT SELESAI (SUKSES) ======');
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Item berhasil dihapus (mode debug)',
|
||||
'debug_info' => [
|
||||
'user_id' => Auth::id(),
|
||||
'item_id' => $id,
|
||||
'deleted' => true,
|
||||
'time' => now()->toDateTimeString()
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
\Log::debug('====== DEBUG HAPUS DIRECT SELESAI (GAGAL) ======');
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghapus item'
|
||||
], 404); // Gunakan 404 jika item tidak ditemukan
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error('Exception: ' . $e->getMessage());
|
||||
\Log::error($e->getTraceAsString());
|
||||
\Log::debug('====== DEBUG HAPUS DIRECT SELESAI (ERROR) ======');
|
||||
|
||||
// Kembalikan respons JSON yang valid, meskipun terjadi error
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan: ' . $e->getMessage(),
|
||||
'error_type' => 'exception'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update jumlah item di keranjang secara langsung
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function updateDirect(Request $request)
|
||||
{
|
||||
// Set header content type untuk memastikan respons JSON yang benar
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
\Log::debug('====== DEBUG UPDATE DIRECT MULAI ======');
|
||||
\Log::debug('User ID dari Auth: ' . Auth::id());
|
||||
|
||||
// Tangani semua jenis request (JSON atau form)
|
||||
if ($request->isJson()) {
|
||||
$data = $request->json()->all();
|
||||
\Log::debug('Request adalah JSON: ' . json_encode($data));
|
||||
} else {
|
||||
$data = $request->all();
|
||||
\Log::debug('Request adalah form data: ' . json_encode($data));
|
||||
}
|
||||
|
||||
// Validasi minimal
|
||||
$id = $data['id'] ?? null;
|
||||
$jumlah = $data['jumlah'] ?? null;
|
||||
|
||||
if (!$id || !$jumlah) {
|
||||
\Log::debug('ID atau jumlah tidak ditemukan dalam request');
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'ID atau jumlah tidak valid'
|
||||
], 400);
|
||||
}
|
||||
|
||||
\Log::debug('ID keranjang: ' . $id . ', jumlah baru: ' . $jumlah);
|
||||
|
||||
// Ambil item keranjang
|
||||
$keranjang = Keranjang::where('id', $id)
|
||||
->where('user_id', Auth::id())
|
||||
->first();
|
||||
|
||||
if (!$keranjang) {
|
||||
\Log::debug('Item keranjang tidak ditemukan atau bukan milik user ini');
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Item tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Validasi stok
|
||||
$barang = $keranjang->barang;
|
||||
if ($jumlah > $barang->stok) {
|
||||
\Log::debug('Jumlah melebihi stok tersedia: ' . $barang->stok);
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Jumlah melebihi stok yang tersedia'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Update jumlah dan total harga
|
||||
$keranjang->jumlah = $jumlah;
|
||||
$keranjang->total_harga = $barang->harga * $jumlah;
|
||||
$result = $keranjang->save();
|
||||
|
||||
\Log::debug('Hasil update: ' . ($result ? 'BERHASIL' : 'GAGAL'));
|
||||
\Log::debug('====== DEBUG UPDATE DIRECT SELESAI (SUKSES) ======');
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Jumlah berhasil diperbarui',
|
||||
'data' => [
|
||||
'id' => $keranjang->id,
|
||||
'jumlah' => $keranjang->jumlah,
|
||||
'total_harga' => $keranjang->total_harga,
|
||||
'harga_satuan' => $barang->harga
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error('Exception: ' . $e->getMessage());
|
||||
\Log::error($e->getTraceAsString());
|
||||
\Log::debug('====== DEBUG UPDATE DIRECT SELESAI (ERROR) ======');
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan: ' . $e->getMessage(),
|
||||
'error_type' => 'exception'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update jumlah item di keranjang dengan form tradisional (fallback)
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateFallback(Request $request)
|
||||
{
|
||||
try {
|
||||
\Log::debug('====== UPDATE FALLBACK ======');
|
||||
\Log::debug('User ID: ' . Auth::id());
|
||||
\Log::debug('Request data: ' . json_encode($request->all()));
|
||||
|
||||
// Validasi minimal
|
||||
$request->validate([
|
||||
'id' => 'required|integer|exists:keranjang,id',
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
// Ambil item keranjang
|
||||
$keranjang = Keranjang::where('id', $request->id)
|
||||
->where('user_id', Auth::id())
|
||||
->first();
|
||||
|
||||
if (!$keranjang) {
|
||||
\Log::debug('Item keranjang tidak ditemukan atau bukan milik user ini');
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Item tidak ditemukan');
|
||||
}
|
||||
|
||||
// Validasi stok
|
||||
$barang = $keranjang->barang;
|
||||
if ($request->jumlah > $barang->stok) {
|
||||
\Log::debug('Jumlah melebihi stok tersedia: ' . $barang->stok);
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Jumlah melebihi stok yang tersedia');
|
||||
}
|
||||
|
||||
// Update jumlah dan total harga
|
||||
$keranjang->jumlah = $request->jumlah;
|
||||
$keranjang->total_harga = $barang->harga * $request->jumlah;
|
||||
$result = $keranjang->save();
|
||||
|
||||
\Log::debug('Hasil update: ' . ($result ? 'BERHASIL' : 'GAGAL'));
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('success', 'Jumlah berhasil diperbarui');
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error('Exception: ' . $e->getMessage());
|
||||
\Log::error($e->getTraceAsString());
|
||||
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Terjadi kesalahan: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Ongkir;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LocationController extends Controller
|
||||
{
|
||||
public function getProvinces()
|
||||
{
|
||||
try {
|
||||
$provinces = Ongkir::select('province_id', 'province_name')
|
||||
->distinct()
|
||||
->orderBy('province_name')
|
||||
->get();
|
||||
|
||||
return response()->json($provinces);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error getting provinces:', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return response()->json([
|
||||
'error' => 'Gagal mengambil data provinsi',
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCities(Request $request)
|
||||
{
|
||||
try {
|
||||
$cities = Ongkir::where('province_id', $request->province_id)
|
||||
->select('city_id', 'city_name')
|
||||
->distinct()
|
||||
->orderBy('city_name')
|
||||
->get();
|
||||
|
||||
return response()->json($cities);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error getting cities:', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return response()->json([
|
||||
'error' => 'Gagal mengambil data kota',
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function calculateCost(Request $request)
|
||||
{
|
||||
try {
|
||||
$ongkir = Ongkir::where('province_id', $request->province_id)
|
||||
->where('city_id', $request->city_id)
|
||||
->first();
|
||||
|
||||
if (!$ongkir) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data ongkos kirim tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$shippingOptions = [];
|
||||
|
||||
// JNE Options
|
||||
if ($ongkir->jne_reg) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'JNE Regular',
|
||||
'description' => 'Pengiriman reguler menggunakan JNE',
|
||||
'cost' => $ongkir->jne_reg,
|
||||
'etd' => '2-3'
|
||||
];
|
||||
}
|
||||
if ($ongkir->jne_oke) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'JNE OKE',
|
||||
'description' => 'Pengiriman ekonomis menggunakan JNE',
|
||||
'cost' => $ongkir->jne_oke,
|
||||
'etd' => '3-4'
|
||||
];
|
||||
}
|
||||
if ($ongkir->jne_yes) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'JNE YES',
|
||||
'description' => 'Pengiriman cepat menggunakan JNE',
|
||||
'cost' => $ongkir->jne_yes,
|
||||
'etd' => '1-2'
|
||||
];
|
||||
}
|
||||
|
||||
// POS Options
|
||||
if ($ongkir->pos_reg) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'POS Regular',
|
||||
'description' => 'Pengiriman reguler menggunakan POS Indonesia',
|
||||
'cost' => $ongkir->pos_reg,
|
||||
'etd' => '3-4'
|
||||
];
|
||||
}
|
||||
if ($ongkir->pos_express) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'POS Express',
|
||||
'description' => 'Pengiriman cepat menggunakan POS Indonesia',
|
||||
'cost' => $ongkir->pos_express,
|
||||
'etd' => '2-3'
|
||||
];
|
||||
}
|
||||
|
||||
// TIKI Options
|
||||
if ($ongkir->tiki_reg) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'TIKI Regular',
|
||||
'description' => 'Pengiriman reguler menggunakan TIKI',
|
||||
'cost' => $ongkir->tiki_reg,
|
||||
'etd' => '2-3'
|
||||
];
|
||||
}
|
||||
if ($ongkir->tiki_eco) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'TIKI ECO',
|
||||
'description' => 'Pengiriman ekonomis menggunakan TIKI',
|
||||
'cost' => $ongkir->tiki_eco,
|
||||
'etd' => '3-4'
|
||||
];
|
||||
}
|
||||
if ($ongkir->tiki_express) {
|
||||
$shippingOptions[] = [
|
||||
'service' => 'TIKI Express',
|
||||
'description' => 'Pengiriman cepat menggunakan TIKI',
|
||||
'cost' => $ongkir->tiki_express,
|
||||
'etd' => '1-2'
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($shippingOptions)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Tidak ada opsi pengiriman yang tersedia'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'options' => $shippingOptions
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error calculating cost:', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghitung ongkos kirim',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,376 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Pesanan;
|
||||
use App\Models\Barang;
|
||||
use App\Models\Keranjang;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use App\Models\Transaksi;
|
||||
|
||||
class PesananController extends Controller
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$query = Pesanan::with(['user', 'barang'])
|
||||
->where('user_id', Auth::id());
|
||||
|
||||
// Filter berdasarkan tanggal
|
||||
if (request('start_date')) {
|
||||
$query->whereDate('created_at', '>=', request('start_date'));
|
||||
}
|
||||
if (request('end_date')) {
|
||||
$query->whereDate('created_at', '<=', request('end_date'));
|
||||
}
|
||||
|
||||
// Filter berdasarkan status
|
||||
if (request('status')) {
|
||||
$query->where('status', request('status'));
|
||||
}
|
||||
|
||||
$pesanan = $query->latest()->paginate(10);
|
||||
return view('pesanan.index', compact('pesanan'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$barang = Barang::where('stok', '>', 0)->get();
|
||||
return view('pesanan.create', compact('barang'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'barang_id' => 'required|exists:barang,id',
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
'catatan' => 'nullable|string'
|
||||
]);
|
||||
|
||||
$barang = Barang::findOrFail($request->barang_id);
|
||||
|
||||
if ($barang->stok < $request->jumlah) {
|
||||
return back()->with('error', 'Stok tidak mencukupi');
|
||||
}
|
||||
|
||||
// Cek apakah sudah ada pesanan pending untuk barang yang sama
|
||||
$existingPesanan = Pesanan::where('user_id', Auth::id())
|
||||
->where('barang_id', $request->barang_id)
|
||||
->where('status', 'pending')
|
||||
->first();
|
||||
|
||||
if ($existingPesanan) {
|
||||
// Update jumlah pesanan yang ada
|
||||
$newJumlah = $existingPesanan->jumlah + $request->jumlah;
|
||||
|
||||
if ($barang->stok < $newJumlah) {
|
||||
return back()->with('error', 'Stok tidak mencukupi untuk total pesanan');
|
||||
}
|
||||
|
||||
$existingPesanan->update([
|
||||
'jumlah' => $newJumlah,
|
||||
'total_harga' => $barang->harga * $newJumlah,
|
||||
'catatan' => $request->catatan ?? $existingPesanan->catatan
|
||||
]);
|
||||
|
||||
// Kurangi stok barang
|
||||
$barang->update([
|
||||
'stok' => $barang->stok - $request->jumlah
|
||||
]);
|
||||
|
||||
return redirect()->route('pesanan.index')->with('success', 'Pesanan berhasil diperbarui');
|
||||
}
|
||||
|
||||
// Jika tidak ada pesanan yang sama, buat pesanan baru
|
||||
$total_harga = $barang->harga * $request->jumlah;
|
||||
|
||||
$pesanan = Pesanan::create([
|
||||
'user_id' => Auth::id(),
|
||||
'barang_id' => $request->barang_id,
|
||||
'jumlah' => $request->jumlah,
|
||||
'total_harga' => $total_harga,
|
||||
'status' => 'pending',
|
||||
'catatan' => $request->catatan
|
||||
]);
|
||||
|
||||
// Kurangi stok barang
|
||||
$barang->update([
|
||||
'stok' => $barang->stok - $request->jumlah
|
||||
]);
|
||||
|
||||
return redirect()->route('pesanan.index')->with('success', 'Pesanan berhasil dibuat');
|
||||
}
|
||||
|
||||
public function show(Pesanan $pesanan)
|
||||
{
|
||||
$pesanan->load(['user', 'barang', 'items.barang']);
|
||||
return view('pesanan.show', compact('pesanan'));
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request, Pesanan $pesanan)
|
||||
{
|
||||
$request->validate([
|
||||
'status' => 'required|in:pending,diproses,dikirim,selesai,dibatalkan'
|
||||
]);
|
||||
|
||||
$pesanan->update(['status' => $request->status]);
|
||||
|
||||
// Jika pesanan dibatalkan, kembalikan stok
|
||||
if ($request->status === 'dibatalkan') {
|
||||
$pesanan->barang->update([
|
||||
'stok' => $pesanan->barang->stok + $pesanan->jumlah
|
||||
]);
|
||||
}
|
||||
|
||||
return back()->with('success', 'Status pesanan berhasil diperbarui');
|
||||
}
|
||||
|
||||
public function destroy(Pesanan $pesanan)
|
||||
{
|
||||
try {
|
||||
// Kembalikan stok
|
||||
$pesanan->barang->update([
|
||||
'stok' => $pesanan->barang->stok + $pesanan->jumlah
|
||||
]);
|
||||
|
||||
// Hapus pesanan
|
||||
$pesanan->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pesanan berhasil dibatalkan'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Terjadi kesalahan saat membatalkan pesanan'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function createFromBarang(Barang $barang)
|
||||
{
|
||||
if ($barang->stok <= 0) {
|
||||
return back()->with('error', 'Maaf, stok barang tidak tersedia');
|
||||
}
|
||||
|
||||
return view('pesanan.create-from-barang', compact('barang'));
|
||||
}
|
||||
|
||||
public function edit(Pesanan $pesanan)
|
||||
{
|
||||
// Pastikan user hanya bisa mengedit pesanannya sendiri
|
||||
if ($pesanan->user_id !== Auth::id()) {
|
||||
return abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
// Pastikan hanya pesanan dengan status pending yang bisa diedit
|
||||
if ($pesanan->status !== 'pending') {
|
||||
return redirect()->route('pesanan.index')
|
||||
->with('error', 'Hanya pesanan dengan status pending yang dapat diedit');
|
||||
}
|
||||
|
||||
return view('pesanan.edit', compact('pesanan'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Pesanan $pesanan)
|
||||
{
|
||||
// Validasi user
|
||||
if ($pesanan->user_id !== Auth::id()) {
|
||||
return abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
// Validasi status
|
||||
if ($pesanan->status !== 'pending') {
|
||||
return redirect()->route('pesanan.index')
|
||||
->with('error', 'Hanya pesanan dengan status pending yang dapat diubah');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'jumlah' => 'required|integer|min:1',
|
||||
'catatan' => 'nullable|string'
|
||||
]);
|
||||
|
||||
$barang = $pesanan->barang;
|
||||
$stokTersedia = $barang->stok + $pesanan->jumlah; // Stok saat ini + jumlah pesanan yang akan diubah
|
||||
|
||||
if ($request->jumlah > $stokTersedia) {
|
||||
return back()->with('error', 'Stok tidak mencukupi');
|
||||
}
|
||||
|
||||
// Hitung selisih stok
|
||||
$selisihStok = $pesanan->jumlah - $request->jumlah;
|
||||
|
||||
// Update pesanan
|
||||
$pesanan->update([
|
||||
'jumlah' => $request->jumlah,
|
||||
'total_harga' => $barang->harga * $request->jumlah,
|
||||
'catatan' => $request->catatan
|
||||
]);
|
||||
|
||||
// Update stok barang
|
||||
$barang->update([
|
||||
'stok' => $barang->stok + $selisihStok
|
||||
]);
|
||||
|
||||
return redirect()->route('pesanan.index')
|
||||
->with('success', 'Pesanan berhasil diperbarui');
|
||||
}
|
||||
|
||||
public function storeFromCart(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'catatan' => 'nullable|string',
|
||||
'shipping_info' => 'required|json',
|
||||
'selected_items' => 'required|array'
|
||||
]);
|
||||
|
||||
$shippingInfo = json_decode($request->shipping_info, true);
|
||||
if (!$shippingInfo) {
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Informasi pengiriman tidak valid');
|
||||
}
|
||||
|
||||
$query = Keranjang::with('barang')->where('user_id', Auth::id());
|
||||
|
||||
// Jika ada item yang dipilih, gunakan hanya item tersebut
|
||||
if ($request->has('selected_items') && !empty($request->selected_items)) {
|
||||
$query->whereIn('id', $request->selected_items);
|
||||
}
|
||||
|
||||
$keranjangItems = $query->get();
|
||||
|
||||
if ($keranjangItems->isEmpty()) {
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Keranjang belanja Anda kosong');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$totalHargaBarang = 0;
|
||||
$items = [];
|
||||
|
||||
foreach ($keranjangItems as $item) {
|
||||
$barang = $item->barang;
|
||||
|
||||
// Verify stock availability
|
||||
if ($barang->stok < $item->jumlah) {
|
||||
DB::rollBack();
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', "Stok {$barang->nama_barang} tidak mencukupi, tersisa {$barang->stok}");
|
||||
}
|
||||
|
||||
$totalHargaBarang += $item->total_harga;
|
||||
$items[] = [
|
||||
'barang_id' => $barang->id,
|
||||
'jumlah' => $item->jumlah,
|
||||
'harga' => $barang->harga,
|
||||
'subtotal' => $item->total_harga
|
||||
];
|
||||
|
||||
// Update stock
|
||||
$barang->update([
|
||||
'stok' => $barang->stok - $item->jumlah
|
||||
]);
|
||||
}
|
||||
|
||||
// Buat satu pesanan untuk semua item
|
||||
$pesanan = Pesanan::create([
|
||||
'user_id' => Auth::id(),
|
||||
'barang_id' => $items[0]['barang_id'], // Set barang_id dari item pertama
|
||||
'jumlah' => $items[0]['jumlah'], // Set jumlah dari item pertama
|
||||
'total_harga' => $totalHargaBarang + $shippingInfo['cost'],
|
||||
'status' => 'pending',
|
||||
'catatan' => $request->catatan,
|
||||
'shipping_cost' => $shippingInfo['cost'],
|
||||
'shipping_service' => $shippingInfo['service'],
|
||||
'shipping_etd' => $shippingInfo['etd'],
|
||||
'shipping_courier' => $shippingInfo['courier'],
|
||||
'shipping_province_id' => $shippingInfo['province_id'],
|
||||
'shipping_city_id' => $shippingInfo['city_id']
|
||||
]);
|
||||
|
||||
// Simpan detail item pesanan
|
||||
foreach ($items as $item) {
|
||||
$pesanan->items()->create([
|
||||
'barang_id' => $item['barang_id'],
|
||||
'jumlah' => $item['jumlah'],
|
||||
'harga' => $item['harga'],
|
||||
'total_harga' => $item['subtotal']
|
||||
]);
|
||||
}
|
||||
|
||||
// Hapus item dari keranjang
|
||||
$keranjangItems->each->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
// Buat transaksi Midtrans
|
||||
try {
|
||||
// Hitung total harga item
|
||||
$itemDetails = array_map(function($item) {
|
||||
return [
|
||||
'id' => $item['barang_id'],
|
||||
'price' => $item['harga'],
|
||||
'quantity' => $item['jumlah'],
|
||||
'name' => $item['barang']->nama_barang
|
||||
];
|
||||
}, $items);
|
||||
|
||||
// Tambahkan detail pengiriman sebagai item terpisah
|
||||
$itemDetails[] = [
|
||||
'id' => 'shipping',
|
||||
'price' => $shippingInfo['cost'],
|
||||
'quantity' => 1,
|
||||
'name' => 'Ongkos Kirim - ' . strtoupper($shippingInfo['courier']) . ' ' . $shippingInfo['service']
|
||||
];
|
||||
|
||||
$params = [
|
||||
'transaction_details' => [
|
||||
'order_id' => 'ORDER-' . $pesanan->id,
|
||||
'gross_amount' => $pesanan->total_harga,
|
||||
],
|
||||
'customer_details' => [
|
||||
'first_name' => Auth::user()->name,
|
||||
'email' => Auth::user()->email,
|
||||
],
|
||||
'item_details' => $itemDetails
|
||||
];
|
||||
|
||||
// Dapatkan Snap Token
|
||||
$snapToken = \Midtrans\Snap::getSnapToken($params);
|
||||
|
||||
// Simpan transaksi
|
||||
$transaksi = Transaksi::create([
|
||||
'pesanan_id' => $pesanan->id,
|
||||
'user_id' => Auth::id(),
|
||||
'total_bayar' => $pesanan->total_harga,
|
||||
'status' => 'pending',
|
||||
'snap_token' => $snapToken
|
||||
]);
|
||||
|
||||
return redirect()->route('transaksi.show', $transaksi)
|
||||
->with('success', 'Pesanan berhasil dibuat. Silakan selesaikan pembayaran.');
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Midtrans Error: ' . $e->getMessage());
|
||||
return redirect()->route('pesanan.index');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return redirect()->route('keranjang.index')
|
||||
->with('error', 'Terjadi kesalahan saat membuat pesanan: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,501 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Transaksi;
|
||||
use App\Models\Pesanan;
|
||||
use App\Services\MidtransService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class TransaksiController extends Controller
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
|
||||
protected $midtransService;
|
||||
|
||||
public function __construct(MidtransService $midtransService)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->midtransService = $midtransService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$query = Transaksi::with(['pesanan.barang', 'user']);
|
||||
|
||||
// Filter berdasarkan tanggal
|
||||
if (request('start_date')) {
|
||||
$query->whereDate('created_at', '>=', request('start_date'));
|
||||
}
|
||||
if (request('end_date')) {
|
||||
$query->whereDate('created_at', '<=', request('end_date'));
|
||||
}
|
||||
|
||||
// Filter berdasarkan status
|
||||
if (request('status')) {
|
||||
$query->where('status', request('status'));
|
||||
}
|
||||
|
||||
$transaksi = $query->latest()->paginate(10);
|
||||
|
||||
return view('admin.transaksi.index', compact('transaksi'));
|
||||
}
|
||||
|
||||
public function create(Pesanan $pesanan)
|
||||
{
|
||||
try {
|
||||
// Load relasi barang
|
||||
$pesanan->load('barang');
|
||||
|
||||
// Debug logging
|
||||
Log::info('Transaksi Create Debug', [
|
||||
'pesanan_id' => $pesanan->id,
|
||||
'pesanan_user_id' => $pesanan->user_id,
|
||||
'auth_user_id' => Auth::id(),
|
||||
'has_transaksi' => $pesanan->transaksi ? true : false
|
||||
]);
|
||||
|
||||
// Pastikan pesanan milik user yang sedang login
|
||||
if ((int)$pesanan->user_id !== Auth::id()) {
|
||||
return response()->json([
|
||||
'error' => 'Unauthorized action'
|
||||
], 403);
|
||||
}
|
||||
|
||||
// Jika sudah ada transaksi, gunakan transaksi yang ada
|
||||
if ($pesanan->transaksi) {
|
||||
$transaksi = $pesanan->transaksi;
|
||||
|
||||
// Dapatkan snap token baru
|
||||
$snapToken = $this->midtransService->getSnapToken([
|
||||
'transaction_details' => [
|
||||
'order_id' => $transaksi->kode_transaksi,
|
||||
'gross_amount' => $transaksi->total_pembayaran
|
||||
],
|
||||
'item_details' => [
|
||||
[
|
||||
'id' => (string)$pesanan->barang_id,
|
||||
'price' => (int)$pesanan->total_harga,
|
||||
'quantity' => 1,
|
||||
'name' => $pesanan->barang->nama_barang,
|
||||
'category' => 'Electronics'
|
||||
]
|
||||
],
|
||||
'customer_details' => [
|
||||
'first_name' => $transaksi->nama_penerima,
|
||||
'email' => Auth::user()->email ?: 'guest@example.com',
|
||||
'phone' => $transaksi->no_telp,
|
||||
'billing_address' => [
|
||||
'address' => $transaksi->alamat
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'snap_token' => $snapToken
|
||||
]);
|
||||
}
|
||||
|
||||
// Generate kode transaksi
|
||||
$kodeTransaksi = 'TRX' . date('YmdHis') . rand(100, 999);
|
||||
|
||||
// Gunakan total_harga langsung dari pesanan
|
||||
$totalPembayaran = (int)$pesanan->total_harga;
|
||||
|
||||
// Validasi total pembayaran
|
||||
if ($totalPembayaran < 1) {
|
||||
return response()->json([
|
||||
'error' => 'Total pembayaran harus lebih besar dari 0'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Buat transaksi baru
|
||||
$user = Auth::user();
|
||||
$transaksi = Transaksi::create([
|
||||
'user_id' => Auth::id(),
|
||||
'pesanan_id' => $pesanan->id,
|
||||
'kode_transaksi' => $kodeTransaksi,
|
||||
'total_pembayaran' => $totalPembayaran,
|
||||
'status' => 'menunggu_pembayaran',
|
||||
'nama_penerima' => $user->name ?? 'Guest',
|
||||
'no_telp' => $user->no_telp ?? '-',
|
||||
'alamat' => $user->alamat ?? '-'
|
||||
]);
|
||||
|
||||
// Siapkan item details
|
||||
$itemDetails = [];
|
||||
|
||||
// Tambahkan item barang
|
||||
if ($pesanan->barang) {
|
||||
$itemDetails[] = [
|
||||
'id' => (string)$pesanan->barang_id,
|
||||
'price' => (int)$pesanan->total_harga,
|
||||
'quantity' => 1,
|
||||
'name' => $pesanan->barang->nama_barang,
|
||||
'category' => 'Electronics'
|
||||
];
|
||||
}
|
||||
|
||||
// Debug log untuk memeriksa total harga
|
||||
Log::info('Total Harga Debug', [
|
||||
'total_pembayaran' => $totalPembayaran,
|
||||
'item_details' => $itemDetails,
|
||||
'transaksi_id' => $transaksi->id,
|
||||
]);
|
||||
|
||||
// Dapatkan Snap token dari Midtrans dengan order_id yang sama
|
||||
$snapToken = $this->midtransService->getSnapToken([
|
||||
'transaction_details' => [
|
||||
'order_id' => $transaksi->kode_transaksi,
|
||||
'gross_amount' => $totalPembayaran // Gunakan totalPembayaran yang sudah termasuk ongkir
|
||||
],
|
||||
'item_details' => $itemDetails,
|
||||
'customer_details' => [
|
||||
'first_name' => $transaksi->nama_penerima,
|
||||
'email' => Auth::user()->email ?: 'guest@example.com',
|
||||
'phone' => $transaksi->no_telp,
|
||||
'billing_address' => [
|
||||
'address' => $transaksi->alamat
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'snap_token' => $snapToken
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error creating transaction: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'error' => 'Terjadi kesalahan saat memproses pembayaran: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'pesanan_id' => 'required|exists:pesanan,id',
|
||||
'nama_penerima' => 'required|string|max:255',
|
||||
'no_telp' => 'required|string|max:15',
|
||||
'alamat' => 'required|string',
|
||||
'metode_pembayaran' => 'required|in:transfer,cod',
|
||||
'catatan_pengiriman' => 'nullable|string'
|
||||
]);
|
||||
|
||||
$pesanan = Pesanan::findOrFail($request->pesanan_id);
|
||||
|
||||
// Pastikan pesanan milik user yang sedang login
|
||||
if ($pesanan->user_id !== Auth::id()) {
|
||||
return back()->with('error', 'Anda tidak memiliki akses ke pesanan ini');
|
||||
}
|
||||
|
||||
// Pastikan pesanan masih pending
|
||||
if ($pesanan->status !== 'pending') {
|
||||
return back()->with('error', 'Pesanan tidak dapat diproses untuk pembayaran');
|
||||
}
|
||||
|
||||
// Generate kode transaksi
|
||||
$kodeTransaksi = 'TRX' . date('YmdHis') . rand(100, 999);
|
||||
|
||||
// Gunakan total_harga langsung dari pesanan
|
||||
$totalPembayaran = (int)$pesanan->total_harga;
|
||||
|
||||
// Buat transaksi baru
|
||||
$transaksi = Transaksi::create([
|
||||
'user_id' => Auth::id(),
|
||||
'pesanan_id' => $pesanan->id,
|
||||
'kode_transaksi' => $kodeTransaksi,
|
||||
'total_pembayaran' => $totalPembayaran,
|
||||
'metode_pembayaran' => $request->metode_pembayaran,
|
||||
'status' => 'menunggu_pembayaran',
|
||||
'nama_penerima' => $request->nama_penerima,
|
||||
'no_telp' => $request->no_telp,
|
||||
'alamat' => $request->alamat,
|
||||
'catatan_pengiriman' => $request->catatan_pengiriman
|
||||
]);
|
||||
|
||||
// Update status pesanan menjadi diproses
|
||||
$pesanan->update(['status' => 'diproses']);
|
||||
|
||||
return redirect()->route('transaksi.show', $transaksi)
|
||||
->with('success', 'Transaksi berhasil dibuat. Silakan lakukan pembayaran.');
|
||||
}
|
||||
|
||||
public function show(Transaksi $transaksi)
|
||||
{
|
||||
// Pastikan transaksi milik user yang sedang login
|
||||
if ($transaksi->user_id !== Auth::id()) {
|
||||
return abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$transaksi->load(['pesanan.barang']);
|
||||
return view('transaksi.show', compact('transaksi'));
|
||||
}
|
||||
|
||||
public function uploadBukti(Request $request, Transaksi $transaksi)
|
||||
{
|
||||
$request->validate([
|
||||
'bukti_pembayaran' => 'required|image|max:2048'
|
||||
]);
|
||||
|
||||
if ($transaksi->user_id !== Auth::id()) {
|
||||
return abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
if ($transaksi->status !== 'menunggu_pembayaran') {
|
||||
return back()->with('error', 'Bukti pembayaran tidak dapat diupload');
|
||||
}
|
||||
|
||||
// Upload bukti pembayaran
|
||||
$path = $request->file('bukti_pembayaran')->store('bukti_pembayaran', 'public');
|
||||
|
||||
$transaksi->update([
|
||||
'bukti_pembayaran' => $path,
|
||||
'status' => 'menunggu_konfirmasi'
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Bukti pembayaran berhasil diupload');
|
||||
}
|
||||
|
||||
public function confirmPayment(Request $request, Transaksi $transaksi)
|
||||
{
|
||||
if ($transaksi->status !== 'menunggu_konfirmasi') {
|
||||
return back()->with('error', 'Status transaksi tidak valid');
|
||||
}
|
||||
|
||||
$transaksi->update(['status' => 'dibayar']);
|
||||
$transaksi->pesanan->update(['status' => 'diproses']);
|
||||
|
||||
return back()->with('success', 'Pembayaran berhasil dikonfirmasi');
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
try {
|
||||
$payload = $request->all();
|
||||
$transaksi = $this->midtransService->handleCallback((object) $payload);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Callback berhasil diproses',
|
||||
'data' => $transaksi
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function finish(Request $request)
|
||||
{
|
||||
try {
|
||||
Log::info('Finish Callback', [
|
||||
'order_id' => $request->order_id,
|
||||
'transaction_status' => $request->transaction_status,
|
||||
'payment_type' => $request->payment_type,
|
||||
'all_params' => $request->all()
|
||||
]);
|
||||
|
||||
$transaksi = Transaksi::where('kode_transaksi', $request->order_id)->first();
|
||||
|
||||
if (!$transaksi) {
|
||||
Log::error('Transaksi tidak ditemukan', [
|
||||
'order_id' => $request->order_id,
|
||||
'snap_token' => $request->snap_token
|
||||
]);
|
||||
return redirect()->route('pesanan.index')
|
||||
->with('error', 'Transaksi tidak ditemukan. Silakan hubungi admin dengan kode transaksi: ' . $request->order_id);
|
||||
}
|
||||
|
||||
// Update status transaksi
|
||||
$transaksi->update([
|
||||
'status' => 'dibayar',
|
||||
'payment_type' => $request->payment_type,
|
||||
'transaction_status' => $request->transaction_status
|
||||
]);
|
||||
|
||||
// Update status pesanan
|
||||
$transaksi->pesanan->update(['status' => 'diproses']);
|
||||
|
||||
return view('transaksi.success', [
|
||||
'transaksi' => $transaksi,
|
||||
'payment_type' => $request->payment_type,
|
||||
'transaction_status' => $request->transaction_status
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in finish callback: ' . $e->getMessage(), [
|
||||
'order_id' => $request->order_id,
|
||||
'exception' => $e
|
||||
]);
|
||||
|
||||
return redirect()->route('pesanan.index')
|
||||
->with('error', 'Terjadi kesalahan saat memproses pembayaran. Silakan hubungi admin.');
|
||||
}
|
||||
}
|
||||
|
||||
public function unfinish(Request $request)
|
||||
{
|
||||
try {
|
||||
Log::info('Unfinish Callback', [
|
||||
'order_id' => $request->order_id,
|
||||
'transaction_status' => $request->transaction_status,
|
||||
'payment_type' => $request->payment_type,
|
||||
'all_params' => $request->all()
|
||||
]);
|
||||
|
||||
$transaksi = Transaksi::where('kode_transaksi', $request->order_id)->first();
|
||||
|
||||
if (!$transaksi) {
|
||||
Log::error('Transaksi tidak ditemukan', [
|
||||
'order_id' => $request->order_id
|
||||
]);
|
||||
return redirect()->route('pesanan.index')
|
||||
->with('error', 'Transaksi tidak ditemukan. Silakan hubungi admin dengan kode transaksi: ' . $request->order_id);
|
||||
}
|
||||
|
||||
// Update status transaksi menjadi pending
|
||||
$transaksi->update([
|
||||
'status' => 'menunggu_pembayaran',
|
||||
'payment_type' => $request->payment_type,
|
||||
'transaction_status' => $request->transaction_status
|
||||
]);
|
||||
|
||||
// Tampilkan halaman pending dengan informasi pembayaran
|
||||
return view('transaksi.pending', [
|
||||
'transaksi' => $transaksi,
|
||||
'payment_type' => $request->payment_type,
|
||||
'transaction_status' => $request->transaction_status,
|
||||
'message' => 'Pembayaran Anda belum selesai. Silakan selesaikan pembayaran Anda.'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in unfinish callback: ' . $e->getMessage(), [
|
||||
'order_id' => $request->order_id,
|
||||
'exception' => $e
|
||||
]);
|
||||
|
||||
return redirect()->route('pesanan.index')
|
||||
->with('error', 'Terjadi kesalahan saat memproses pembayaran. Silakan hubungi admin.');
|
||||
}
|
||||
}
|
||||
|
||||
public function error(Request $request)
|
||||
{
|
||||
$transaksi = Transaksi::where('kode_transaksi', $request->order_id)->first();
|
||||
|
||||
if (!$transaksi) {
|
||||
return redirect()->route('pesanan.index')->with('error', 'Transaksi tidak ditemukan');
|
||||
}
|
||||
|
||||
return view('transaksi.error', [
|
||||
'transaksi' => $transaksi
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSnapToken(Pesanan $pesanan)
|
||||
{
|
||||
try {
|
||||
// Cek apakah pesanan memiliki transaksi
|
||||
$transaksi = $pesanan->transaksi;
|
||||
if (!$transaksi) {
|
||||
return response()->json([
|
||||
'error' => 'Tidak ada transaksi yang sedang menunggu pembayaran'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Pastikan pesanan milik user yang sedang login
|
||||
if ((int)$pesanan->user_id !== Auth::id()) {
|
||||
return response()->json([
|
||||
'error' => 'Unauthorized action'
|
||||
], 403);
|
||||
}
|
||||
|
||||
// Siapkan item details
|
||||
$itemDetails = [];
|
||||
|
||||
// Ambil semua item dari pesanan
|
||||
foreach ($pesanan->items as $item) {
|
||||
$itemDetails[] = [
|
||||
'id' => (string)$item->barang_id,
|
||||
'price' => (int)$item->harga,
|
||||
'quantity' => $item->jumlah,
|
||||
'name' => $item->barang->nama_barang,
|
||||
'category' => 'Electronics'
|
||||
];
|
||||
}
|
||||
|
||||
// Debug log untuk memeriksa total harga
|
||||
Log::info('Total Harga Debug', [
|
||||
'total_pembayaran' => $transaksi->total_pembayaran,
|
||||
'item_details' => $itemDetails,
|
||||
'transaksi_id' => $transaksi->id,
|
||||
]);
|
||||
|
||||
// Dapatkan Snap token dari Midtrans dengan order_id yang sama
|
||||
$snapToken = $this->midtransService->getSnapToken([
|
||||
'transaction_details' => [
|
||||
'order_id' => $transaksi->kode_transaksi,
|
||||
'gross_amount' => (int)$transaksi->total_pembayaran
|
||||
],
|
||||
'item_details' => $itemDetails,
|
||||
'customer_details' => [
|
||||
'first_name' => $transaksi->nama_penerima,
|
||||
'email' => Auth::user()->email ?: 'guest@example.com',
|
||||
'phone' => $transaksi->no_telp,
|
||||
'billing_address' => [
|
||||
'address' => $transaksi->alamat
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'snap_token' => $snapToken
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error getting snap token: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'error' => 'Terjadi kesalahan saat memproses pembayaran: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request)
|
||||
{
|
||||
try {
|
||||
$transaksi = Transaksi::where('kode_transaksi', $request->order_id)->first();
|
||||
|
||||
if (!$transaksi) {
|
||||
return response()->json([
|
||||
'error' => 'Transaksi tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Update status transaksi
|
||||
$transaksi->update([
|
||||
'status' => 'dibayar',
|
||||
'payment_type' => $request->payment_type,
|
||||
'transaction_status' => $request->transaction_status
|
||||
]);
|
||||
|
||||
// Update status pesanan
|
||||
$transaksi->pesanan->update(['status' => 'diproses']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Status transaksi berhasil diupdate'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error updating transaction status: ' . $e->getMessage());
|
||||
return response()->json([
|
||||
'error' => 'Terjadi kesalahan saat mengupdate status transaksi'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function updateAddress(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'alamat' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$user->alamat = $request->alamat;
|
||||
$user->save();
|
||||
|
||||
return redirect()->back()->with('success', 'Alamat berhasil diperbarui');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class UserProfileController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
$user = Auth::user();
|
||||
return view('user.profile', compact('user'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users,email,' . $user->id,
|
||||
'alamat' => 'required|string|max:500',
|
||||
'nomor_telp' => 'required|string|max:15',
|
||||
'current_password' => 'nullable|required_with:new_password',
|
||||
'new_password' => 'nullable|min:8|confirmed',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
// Update informasi dasar
|
||||
$user->nama = $request->nama;
|
||||
$user->email = $request->email;
|
||||
$user->alamat = $request->alamat;
|
||||
$user->nomor_telp = $request->nomor_telp;
|
||||
|
||||
// Update password jika diisi
|
||||
if ($request->filled('current_password')) {
|
||||
if (!Hash::check($request->current_password, $user->password)) {
|
||||
return back()
|
||||
->withErrors(['current_password' => 'Password saat ini tidak sesuai'])
|
||||
->withInput();
|
||||
}
|
||||
|
||||
$user->password = Hash::make($request->new_password);
|
||||
}
|
||||
|
||||
try {
|
||||
$user->save();
|
||||
return back()->with('success', 'Profil berhasil diperbarui');
|
||||
} catch (\Exception $e) {
|
||||
return back()
|
||||
->withErrors(['error' => 'Terjadi kesalahan saat memperbarui profil'])
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's middleware aliases.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \App\Http\Middleware\EnsureEmailIsVerified::class,
|
||||
'role' => \App\Http\Middleware\RoleMiddleware::class,
|
||||
'check.role' => \App\Http\Middleware\CheckRole::class,
|
||||
];
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return $request->expectsJson() ? null : route('login');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckRole
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string $role): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
$roles = explode('|', $role);
|
||||
|
||||
if (!in_array(Auth::user()->role, $roles)) {
|
||||
if (Auth::user()->role === 'admin') {
|
||||
return redirect()->route('admin.dashboard')
|
||||
->with('error', 'Anda tidak memiliki akses ke halaman ini.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard')
|
||||
->with('error', 'Anda tidak memiliki akses ke halaman ini.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class EnsureEmailIsVerified
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (!Auth::user() || !Auth::user()->is_verified) {
|
||||
return $request->expectsJson()
|
||||
? response()->json(['message' => 'Email Anda belum diverifikasi.'], 403)
|
||||
: Redirect::route('verification.notice');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RoleMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string $role
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $role)
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
$roles = is_array($role) ? $role : explode('|', $role);
|
||||
|
||||
if (!in_array(Auth::user()->role, $roles)) {
|
||||
if (Auth::user()->role === 'admin') {
|
||||
return redirect()->route('admin.dashboard')
|
||||
->with('error', 'Anda tidak memiliki akses ke halaman ini.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard')
|
||||
->with('error', 'Anda tidak memiliki akses ke halaman ini.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
protected $proxies;
|
||||
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
protected $except = [
|
||||
// Kecualikan semua route keranjang untuk kemudahan debugging
|
||||
'keranjang/*',
|
||||
// Dan secara spesifik route hapus-direct
|
||||
'keranjang/hapus-direct',
|
||||
// Kecualikan route API pesanan
|
||||
'api/pesanan/*'
|
||||
];
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Banner extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'judul',
|
||||
'deskripsi',
|
||||
'gambar',
|
||||
'url',
|
||||
'aktif',
|
||||
'urutan',
|
||||
'tanggal_mulai',
|
||||
'tanggal_selesai'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'aktif' => 'boolean',
|
||||
'tanggal_mulai' => 'datetime',
|
||||
'tanggal_selesai' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope untuk mendapatkan banner yang aktif
|
||||
*/
|
||||
public function scopeAktif($query)
|
||||
{
|
||||
return $query->where('aktif', true)
|
||||
->where(function ($q) {
|
||||
$q->whereNull('tanggal_mulai')
|
||||
->orWhere('tanggal_mulai', '<=', now());
|
||||
})
|
||||
->where(function ($q) {
|
||||
$q->whereNull('tanggal_selesai')
|
||||
->orWhere('tanggal_selesai', '>=', now());
|
||||
})
|
||||
->orderBy('urutan');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Barang extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'barang';
|
||||
|
||||
protected $fillable = [
|
||||
'nama_barang',
|
||||
'deskripsi',
|
||||
'harga',
|
||||
'stok',
|
||||
'gambar',
|
||||
'kategori',
|
||||
'slug'
|
||||
];
|
||||
|
||||
/**
|
||||
* Mendapatkan flash sale items yang terkait dengan barang ini
|
||||
*/
|
||||
public function flashSaleItems()
|
||||
{
|
||||
return $this->hasMany(FlashSaleItem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan pesanan yang terkait dengan barang ini
|
||||
*/
|
||||
public function pesanan()
|
||||
{
|
||||
return $this->hasMany(Pesanan::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FlashSale extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'deskripsi',
|
||||
'banner',
|
||||
'waktu_mulai',
|
||||
'waktu_selesai',
|
||||
'aktif',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'waktu_mulai' => 'datetime',
|
||||
'waktu_selesai' => 'datetime',
|
||||
'aktif' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke item flash sale
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(FlashSaleItem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relasi ke barang-barang yang termasuk dalam flash sale
|
||||
*/
|
||||
public function barangs()
|
||||
{
|
||||
return $this->belongsToMany(Barang::class, 'flash_sale_items')
|
||||
->withPivot('harga_flash_sale', 'persentase_diskon', 'stok_flash_sale', 'stok_terjual', 'aktif')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope untuk mendapatkan flash sale yang aktif dan berjalan saat ini
|
||||
*/
|
||||
public function scopeAktif($query)
|
||||
{
|
||||
return $query->where('aktif', true)
|
||||
->where('waktu_mulai', '<=', now())
|
||||
->where('waktu_selesai', '>=', now());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah flash sale sedang berlangsung
|
||||
*/
|
||||
public function getSedangBerlangsungAttribute()
|
||||
{
|
||||
return $this->aktif &&
|
||||
$this->waktu_mulai <= now() &&
|
||||
$this->waktu_selesai >= now();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FlashSaleItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'flash_sale_id',
|
||||
'barang_id',
|
||||
'harga_flash_sale',
|
||||
'persentase_diskon',
|
||||
'stok_flash_sale',
|
||||
'stok_terjual',
|
||||
'aktif',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'aktif' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke flash sale
|
||||
*/
|
||||
public function flashSale()
|
||||
{
|
||||
return $this->belongsTo(FlashSale::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relasi ke barang
|
||||
*/
|
||||
public function barang()
|
||||
{
|
||||
return $this->belongsTo(Barang::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah masih tersedia stok
|
||||
*/
|
||||
public function getStokTersediaAttribute()
|
||||
{
|
||||
return $this->stok_flash_sale - $this->stok_terjual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah item flash sale masih tersedia
|
||||
*/
|
||||
public function getTersediaAttribute()
|
||||
{
|
||||
return $this->aktif && $this->getStokTersediaAttribute() > 0 && $this->flashSale && $this->flashSale->sedang_berlangsung;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Keranjang extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'keranjang';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'barang_id',
|
||||
'jumlah',
|
||||
'total_harga',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke model Barang
|
||||
*/
|
||||
public function barang()
|
||||
{
|
||||
return $this->belongsTo(Barang::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relasi ke model User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Ongkir extends Model
|
||||
{
|
||||
protected $table = 'ongkir';
|
||||
protected $fillable = [
|
||||
'province_id',
|
||||
'province_name',
|
||||
'city_id',
|
||||
'city_name',
|
||||
'jne_reg',
|
||||
'jne_oke',
|
||||
'jne_yes',
|
||||
'pos_reg',
|
||||
'pos_express',
|
||||
'tiki_reg',
|
||||
'tiki_eco',
|
||||
'tiki_express'
|
||||
];
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pesanan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'pesanan';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'barang_id',
|
||||
'jumlah',
|
||||
'total_harga',
|
||||
'status',
|
||||
'catatan',
|
||||
'shipping_info',
|
||||
'province_id',
|
||||
'city_id',
|
||||
'courier',
|
||||
'shipping_cost',
|
||||
'shipping_service',
|
||||
'shipping_etd',
|
||||
'shipping_courier',
|
||||
'shipping_province_id',
|
||||
'shipping_city_id'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'shipping_info' => 'array',
|
||||
'shipping_cost' => 'decimal:2'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function barang()
|
||||
{
|
||||
return $this->belongsTo(Barang::class);
|
||||
}
|
||||
|
||||
public function transaksi()
|
||||
{
|
||||
return $this->hasOne(Transaksi::class, 'pesanan_id');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(PesananItem::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PesananItem extends Model
|
||||
{
|
||||
protected $table = 'pesanan_items';
|
||||
|
||||
protected $fillable = [
|
||||
'pesanan_id',
|
||||
'barang_id',
|
||||
'jumlah',
|
||||
'total_harga'
|
||||
];
|
||||
|
||||
public function pesanan()
|
||||
{
|
||||
return $this->belongsTo(Pesanan::class);
|
||||
}
|
||||
|
||||
public function barang()
|
||||
{
|
||||
return $this->belongsTo(Barang::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Transaksi extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'transaksi';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'pesanan_id',
|
||||
'kode_transaksi',
|
||||
'total_pembayaran',
|
||||
'metode_pembayaran',
|
||||
'status',
|
||||
'bukti_pembayaran',
|
||||
'nama_penerima',
|
||||
'no_telp',
|
||||
'alamat',
|
||||
'catatan_pengiriman'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tanggal_pembayaran' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function pesanan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Pesanan::class);
|
||||
}
|
||||
|
||||
public static function generateKodeTransaksi(): string
|
||||
{
|
||||
$prefix = 'TRX';
|
||||
$date = now()->format('Ymd');
|
||||
$random = str_pad(mt_rand(1, 999), 3, '0', STR_PAD_LEFT);
|
||||
return $prefix . $date . $random;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'email',
|
||||
'password',
|
||||
'username',
|
||||
'role',
|
||||
'nomor_telp',
|
||||
'alamat',
|
||||
'is_verified',
|
||||
'verification_token',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_verified' => 'boolean',
|
||||
];
|
||||
|
||||
public function keranjang()
|
||||
{
|
||||
return $this->hasMany(Keranjang::class);
|
||||
}
|
||||
|
||||
public function transaksi()
|
||||
{
|
||||
return $this->hasMany(Transaksi::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
Schema::defaultStringLength(191);
|
||||
|
||||
// Nonaktifkan ONLY_FULL_GROUP_BY
|
||||
DB::statement("SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use App\Models\Pesanan;
|
||||
use App\Policies\PesananPolicy;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected $policies = [
|
||||
Pesanan::class => PesananPolicy::class,
|
||||
];
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
public const HOME = '/dashboard';
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Transaksi;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Midtrans\Config;
|
||||
use Midtrans\Snap;
|
||||
|
||||
class MidtransService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
Config::$serverKey = config('midtrans.server_key');
|
||||
Config::$isProduction = config('midtrans.is_production', false);
|
||||
Config::$isSanitized = true;
|
||||
Config::$is3ds = true;
|
||||
|
||||
Log::info('Midtrans Config', [
|
||||
'server_key' => Config::$serverKey,
|
||||
'is_production' => Config::$isProduction
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSnapToken($params)
|
||||
{
|
||||
try {
|
||||
Log::info('Getting Snap Token', ['params' => $params]);
|
||||
|
||||
// Pastikan semua nilai numerik adalah integer
|
||||
if (isset($params['transaction_details']['gross_amount'])) {
|
||||
$params['transaction_details']['gross_amount'] = (int)$params['transaction_details']['gross_amount'];
|
||||
}
|
||||
|
||||
if (isset($params['item_details'])) {
|
||||
foreach ($params['item_details'] as &$item) {
|
||||
$item['price'] = (int)$item['price'];
|
||||
$item['quantity'] = (int)$item['quantity'];
|
||||
}
|
||||
}
|
||||
|
||||
// Tambahkan konfigurasi callback
|
||||
$params['callbacks'] = [
|
||||
'finish' => config('midtrans.finish_url'),
|
||||
'unfinish' => config('midtrans.unfinish_url'),
|
||||
'error' => config('midtrans.error_url')
|
||||
];
|
||||
|
||||
$snapToken = Snap::getSnapToken($params);
|
||||
Log::info('Snap Token Generated', ['token' => $snapToken]);
|
||||
|
||||
return $snapToken;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Midtrans Error: ' . $e->getMessage(), [
|
||||
'params' => $params,
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function handleCallback($payload)
|
||||
{
|
||||
try {
|
||||
$transaksi = Transaksi::where('kode_transaksi', $payload->order_id)->first();
|
||||
|
||||
if (!$transaksi) {
|
||||
throw new \Exception('Transaksi tidak ditemukan');
|
||||
}
|
||||
|
||||
$transactionStatus = $payload->transaction_status;
|
||||
$fraudStatus = $payload->fraud_status;
|
||||
|
||||
if ($transactionStatus == 'capture') {
|
||||
if ($fraudStatus == 'challenge') {
|
||||
$transaksi->status = 'challenge';
|
||||
} else if ($fraudStatus == 'accept') {
|
||||
$transaksi->status = 'success';
|
||||
$transaksi->pesanan->update(['status' => 'diproses']);
|
||||
}
|
||||
} else if ($transactionStatus == 'settlement') {
|
||||
$transaksi->status = 'success';
|
||||
$transaksi->pesanan->update(['status' => 'diproses']);
|
||||
} else if ($transactionStatus == 'cancel' || $transactionStatus == 'deny' || $transactionStatus == 'expire') {
|
||||
$transaksi->status = 'failed';
|
||||
} else if ($transactionStatus == 'pending') {
|
||||
$transaksi->status = 'pending';
|
||||
}
|
||||
|
||||
$transaksi->midtrans_transaction_id = $payload->transaction_id;
|
||||
$transaksi->midtrans_payment_type = $payload->payment_type;
|
||||
$transaksi->midtrans_transaction_time = $payload->transaction_time;
|
||||
$transaksi->midtrans_transaction_status = $payload->transaction_status;
|
||||
$transaksi->midtrans_fraud_status = $payload->fraud_status;
|
||||
$transaksi->save();
|
||||
|
||||
return $transaksi;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error handling callback: ' . $e->getMessage(), [
|
||||
'payload' => $payload,
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Ongkir;
|
||||
|
||||
class OngkirService
|
||||
{
|
||||
public function getProvinces()
|
||||
{
|
||||
return Ongkir::select('province_id', 'province_name')
|
||||
->distinct()
|
||||
->orderBy('province_name')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getCities($provinceId)
|
||||
{
|
||||
return Ongkir::where('province_id', $provinceId)
|
||||
->select('city_id', 'city_name')
|
||||
->orderBy('city_name')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function calculateCost($origin, $destination, $weight, $courier)
|
||||
{
|
||||
// Ambil data ongkir berdasarkan kota tujuan
|
||||
$ongkir = Ongkir::where('city_id', $destination)->first();
|
||||
|
||||
if (!$ongkir) {
|
||||
throw new \Exception('Data ongkir tidak ditemukan');
|
||||
}
|
||||
|
||||
// Hitung ongkir berdasarkan kurir dan layanan
|
||||
$costs = [];
|
||||
|
||||
switch ($courier) {
|
||||
case 'jne':
|
||||
$costs = [
|
||||
[
|
||||
'service' => 'REG',
|
||||
'description' => 'Layanan Reguler',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->jne_reg,
|
||||
'etd' => '2-3',
|
||||
'note' => 'Estimasi pengiriman 2-3 hari'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'service' => 'OKE',
|
||||
'description' => 'Layanan Ekonomis',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->jne_oke,
|
||||
'etd' => '3-5',
|
||||
'note' => 'Estimasi pengiriman 3-5 hari'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'service' => 'YES',
|
||||
'description' => 'Layanan Express',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->jne_yes,
|
||||
'etd' => '1-2',
|
||||
'note' => 'Estimasi pengiriman 1-2 hari'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
break;
|
||||
|
||||
case 'pos':
|
||||
$costs = [
|
||||
[
|
||||
'service' => 'REG',
|
||||
'description' => 'Layanan Reguler',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->pos_reg,
|
||||
'etd' => '3-4',
|
||||
'note' => 'Estimasi pengiriman 3-4 hari'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'service' => 'EXPRESS',
|
||||
'description' => 'Layanan Express',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->pos_express,
|
||||
'etd' => '1-2',
|
||||
'note' => 'Estimasi pengiriman 1-2 hari'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
break;
|
||||
|
||||
case 'tiki':
|
||||
$costs = [
|
||||
[
|
||||
'service' => 'REG',
|
||||
'description' => 'Layanan Reguler',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->tiki_reg,
|
||||
'etd' => '2-3',
|
||||
'note' => 'Estimasi pengiriman 2-3 hari'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'service' => 'ECO',
|
||||
'description' => 'Layanan Ekonomis',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->tiki_eco,
|
||||
'etd' => '3-5',
|
||||
'note' => 'Estimasi pengiriman 3-5 hari'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'service' => 'EXPRESS',
|
||||
'description' => 'Layanan Express',
|
||||
'cost' => [
|
||||
[
|
||||
'value' => $ongkir->tiki_express,
|
||||
'etd' => '1-2',
|
||||
'note' => 'Estimasi pengiriman 1-2 hari'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'rajaongkir' => [
|
||||
'query' => [
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'weight' => $weight,
|
||||
'courier' => $courier
|
||||
],
|
||||
'status' => [
|
||||
'code' => 200,
|
||||
'description' => 'OK'
|
||||
],
|
||||
'results' => [
|
||||
[
|
||||
'code' => $courier,
|
||||
'name' => strtoupper($courier),
|
||||
'costs' => $costs
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class RajaOngkirService
|
||||
{
|
||||
protected $baseUrl;
|
||||
protected $apiKey;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->baseUrl = config('services.rajaongkir.base_url');
|
||||
$this->apiKey = config('services.rajaongkir.api_key');
|
||||
}
|
||||
|
||||
public function getProvinces($id = null)
|
||||
{
|
||||
try {
|
||||
$curl = curl_init();
|
||||
|
||||
$url = $this->baseUrl . "/province";
|
||||
if ($id) {
|
||||
$url .= "?id=" . $id;
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"key: " . $this->apiKey
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
throw new \Exception("cURL Error #:" . $err);
|
||||
}
|
||||
|
||||
return json_decode($response, true);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('Gagal mengambil data provinsi: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getCities($provinceId = null, $id = null)
|
||||
{
|
||||
try {
|
||||
$curl = curl_init();
|
||||
|
||||
$url = $this->baseUrl . "/city";
|
||||
$params = [];
|
||||
if ($provinceId) {
|
||||
$params[] = "province=" . $provinceId;
|
||||
}
|
||||
if ($id) {
|
||||
$params[] = "id=" . $id;
|
||||
}
|
||||
if (!empty($params)) {
|
||||
$url .= "?" . implode("&", $params);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"key: " . $this->apiKey
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
throw new \Exception("cURL Error #:" . $err);
|
||||
}
|
||||
|
||||
return json_decode($response, true);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('Gagal mengambil data kota: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function calculateCost($origin, $destination, $weight, $courier)
|
||||
{
|
||||
try {
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $this->baseUrl . "/cost",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "POST",
|
||||
CURLOPT_POSTFIELDS => http_build_query([
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'weight' => $weight,
|
||||
'courier' => $courier
|
||||
]),
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"content-type: application/x-www-form-urlencoded",
|
||||
"key: " . $this->apiKey
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
throw new \Exception("cURL Error #:" . $err);
|
||||
}
|
||||
|
||||
return json_decode($response, true);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('Gagal menghitung ongkos kirim: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
// Register the Composer autoloader...
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
// Bootstrap Laravel and handle the command...
|
||||
$status = (require_once __DIR__.'/bootstrap/app.php')
|
||||
->handleCommand(new ArgvInput);
|
||||
|
||||
exit($status);
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Configuration\Exceptions;
|
||||
use Illuminate\Foundation\Configuration\Middleware;
|
||||
|
||||
return Application::configure(basePath: dirname(__DIR__))
|
||||
->withRouting(
|
||||
web: __DIR__.'/../routes/web.php',
|
||||
commands: __DIR__.'/../routes/console.php',
|
||||
health: '/up',
|
||||
)
|
||||
->withMiddleware(function (Middleware $middleware) {
|
||||
//
|
||||
})
|
||||
->withExceptions(function (Exceptions $exceptions) {
|
||||
//
|
||||
})->create();
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
App\Providers\AppServiceProvider::class,
|
||||
];
|
|
@ -0,0 +1,77 @@
|
|||
{
|
||||
"$schema": "https://getcomposer.org/schema.json",
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"barryvdh/laravel-dompdf": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.9",
|
||||
"laravel/framework": "^11.31",
|
||||
"laravel/sanctum": "^4.0",
|
||||
"laravel/tinker": "^2.9",
|
||||
"laravel/ui": "^4.6",
|
||||
"midtrans/midtrans-php": "^2.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.23",
|
||||
"laravel/pail": "^1.1",
|
||||
"laravel/pint": "^1.13",
|
||||
"laravel/sail": "^1.26",
|
||||
"mockery/mockery": "^1.6",
|
||||
"nunomaduro/collision": "^8.1",
|
||||
"phpunit/phpunit": "^11.0.1",
|
||||
"spatie/laravel-ignition": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"@php artisan key:generate --ansi",
|
||||
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
|
||||
"@php artisan migrate --graceful --ansi"
|
||||
],
|
||||
"dev": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": []
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application, which will be used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| other UI elements where an application name needs to be displayed.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. Set this in your ".env" file.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => env('APP_ENV', 'production'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
|
||||
'debug' => (bool) env('APP_DEBUG', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This URL is used by the console to properly generate URLs when using
|
||||
| the Artisan command line tool. You should set this to the root of
|
||||
| the application so that it's available within Artisan commands.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default timezone for your application, which
|
||||
| will be used by the PHP date and date-time functions. The timezone
|
||||
| is set to "UTC" by default as it is suitable for most use cases.
|
||||
|
|
||||
*/
|
||||
|
||||
'timezone' => env('APP_TIMEZONE', 'UTC'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Locale Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The application locale determines the default locale that will be used
|
||||
| by Laravel's translation / localization methods. This option can be
|
||||
| set to any locale for which you plan to have translation strings.
|
||||
|
|
||||
*/
|
||||
|
||||
'locale' => env('APP_LOCALE', 'en'),
|
||||
|
||||
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
|
||||
|
||||
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This key is utilized by Laravel's encryption services and should be set
|
||||
| to a random, 32 character string to ensure that all encrypted values
|
||||
| are secure. You should do this prior to deploying the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'previous_keys' => [
|
||||
...array_filter(
|
||||
explode(',', env('APP_PREVIOUS_KEYS', ''))
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maintenance Mode Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options determine the driver used to determine and
|
||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||
| allow maintenance mode to be controlled across multiple machines.
|
||||
|
|
||||
| Supported drivers: "file", "cache"
|
||||
|
|
||||
*/
|
||||
|
||||
'maintenance' => [
|
||||
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
|
||||
'store' => env('APP_MAINTENANCE_STORE', 'database'),
|
||||
],
|
||||
|
||||
];
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Defaults
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default authentication "guard" and password
|
||||
| reset "broker" for your application. You may change these values
|
||||
| as required, but they're a perfect start for most applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => env('AUTH_GUARD', 'web'),
|
||||
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, you may define every authentication guard for your application.
|
||||
| Of course, a great default configuration has been defined for you
|
||||
| which utilizes session storage plus the Eloquent user provider.
|
||||
|
|
||||
| All authentication guards have a user provider, which defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| system used by the application. Typically, Eloquent is utilized.
|
||||
|
|
||||
| Supported: "session"
|
||||
|
|
||||
*/
|
||||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All authentication guards have a user provider, which defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| system used by the application. Typically, Eloquent is utilized.
|
||||
|
|
||||
| If you have multiple user tables or models you may configure multiple
|
||||
| providers to represent the model / table. These providers may then
|
||||
| be assigned to any extra authentication guards you have defined.
|
||||
|
|
||||
| Supported: "database", "eloquent"
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => env('AUTH_MODEL', App\Models\User::class),
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options specify the behavior of Laravel's password
|
||||
| reset functionality, including the table utilized for token storage
|
||||
| and the user provider that is invoked to actually retrieve users.
|
||||
|
|
||||
| The expiry time is the number of minutes that each reset token will be
|
||||
| considered valid. This security feature keeps tokens short-lived so
|
||||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
| The throttle setting is the number of seconds a user must wait before
|
||||
| generating more password reset tokens. This prevents the user from
|
||||
| quickly generating a very large amount of password reset tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
|
||||
'expire' => 60,
|
||||
'throttle' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Confirmation Timeout
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define the amount of seconds before a password confirmation
|
||||
| window expires and users are asked to re-enter their password via the
|
||||
| confirmation screen. By default, the timeout lasts for three hours.
|
||||
|
|
||||
*/
|
||||
|
||||
'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),
|
||||
|
||||
];
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default cache store that will be used by the
|
||||
| framework. This connection is utilized if another isn't explicitly
|
||||
| specified when running a cache operation inside the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('CACHE_STORE', 'database'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Stores
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the cache "stores" for your application as
|
||||
| well as their drivers. You may even define multiple stores for the
|
||||
| same cache driver to group types of items stored in your caches.
|
||||
|
|
||||
| Supported drivers: "array", "database", "file", "memcached",
|
||||
| "redis", "dynamodb", "octane", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'stores' => [
|
||||
|
||||
'array' => [
|
||||
'driver' => 'array',
|
||||
'serialize' => false,
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'connection' => env('DB_CACHE_CONNECTION'),
|
||||
'table' => env('DB_CACHE_TABLE', 'cache'),
|
||||
'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'),
|
||||
'lock_table' => env('DB_CACHE_LOCK_TABLE'),
|
||||
],
|
||||
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/data'),
|
||||
'lock_path' => storage_path('framework/cache/data'),
|
||||
],
|
||||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
'port' => env('MEMCACHED_PORT', 11211),
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
|
||||
'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'),
|
||||
],
|
||||
|
||||
'dynamodb' => [
|
||||
'driver' => 'dynamodb',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||
],
|
||||
|
||||
'octane' => [
|
||||
'driver' => 'octane',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Key Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the APC, database, memcached, Redis, and DynamoDB cache
|
||||
| stores, there might be other applications using the same cache. For
|
||||
| that reason, you may prefix every cache key to avoid collisions.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
|
||||
|
||||
];
|
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for database operations. This is
|
||||
| the connection which will be utilized unless another connection
|
||||
| is explicitly specified when you execute a query / statement.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'sqlite'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Below are all of the database connections defined for your application.
|
||||
| An example configuration is provided for each database system which
|
||||
| is supported by Laravel. You're free to add / remove connections.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('DB_URL'),
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
'busy_timeout' => null,
|
||||
'journal_mode' => null,
|
||||
'synchronous' => null,
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'oyiwebid_dijee'),
|
||||
'username' => env('DB_USERNAME', 'oyiwebid_kevin'),
|
||||
'password' => env('DB_PASSWORD', 'exmCmcFw@!)H'),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'mariadb' => [
|
||||
'driver' => 'mariadb',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'laravel'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'laravel'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'search_path' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'sqlsrv' => [
|
||||
'driver' => 'sqlsrv',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '1433'),
|
||||
'database' => env('DB_DATABASE', 'laravel'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run on the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => [
|
||||
'table' => 'migrations',
|
||||
'update_date_on_publish' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer body of commands than a typical key-value system
|
||||
| such as Memcached. You may define your connection settings here.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||
|
||||
'options' => [
|
||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
||||
],
|
||||
|
||||
'default' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_DB', '0'),
|
||||
],
|
||||
|
||||
'cache' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_CACHE_DB', '1'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Filesystem Disk
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default filesystem disk that should be used
|
||||
| by the framework. The "local" disk, as well as a variety of cloud
|
||||
| based disks are available to your application for file storage.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filesystem Disks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Below you may configure as many filesystem disks as necessary, and you
|
||||
| may even configure multiple disks for the same driver. Examples for
|
||||
| most supported storage drivers are configured here for reference.
|
||||
|
|
||||
| Supported drivers: "local", "ftp", "sftp", "s3"
|
||||
|
|
||||
*/
|
||||
|
||||
'disks' => [
|
||||
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/private'),
|
||||
'serve' => true,
|
||||
'throw' => false,
|
||||
'report' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
'report' => false,
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
'report' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Symbolic Links
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the symbolic links that will be created when the
|
||||
| `storage:link` Artisan command is executed. The array keys should be
|
||||
| the locations of the links and the values should be their targets.
|
||||
|
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
],
|
||||
|
||||
];
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\SyslogUdpHandler;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default log channel that is utilized to write
|
||||
| messages to your logs. The value provided here should match one of
|
||||
| the channels present in the list of "channels" configured below.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Deprecations Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the log channel that should be used to log warnings
|
||||
| regarding deprecated PHP and library features. This allows you to get
|
||||
| your application ready for upcoming major versions of dependencies.
|
||||
|
|
||||
*/
|
||||
|
||||
'deprecations' => [
|
||||
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||
'trace' => env('LOG_DEPRECATIONS_TRACE', false),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log Channels
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the log channels for your application. Laravel
|
||||
| utilizes the Monolog PHP logging library, which includes a variety
|
||||
| of powerful log handlers and formatters that you're free to use.
|
||||
|
|
||||
| Available drivers: "single", "daily", "slack", "syslog",
|
||||
| "errorlog", "monolog", "custom", "stack"
|
||||
|
|
||||
*/
|
||||
|
||||
'channels' => [
|
||||
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => explode(',', env('LOG_STACK', 'single')),
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'daily' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => env('LOG_DAILY_DAYS', 14),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'driver' => 'slack',
|
||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||
'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'),
|
||||
'emoji' => env('LOG_SLACK_EMOJI', ':boom:'),
|
||||
'level' => env('LOG_LEVEL', 'critical'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'papertrail' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||
'handler_with' => [
|
||||
'host' => env('PAPERTRAIL_URL'),
|
||||
'port' => env('PAPERTRAIL_PORT'),
|
||||
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'stderr' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'with' => [
|
||||
'stream' => 'php://stderr',
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'syslog' => [
|
||||
'driver' => 'syslog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'errorlog' => [
|
||||
'driver' => 'errorlog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'monolog',
|
||||
'handler' => NullHandler::class,
|
||||
],
|
||||
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'default' => env('MAIL_MAILER', 'smtp'),
|
||||
|
||||
'mailers' => [
|
||||
'smtp' => [
|
||||
'transport' => 'smtp',
|
||||
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
|
||||
'port' => env('MAIL_PORT', 587),
|
||||
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||
'username' => env('MAIL_USERNAME'),
|
||||
'password' => env('MAIL_PASSWORD'),
|
||||
'timeout' => null,
|
||||
'local_domain' => env('MAIL_EHLO_DOMAIN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'transport' => 'ses',
|
||||
],
|
||||
|
||||
'mailgun' => [
|
||||
'transport' => 'mailgun',
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'transport' => 'log',
|
||||
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'transport' => 'array',
|
||||
],
|
||||
],
|
||||
|
||||
'from' => [
|
||||
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
'markdown' => [
|
||||
'theme' => 'default',
|
||||
|
||||
'paths' => [
|
||||
resource_path('views/vendor/mail'),
|
||||
],
|
||||
],
|
||||
];
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Midtrans Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you can configure your Midtrans settings
|
||||
|
|
||||
*/
|
||||
|
||||
'merchant_id' => env('MIDTRANS_MERCHANT_ID', ''),
|
||||
'client_key' => env('MIDTRANS_CLIENT_KEY', 'Mid-client-dGZpmVPgIuz0Y9tV'),
|
||||
'server_key' => env('MIDTRANS_SERVER_KEY', 'Mid-server-VvPKuiVcPnaxZXutJMKlXj-d'),
|
||||
'is_production' => env('MIDTRANS_IS_PRODUCTION', true),
|
||||
|
||||
'snap_url' => env('MIDTRANS_IS_PRODUCTION', true)
|
||||
? 'https://app.midtrans.com/snap/snap.js'
|
||||
: 'https://app.sandbox.midtrans.com/snap/snap.js',
|
||||
|
||||
'finish_url' => env('APP_URL') . '/transaksi/finish',
|
||||
'unfinish_url' => env('APP_URL') . '/transaksi/unfinish',
|
||||
'error_url' => env('APP_URL') . '/transaksi/error',
|
||||
|
||||
// Konfigurasi Snap
|
||||
'snap' => [
|
||||
'callback_url' => env('MIDTRANS_SNAP_CALLBACK_URL', ''),
|
||||
'finish_url' => env('APP_URL') . '/transaksi/finish',
|
||||
'unfinish_url' => env('APP_URL') . '/transaksi/unfinish',
|
||||
'error_url' => env('APP_URL') . '/transaksi/error',
|
||||
],
|
||||
|
||||
// Konfigurasi default untuk transaksi
|
||||
'transaction' => [
|
||||
'payment_type' => 'bank_transfer', // bank_transfer, credit_card, e-wallet, dll
|
||||
'bank_transfer' => [
|
||||
'bank' => 'bca', // bca, bni, mandiri, dll
|
||||
],
|
||||
'credit_card' => [
|
||||
'secure' => true,
|
||||
'bank' => 'all', // all, bca, bni, mandiri, dll
|
||||
'installment' => [
|
||||
'required' => false,
|
||||
'terms' => [
|
||||
'bca' => [3, 6, 12],
|
||||
'bni' => [3, 6, 12],
|
||||
'mandiri' => [3, 6, 12],
|
||||
],
|
||||
],
|
||||
],
|
||||
'expiry' => [
|
||||
'start_time' => '2024-01-01 00:00:00 +0700',
|
||||
'unit' => 'day',
|
||||
'duration' => 1,
|
||||
],
|
||||
],
|
||||
|
||||
// Konfigurasi notifikasi
|
||||
'notification' => [
|
||||
'enabled' => true,
|
||||
'url' => env('MIDTRANS_NOTIFICATION_URL', ''),
|
||||
],
|
||||
|
||||
// Konfigurasi URL notifikasi
|
||||
'notification_url' => env('APP_URL') . '/transaksi/callback',
|
||||
];
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Queue Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel's queue supports a variety of backends via a single, unified
|
||||
| API, giving you convenient access to each backend using identical
|
||||
| syntax for each. The default queue connection is defined below.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('QUEUE_CONNECTION', 'database'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queue Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the connection options for every queue backend
|
||||
| used by your application. An example configuration is provided for
|
||||
| each backend supported by Laravel. You're also free to add more.
|
||||
|
|
||||
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'connection' => env('DB_QUEUE_CONNECTION'),
|
||||
'table' => env('DB_QUEUE_TABLE', 'jobs'),
|
||||
'queue' => env('DB_QUEUE', 'default'),
|
||||
'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'),
|
||||
'queue' => env('BEANSTALKD_QUEUE', 'default'),
|
||||
'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90),
|
||||
'block_for' => 0,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
|
||||
'queue' => env('SQS_QUEUE', 'default'),
|
||||
'suffix' => env('SQS_SUFFIX'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => env('REDIS_QUEUE_CONNECTION', 'default'),
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90),
|
||||
'block_for' => null,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Job Batching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following options configure the database and table that store job
|
||||
| batching information. These options can be updated to any database
|
||||
| connection and table which has been defined by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'batching' => [
|
||||
'database' => env('DB_CONNECTION', 'sqlite'),
|
||||
'table' => 'job_batches',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Failed Queue Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These options configure the behavior of failed queue job logging so you
|
||||
| can control how and where failed jobs are stored. Laravel ships with
|
||||
| support for storing failed jobs in a simple file or in a database.
|
||||
|
|
||||
| Supported drivers: "database-uuids", "dynamodb", "file", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'failed' => [
|
||||
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
|
||||
'database' => env('DB_CONNECTION', 'sqlite'),
|
||||
'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Third Party Services
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is for storing the credentials for third party services such
|
||||
| as Mailgun, Postmark, AWS and more. This file provides the de facto
|
||||
| location for this type of information, allowing packages to have
|
||||
| a conventional file to locate the various service credentials.
|
||||
|
|
||||
*/
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => env('MAILGUN_DOMAIN'),
|
||||
'secret' => env('MAILGUN_SECRET'),
|
||||
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
||||
'scheme' => 'https',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
'resend' => [
|
||||
'key' => env('RESEND_KEY'),
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'notifications' => [
|
||||
'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),
|
||||
'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),
|
||||
],
|
||||
],
|
||||
|
||||
'rajaongkir' => [
|
||||
'base_url' => env('RAJAONGKIR_BASE_URL', 'https://api.rajaongkir.com/starter'),
|
||||
'api_key' => env('RAJAONGKIR_API_KEY'),
|
||||
],
|
||||
|
||||
];
|
|
@ -0,0 +1,217 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Session Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines the default session driver that is utilized for
|
||||
| incoming requests. Laravel supports a variety of storage options to
|
||||
| persist session data. Database storage is a great default choice.
|
||||
|
|
||||
| Supported: "file", "cookie", "database", "apc",
|
||||
| "memcached", "redis", "dynamodb", "array"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'database'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Lifetime
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the number of minutes that you wish the session
|
||||
| to be allowed to remain idle before it expires. If you want them
|
||||
| to expire immediately when the browser is closed then you may
|
||||
| indicate that via the expire_on_close configuration option.
|
||||
|
|
||||
*/
|
||||
|
||||
'lifetime' => env('SESSION_LIFETIME', 120),
|
||||
|
||||
'expire_on_close' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to easily specify that all of your session data
|
||||
| should be encrypted before it's stored. All encryption is performed
|
||||
| automatically by Laravel and you may use the session like normal.
|
||||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session File Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the "file" session driver, the session files are placed
|
||||
| on disk. The default storage location is defined here; however, you
|
||||
| are free to provide another location where they should be stored.
|
||||
|
|
||||
*/
|
||||
|
||||
'files' => storage_path('framework/sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" or "redis" session drivers, you may specify a
|
||||
| connection that should be used to manage these sessions. This should
|
||||
| correspond to a connection in your database configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => env('SESSION_CONNECTION'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" session driver, you may specify the table to
|
||||
| be used to store sessions. Of course, a sensible default is defined
|
||||
| for you; however, you're welcome to change this to another table.
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => 'sessions',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using one of the framework's cache driven session backends, you may
|
||||
| define the cache store which should be used to store the session data
|
||||
| between requests. This must match one of your defined cache stores.
|
||||
|
|
||||
| Affects: "apc", "dynamodb", "memcached", "redis"
|
||||
|
|
||||
*/
|
||||
|
||||
'store' => env('SESSION_STORE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Sweeping Lottery
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some session drivers must manually sweep their storage location to get
|
||||
| rid of old sessions from storage. Here are the chances that it will
|
||||
| happen on a given request. By default, the odds are 2 out of 100.
|
||||
|
|
||||
*/
|
||||
|
||||
'lottery' => [2, 100],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the name of the session cookie that is created by
|
||||
| the framework. Typically, you should not need to change this value
|
||||
| since doing so does not grant a meaningful security improvement.
|
||||
|
|
||||
*/
|
||||
|
||||
'cookie' => env(
|
||||
'SESSION_COOKIE',
|
||||
Str::slug(env('APP_NAME', 'laravel'), '_') . '_session'
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The session cookie path determines the path for which the cookie will
|
||||
| be regarded as available. Typically, this will be the root path of
|
||||
| your application, but you're free to change this when necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => '/',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the domain and subdomains the session cookie is
|
||||
| available to. By default, the cookie will be available to the root
|
||||
| domain and all subdomains. Typically, this shouldn't be changed.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('SESSION_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTPS Only Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By setting this option to true, session cookies will only be sent back
|
||||
| to the server if the browser has a HTTPS connection. This will keep
|
||||
| the cookie from being sent to you when it can't be done securely.
|
||||
|
|
||||
*/
|
||||
|
||||
'secure' => env('SESSION_SECURE_COOKIE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Access Only
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will prevent JavaScript from accessing the
|
||||
| value of the cookie and the cookie will only be accessible through
|
||||
| the HTTP protocol. It's unlikely you should disable this option.
|
||||
|
|
||||
*/
|
||||
|
||||
'http_only' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Same-Site Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines how your cookies behave when cross-site requests
|
||||
| take place, and can be used to mitigate CSRF attacks. By default, we
|
||||
| will set this value to "lax" to permit secure cross-site requests.
|
||||
|
|
||||
| See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value
|
||||
|
|
||||
| Supported: "lax", "strict", "none", null
|
||||
|
|
||||
*/
|
||||
|
||||
'same_site' => 'lax',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Partitioned Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will tie the cookie to the top-level site for
|
||||
| a cross-site context. Partitioned cookies are accepted by the browser
|
||||
| when flagged "secure" and the Same-Site attribute is set to "none".
|
||||
|
|
||||
*/
|
||||
|
||||
'partitioned' => env('SESSION_PARTITIONED_COOKIE', false),
|
||||
|
||||
];
|
|
@ -0,0 +1 @@
|
|||
*.sqlite*
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username')->unique();
|
||||
$table->string('nama');
|
||||
$table->string('email')->unique();
|
||||
$table->string('password');
|
||||
$table->enum('role', ['admin', 'customer'])->default('customer');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username')->unique();
|
||||
$table->string('nama');
|
||||
$table->string('alamat');
|
||||
$table->string('nomor_hp');
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('barang', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama_barang');
|
||||
$table->text('deskripsi')->nullable();
|
||||
$table->decimal('harga', 10, 2);
|
||||
$table->integer('stok');
|
||||
$table->string('gambar')->nullable();
|
||||
$table->string('kategori')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('barang');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('pesanan', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
|
||||
$table->foreignId('barang_id')->constrained('barang')->onDelete('cascade');
|
||||
$table->integer('jumlah');
|
||||
$table->decimal('total_harga', 10, 2);
|
||||
$table->enum('status', ['pending', 'diproses', 'dikirim', 'selesai', 'dibatalkan'])->default('pending');
|
||||
$table->text('catatan')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('pesanan');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('transaksi', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
|
||||
$table->foreignId('pesanan_id')->constrained('pesanan')->onDelete('cascade');
|
||||
$table->string('kode_transaksi')->unique();
|
||||
$table->decimal('total_pembayaran', 10, 2);
|
||||
$table->enum('metode_pembayaran', ['transfer', 'cod', 'bank_transfer', 'e_wallet', 'credit_card'])->default('transfer');
|
||||
$table->enum('status', ['menunggu_pembayaran', 'menunggu_konfirmasi', 'dibayar', 'batal', 'expired', 'failed'])->default('menunggu_pembayaran');
|
||||
$table->string('bukti_pembayaran')->nullable();
|
||||
$table->string('nama_penerima');
|
||||
$table->string('no_telp');
|
||||
$table->text('alamat');
|
||||
$table->text('catatan_pengiriman')->nullable();
|
||||
// Kolom untuk Midtrans
|
||||
$table->string('midtrans_order_id')->nullable();
|
||||
$table->string('midtrans_transaction_id')->nullable();
|
||||
$table->string('midtrans_payment_type')->nullable();
|
||||
$table->string('midtrans_transaction_status')->nullable();
|
||||
$table->string('midtrans_va_number')->nullable();
|
||||
$table->string('midtrans_bank')->nullable();
|
||||
$table->string('midtrans_permata_va_number')->nullable();
|
||||
$table->string('midtrans_bill_key')->nullable();
|
||||
$table->string('midtrans_biller_code')->nullable();
|
||||
$table->string('midtrans_redirect_url')->nullable();
|
||||
$table->timestamp('midtrans_expiry_time')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('transaksi');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->enum('role', ['admin', 'customer'])->default('customer')->after('password');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('role');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('alamat')->nullable();
|
||||
$table->string('google_id')->nullable();
|
||||
$table->string('avatar')->nullable();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('google_token')->nullable();
|
||||
$table->string('google_refresh_token')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'alamat',
|
||||
'google_id',
|
||||
'avatar',
|
||||
'email_verified_at',
|
||||
'google_token',
|
||||
'google_refresh_token'
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('barang', function (Blueprint $table) {
|
||||
$table->integer('berat')->default(1000)->after('stok'); // berat dalam gram
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('barang', function (Blueprint $table) {
|
||||
$table->dropColumn('berat');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('users', 'email_verified_at')) {
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('users', 'email_verified_at')) {
|
||||
$table->dropColumn('email_verified_at');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('is_verified')->default(0)->after('email');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('is_verified');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('reset_password_token', 64)->nullable();
|
||||
$table->timestamp('reset_password_expires_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('reset_password_token');
|
||||
$table->dropColumn('reset_password_expires_at');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('verification_token')->nullable()->after('email');
|
||||
$table->boolean('is_verified')->default(0)->after('verification_token');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['verification_token', 'is_verified']);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('pesanan', function (Blueprint $table) {
|
||||
$table->json('shipping_info')->nullable()->after('catatan');
|
||||
$table->string('province_id')->nullable()->after('shipping_info');
|
||||
$table->string('city_id')->nullable()->after('province_id');
|
||||
$table->string('courier')->nullable()->after('city_id');
|
||||
$table->decimal('shipping_cost', 10, 2)->nullable()->after('courier');
|
||||
$table->string('shipping_service')->nullable()->after('shipping_cost');
|
||||
$table->string('shipping_etd')->nullable()->after('shipping_service');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('pesanan', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'shipping_info',
|
||||
'province_id',
|
||||
'city_id',
|
||||
'courier',
|
||||
'shipping_cost',
|
||||
'shipping_service',
|
||||
'shipping_etd'
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class EmailVerifiedAtColumn extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('users', 'email_verified_at')) {
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
} else {
|
||||
// Ubah tipe kolom jika sudah ada
|
||||
$table->timestamp('email_verified_at')->nullable()->change();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('users', 'email_verified_at')) {
|
||||
$table->dropColumn('email_verified_at');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('courses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('kode_mk')->unique();
|
||||
$table->string('nama_mk');
|
||||
$table->integer('sks');
|
||||
$table->text('deskripsi')->nullable();
|
||||
$table->string('semester');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('courses');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('ongkir', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('province_id');
|
||||
$table->string('province_name');
|
||||
$table->string('city_id');
|
||||
$table->string('city_name');
|
||||
$table->decimal('jne_reg', 10, 2);
|
||||
$table->decimal('jne_oke', 10, 2);
|
||||
$table->decimal('jne_yes', 10, 2);
|
||||
$table->decimal('pos_reg', 10, 2);
|
||||
$table->decimal('pos_express', 10, 2);
|
||||
$table->decimal('tiki_reg', 10, 2);
|
||||
$table->decimal('tiki_eco', 10, 2);
|
||||
$table->decimal('tiki_express', 10, 2);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('ongkir');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('pesanan', function (Blueprint $table) {
|
||||
$table->decimal('shipping_cost', 10, 2)->nullable();
|
||||
$table->string('shipping_service')->nullable();
|
||||
$table->string('shipping_etd')->nullable();
|
||||
$table->string('shipping_courier')->nullable();
|
||||
$table->string('shipping_province_id')->nullable();
|
||||
$table->string('shipping_city_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('pesanan', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'shipping_cost',
|
||||
'shipping_service',
|
||||
'shipping_etd',
|
||||
'shipping_courier',
|
||||
'shipping_province_id',
|
||||
'shipping_city_id'
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('pesanan_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('pesanan_id')->constrained('pesanan')->onDelete('cascade');
|
||||
$table->foreignId('barang_id')->constrained('barang')->onDelete('cascade');
|
||||
$table->integer('jumlah');
|
||||
$table->decimal('total_harga', 10, 2);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('pesanan_items');
|
||||
}
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue