<?php

namespace App\Http\Controllers\Admin;

# Models
use App\Models\Notice;

# Other Classes
use DB;
use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;


class BroadCasteController extends Controller
{
    # Define Base view
    protected $view = 'admin.notice.';

     #Bind Notice model
    protected $notice;

    /**
      * Defining the default constructor for controller
      *
      */
    public function __construct(
                                Notice $notice
                            )
    {
        $this->notice  = $notice;
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
         try
        {

            $input = $request->all();

            #get all paymentUser resources
            $notices = $this->notice->where('created_at','!=',null);

            $search_name = '';
            $search_status = '';
            if(isset($input['search_name']) || isset($input['search_status'])){
                $search_name = $input['search_name'];
                $search_status = $input['search_status'];
                if(isset($search_name) && $search_name != null){
                $notices->where('name','LIKE','%'.$search_name.'%');
                }
                if($search_status != null && $search_status == 1){
                    $notices->where('status', $search_status);
                }else if($search_status != null && $search_status == 0){
                    $notices->where('status',$search_status);
                }
               
            }  
            $details['lists'] = $notices->paginate(10);

            #render view
            return view($this->view.'index',$details);
        }catch(\Exception $ex)
        {
            return back()->with('error', $ex->getMessage());
        }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
          try{
           $details['detail'] = $this->notice->first();
            #render view
            return view($this->view.'create',$details);
         }catch(\Exception $ex)
        {
            return back()->with('error', $ex->getMessage());
        }
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
         try{
             #validate the request
          
            #get the requested data in Data variable
            $data = [
                    'descripation'       => $request->descripation,
  
                    ];
            #store the newly creted resoures
            $this->notice->whereId(1)->update($data);
            // #return redirect back to view
             toastr()->success('Store Create Sucess fully ...');
            return redirect('/admin/notice/create');
         }catch(\Exception $ex)
        {
             toastr()->success($ex->getMessage());
            return back()->with('error', $ex->getMessage());
        }
    }

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

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