You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB
PHTML

<?php
namespace App\Http\Controllers;
use App\Models\CustomerLevel;
use App\Models\PoinReward;
use Illuminate\Http\Request;
class PoinRewardController extends Controller
{
public function index()
{
$query = PoinReward::with(['level'])
->orderBy('updated_at', 'desc');
return inertia('PoinReward/Index', [
'query' => $query->paginate(),
'levels' => CustomerLevel::all(),
]);
}
public function store(Request $request)
{
$request->validate([
'amount_buy' => 'required|numeric',
'bonus_poin' => 'required|numeric',
'customer_level_id' => 'required|exists:customer_levels,id',
]);
PoinReward::create([
'amount_buy' => $request->amount_buy,
'bonus_poin' => $request->bonus_poin,
'customer_level_id' => $request->customer_level_id,
]);
session()->flash('message', ['type' => 'success', 'message' => 'Item has beed saved']);
}
public function update(Request $request, PoinReward $reward)
{
$request->validate([
'amount_buy' => 'required|numeric',
'bonus_poin' => 'required|numeric',
'customer_level_id' => 'required|exists:customer_levels,id',
]);
$reward->update([
'amount_buy' => $request->amount_buy,
'bonus_poin' => $request->bonus_poin,
'customer_level_id' => $request->customer_level_id,
]);
session()->flash('message', ['type' => 'success', 'message' => 'Item has beed updated']);
}
public function destroy(PoinReward $reward)
{
$reward->delete();
session()->flash('message', ['type' => 'success', 'message' => 'Item has beed deleted']);
}
}