app/Http/Controllers/Admin/AdsController.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(
            [
                'campaign_id' => 'required',
                'title' => 'required',
                'url'  => 'required|url',
                'file' => 'required',
            ]
        );
        $id = $request->campaign_id;
        $title = $request->title;
        $url = $request->url;
        if ($request->hasFile('file')) {
            $photoPath = $request->file('file')->store('images', 'public');
            $path = storage_path('app/public/'.$photoPath);
            $info = pathinfo($path);
            $ext = $info['extension'];
            $curlFilePath = Report::getCurlRealFilePath($path, 'image/jpeg', round(microtime(true) * 1000).'.'.$ext);
            $uploadedPath = Report::uploadTaboolaThumbnail($curlFilePath);
            Storage::delete($photoPath);
            if(array_key_exists('value', $uploadedPath))
            {
                $resUrl = $uploadedPath['value'];
                $resUrl  = str_replace('http', 'https', $resUrl);
                $res = Report::massTaboolaAdsInsert($id, [ 'collection' => [['url' => $url, 'title' => $title, 'thumbnail_url' => $resUrl]]]);
                if(!array_key_exists('http_status', $res)) {
                    return redirect()->route('ads.edit', $id)->with('success', __('globals.msg.save_success'));
                } else
                {
                    return redirect()->route('ads.edit', $id)->with('error', $res['message']);
                }
            }
        }
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'campaign_id' => 'required' , 'title' => 'required' , 'url' => 'required|url' , 'file' => 'required' , ] ) ; $ id = $ request -> campaign_id ; $ title = $ request -> title ; $ url = $ request -> url ; if ( $ request -> hasFile ( 'file' ) ) { $ photoPath = $ request -> file ( 'file' ) -> store ( 'images' , 'public' ) ; $ path = storage_path ( 'app/public/' . $ photoPath ) ; $ info = pathinfo ( $ path ) ; $ ext = $ info [ 'extension' ] ; $ curlFilePath = Report :: getCurlRealFilePath ( $ path , 'image/jpeg' , round ( microtime ( true ) * 1000 ) . '.' . $ ext ) ; $ uploadedPath = Report :: uploadTaboolaThumbnail ( $ curlFilePath ) ; Storage :: delete ( $ photoPath ) ; if ( array_key_exists ( 'value' , $ uploadedPath ) ) { $ resUrl = $ uploadedPath [ 'value' ] ; $ resUrl = str_replace ( 'http' , 'https' , $ resUrl ) ; $ res = Report :: massTaboolaAdsInsert ( $ id , [ 'collection' => [ [ 'url' => $ url , 'title' => $ title , 'thumbnail_url' => $ resUrl ] ] ] ) ; if ( ! array_key_exists ( 'http_status' , $ res ) ) { return redirect ( ) -> route ( 'ads.edit' , $ id ) -> with ( 'success' , __ ( 'globals.msg.save_success' ) ) ; } else { return redirect ( ) -> route ( 'ads.edit' , $ id ) -> with ( 'error' , $ res [ 'message' ] ) ; } } } }
Store a newly created resource in storage.
Store a newly created resource in storage .