<?php

namespace App\Http\Controllers\Administrator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\BankModel;

class BankInfoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
   function __construct()
   {
        $this->middleware('permission:Bank-List');
        $this->middleware('permission:Bank-Create', ['only' => ['create','store']]);
        $this->middleware('permission:Bank-Edit', ['only' => ['edit','update']]);
   }
    
    public function index()
    {
    
        $data = BankModel::all();
       
        return view('administrator.bank.index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('administrator.bank.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $bank = new BankModel;
       
        $this->validate($request, [
            'name'      => 'required',
        
        ]);

        $bank->name     = $request->name;
        $bank->description     = $request->description;
        $bank->save();
        \LogActivity::addToLog('Bank created successfully !');
        return redirect()->route('bank-info.index')
        ->with('success','Bank created successfully !');
       
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
       
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $bank = BankModel::find($id);
        return view('administrator.bank.edit',compact('bank'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $bank = BankModel::find($id);
       
        $this->validate($request, [
            'name'      => 'required',
        
        ]);

        $bank->name     = $request->name;
        $bank->description    = $request->description;
       
        $bank->update();
        

        \LogActivity::addToLog('Bank updated successfully !');
        return redirect()->route('bank-info.index')
                        ->with('success','bank updated successfully !');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}