Anons79 Mini Shell

Directory : /home/aplikasiposinfo/www/paraduta.fixmate.id/app/Http/Controllers/
Upload File :
Current File : /home/aplikasiposinfo/www/paraduta.fixmate.id/app/Http/Controllers/RewardPromoController.php

<?php

namespace App\Http\Controllers;

use App\Models\RewardPromo;
use DB;
use Illuminate\Http\Request;

class RewardPromoController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $datas = RewardPromo::paginate(10);
        

        return view('reward_promo.index', compact('datas'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        return view('reward_promo.create');
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $request->validate([
            'judul'=>'required',
            'isi'=>'required',
            'status_pelanggan'=>'required'
        ]);

        DB::beginTransaction();
        try {
            $data = RewardPromo::create([
                'judul'=>$request->judul,
                'isi'=>$request->isi,
                'status_pelanggan'=>$request->status_pelanggan,
                'aktif'=>$request->aktif ?? 0,
                'berulang'=>$request->berulang ?? 0,
                'pengguna_id'=>auth()->user()->id,
                'schedule_time'=>$request->schedule_time,
                'jam'=>$request->jam,
                'schedule_in'=>$request->schedule_in
            ]);
            DB::commit();
            return redirect()->route('reward-promo.index')->with('success','Berhasil menambahkan pesan reward & promo');
        } catch (\Throwable $th) {
            //throw $th;
            DB::rollBack();
            Log::error($th);
            return redirect()->back()->withInput($request->all())->with('error','Gagal menambahkan pesan reward & promo');
        }
    }

    /**
     * Display the specified resource.
     */
    public function show(RewardPromo $rewardPromo)
    {
        
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(RewardPromo $rewardPromo)
    {
        return view('reward_promo.edit',[
            'data'=>$rewardPromo
        ]);
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, RewardPromo $rewardPromo)
    {
        $request->validate([
            'judul'=>'required',
            'isi'=>'required',
            'status_pelanggan'=>'required'
        ]);

        DB::beginTransaction();
        try {
            $rewardPromo->update([
                'judul'=>$request->judul,
                'isi'=>$request->isi,
                'status_pelanggan'=>$request->status_pelanggan,
                'aktif'=>$request->aktif ?? 0,
                'berulang'=>$request->berulang ?? 0,
                'schedule_time'=>$request->schedule_time,
                'jam'=>$request->jam,
                'schedule_in'=>$request->schedule_in
            ]);
            DB::commit();
            return redirect()->route('reward-promo.index')->with('success','Berhasil mengubah pesan reward & promo');
        } catch (\Throwable $th) {
            //throw $th;
            DB::rollBack();
            Log::error($th);
            return redirect()->back()->withInput($request->all())->with('error','Gagal mengubah pesan reward & promo');
        }
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(RewardPromo $rewardPromo)
    {
        DB::beginTransaction();
        try {
            $rewardPromo->delete();
            DB::commit();
            return redirect()->route('reward-promo.index')->with('success','Berhasil menghapus pesan reward & promo');
        } catch (\Throwable $th) {
            //throw $th;
            DB::rollBack();
            Log::error($th);
            return redirect()->back()->with('error','Gagal menghapus pesan reward & promo');
        }
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]