<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\ReferedByModel;
use Session;
class ReferedByController extends Controller
{
    function referedBy(){
        return view('masters/referedby');
    }
    function viewReferedByList(Request $req){
        $result = ReferedByModel::all();
        return view('masters/view-referedby-list',['data'=>$result]);
    }

    function saveReferedBy(Request $req){
        if($req->action == 'Save'){
            $Package = new ReferedByModel;
        }
        else{
            $Package = ReferedByModel::find($req->id);
        }
        $Package->Name = $req->Name; 
        $Package->Status = 1;
        $Package->CreatedBy = 19;
        $Package->ModifiedBy = 19;
        $Package->save();
        return 1;
    }

    function editReferedBy(Request $req){
        $data = ReferedByModel::find($req->id);
        return json_encode($data);
    }

    function deleteReferedBy(Request $req){
        $data=ReferedByModel::find($req->id)->delete();
        return 1;
    }
    
    function referedbyList(){
     
            $result = DB::select("SELECT * FROM tbl_referedby");
       
        return $result;
    }
    
    /*function getProcedureDetails(Request $req){
        $data=ReferedByModel::select('Amount')->Where(['Name'=>$req->val,'Type'=>1])->first();
        return $data->Amount;
    }*/
}
