<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\UserBankDetail;
use App\User;
use Auth;
use Session;

class UserBankController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $users = User::where('id', Auth::user()->id)->first();
        $banks = UserBankDetail::where('user_id', Auth::user()->id)->get();
        return view('front.user_profile.user_bank', compact('users', 'banks'));
    }

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        $data = $this->validate($request, [
            'account_holder_name' => 'required',
            'bank_name' => 'required',
        ]);


        $input = $request->all();           
        $data = UserBankDetail::create($input);
        $data->save(); 

        Session::flash('success', trans('flash.AddedSuccessfully'));
   
        return redirect('bankdetail');
    }

    /**
     * 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)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $user = UserBankDetail::findorfail($id);
      

        $input = $request->all();
          

        $user->update($input);

        Session::flash('success', trans('flash.UpdatedSuccessfully'));
        return redirect('bankdetail');

    }

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