<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Today;

class TodayController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   $tod=Today::all();
        return view('Admin.Today')->with('save',$tod);
    }

    /**
     * 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)
    {
        $this->validate($request, [
            'sharecapital'=>'required',
            'loan' => 'required',
            'saving' => 'required',
        ]);
        $save= new Today;
        $save->share_capital=$request->sharecapital;
        $save->saving=$request->saving;
        $save->loan= $request->loan;
        $save->asset= $request->asset;
        $save->member_no=$request->memberno;
        $save->backup_fund=$request->backupfund;
        $save->first_member=$request->firstmem;
        
        $save->save();
    
       return redirect('admin_today')->with('info', 'Datas Saved 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)
    {
        $edittoday=Today::where('id',$id)->first();
        return redirect('admin_today')->with('edit',$edittoday);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $data=array(
        'share_capital'=>$request->sharecapital,
        'saving'=>$request->saving,
        'loan'=>$request->loan,
        'asset'=>$request->asset,
        'member_no'=>$request->memberno,
        'backup_fund'=>$request->backupfund,
        'first_member'=>$request->firstmem,

    );
    Today::where('id',$request->id)->update($data);
    return redirect('admin_today')->with('info', 'Datas Saved Successfully!');
    
    }

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