app/Http/Controllers/Admin/AdController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $request->validate([
            'header' => 'nullable',
            'sidebar1' => 'nullable',
            'sidebar2' => 'nullable',
            'footer' => 'nullable',
            'onclick' => 'nullable',
            'popup' => 'nullable',
        ]);
        $id = $request->id;
        if($id == -1){
            $data = new Ad;
            $data->header = $request->header;
            $data->sidebar1 = $request->sidebar1;
            $data->sidebar2 = $request->sidebar2;
            $data->footer = $request->footer;
            $data->onclick = $request->onclick;
            $data->popup = $request->popup;
            $data->status = 1;
            $data->created_by = Auth::user()->id;
            $data->save();
        }
        else{
            $data = Ad::find($id);
            $data->header = $request->header;
            $data->sidebar1 = $request->sidebar1;
            $data->sidebar2 = $request->sidebar2;
            $data->footer = $request->footer;
            $data->onclick = $request->onclick;
            $data->popup = $request->popup;
            $data->status = 1;
            $data->updated_by = Auth::user()->id;
            $data->save();
        }
        Toastr::success('Ad Script Updated Successfully!', 'success');
        return redirect()->back();
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'header' => 'nullable' , 'sidebar1' => 'nullable' , 'sidebar2' => 'nullable' , 'footer' => 'nullable' , 'onclick' => 'nullable' , 'popup' => 'nullable' , ] ) ; $ id = $ request -> id ; if ( $ id == - 1 ) { $ data = new Ad ; $ data -> header = $ request -> header ; $ data -> sidebar1 = $ request -> sidebar1 ; $ data -> sidebar2 = $ request -> sidebar2 ; $ data -> footer = $ request -> footer ; $ data -> onclick = $ request -> onclick ; $ data -> popup = $ request -> popup ; $ data -> status = 1 ; $ data -> created_by = Auth :: user ( ) -> id ; $ data -> save ( ) ; } else { $ data = Ad :: find ( $ id ) ; $ data -> header = $ request -> header ; $ data -> sidebar1 = $ request -> sidebar1 ; $ data -> sidebar2 = $ request -> sidebar2 ; $ data -> footer = $ request -> footer ; $ data -> onclick = $ request -> onclick ; $ data -> popup = $ request -> popup ; $ data -> status = 1 ; $ data -> updated_by = Auth :: user ( ) -> id ; $ data -> save ( ) ; } Toastr :: success ( 'Ad Script Updated Successfully!' , 'success' ) ; return redirect ( ) -> back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Field Validation // -1 means no data row found // Insert Data // Update Data