<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\BankHowItwork;
use Illuminate\Http\Request;

class BankHowItWorkController extends Controller
{

    function __construct()
    {
        $this->middleware('role_or_permission:bank work access|bank work create|bank work edit|bank work delete', ['only' => ['index']]);
        $this->middleware('role_or_permission:bank work create', ['only' => ['create','store']]);
        $this->middleware('role_or_permission:bank work edit', ['only' => ['edit','update']]);
        $this->middleware('role_or_permission:bank work delete', ['only' => ['delete']]);
    }


    function index()
    {
        $datas = BankHowItwork::all();
        return view('admin.bank.work.index', compact('datas'));
    }
    function create()
    {
        return view('admin.bank.work.create');
    }

    function edit($id)
    {
        $data = BankHowItwork::findOrFail($id);
        return view('admin.bank.work.edit',compact('data'));

    }

    function update(Request $request,$id){
        $data = BankHowItwork::findOrFail($id);
        $data->title = $request->title;
        $data->description = $request->description;
        $data->save();

        $notification = array(
            'messege' => 'Updated successfully',
            'alert-type' => 'success'
        );

        return back()->with($notification);
    }

    function store(Request $request)
    {
        $request->validate([
            'title' => 'required',
            'description' => 'required'
        ]);

        BankHowItwork::query()->create($request->all());

        $notification = array(
            'messege' => 'created successfully',
            'alert-type' => 'success'
        );

        return back()->with($notification);
    }
    function delete($id){
        $data = BankHowItwork::find($id);
        $data->delete();

        $notification = array(
            'messege' => 'Deleted successfully',
            'alert-type' => 'success'
        );

        return back()->with($notification);
    }
}
