sharmila
sharmila

Reputation: 175

Getting error as stated below while passing three array values from controller to the view(i.e., to the same page)

Find below the controller code:

    public function domaincheck()
{

    $response = file_get_contents('https://resellertest.enom.com/interface.asp?command=check&sld=unusualTVname&tld=tv&uid=resellid&pw=resellpw&responsetype=xml');  
        $data = simplexml_load_string($response);
        $configdata   = json_encode($data);
        $final_data = json_decode($configdata,true);// Use true to get data in array rather than object
        // dd($final_data);



        $response1 = file_get_contents('http://resellertest.enom.com/interface.asp?command=GETNAMESUGGESTIONS&UID=resellid&PW=resellpw&SearchTerm=hand&MaxResults=5&ResponseType=XML');       
        $data1 = simplexml_load_string($response1);
        $configdata1   = json_encode($data1);
        $final_data1 = json_decode($configdata1,true);// Use true to get data in array rather than object
        //dd($final_data1);


        $response2 = file_get_contents('https://resellertest.enom.com/interface.asp?command=gettldlist&UID=resellid&PW=resellpw&responsetype=xml');  
        $data2 = simplexml_load_string($response2);
        $configdata2   = json_encode($data2);
        $final_data2 = json_decode($configdata2,true);
        //dd($final_data2);


       return view('clientlayout.main.test',array('final_data1' => 
       $final_data1), array('final_data' => $final_data), 
       array('final_data2' => $final_data2));

}

Find the view code given below:

{{print_r($final_data)}}

<br><br><br>

{{print_r($final_data1)}}
<br> 

{{print_r($final_data2)}}

Find the route code given below:

Route::get('/test','EnomController@domaincheck');

I need to return all the three arrays to the view page but When use the return view code giveb above I'm getting error as "Undefined variable: final_data2 " for the third array alone.If I declare only two array statements in the return view it works correctly. Suggest me a solution to solve this error.

Upvotes: 0

Views: 51

Answers (2)

Muzammil Baloch
Muzammil Baloch

Reputation: 186

in addition to @achraf answer if you dont want to use same variable names in your view as of your controller, you can pass data to your view like this. where final1, final2 and final3 will be the names of the variable in your view.

return view('clientlayout.main.test',['final1' =>$final_data ,'final2'=> $final_data1,'final3' => $final_data2]);

Upvotes: 1

Achraf Khouadja
Achraf Khouadja

Reputation: 6269

View take second param as array, your sending multiple arrays, the solution is to create an array of arrays like this

return view('clientlayout.main.test',compact('final_data','final_data1','final_data2'));

Upvotes: 1

Related Questions