<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Prelander;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;

class PrelandController extends Controller
{
    public function storePreland(Request $request){
        
        $preland = new Prelander();
        $preland->offer_id = $request->offerId;
        $preland->prelander_name = $request->prelandName;
        $preland->prelaner_link = $request->prelandLink;
        $preland->prelander_pvr_link = $request->prelandPrLink;

        $preland->save();

        Session::flash('success', 'Preland added successfully');

        return Redirect::back();
    }

    public function prelandDelete(Request $request){
        
        if (!$request->ajax()) {
            return abort(404);
        }

        $response = [
            'status' => false,
            'message' => 'Somthing went wrong, please try again',
            'data' => []
        ];
        if (Prelander::where('id', $request->id)->delete()) {
            $response = [
                'status' => true,
                'message' => 'Cashout Deleted Successful!',
                'data' => []
            ];
            return response()->json($response);
            // return redirect()->back()->with('success', 'Cashout Deleted Successful!');
        }
        return response()->json($response);
    }
}
