简体   繁体   中英

How i declare a var in Laravel if i need the $row from a foreach in the blade view data

i made a code and now i want to export it in laravel.

in my initial code i've got this

while($row = $getRss->fetch_assoc()) {
                    $rss = simplexml_load_file($row["link"]);
 }

how can i now declare the $rss in my controller and pass it to my view?

Here is the code to add your rss from controller to view

$arrRss = [];
while($row = $getRss->fetch_assoc()) {
     $rss = simplexml_load_file($row["link"]);
     array_push($arrRss,$rss);
 }

return view('the-blade-name',['rss' => $arrRss]);

there are many ways to pass a variable in view(blade) file

$rss = [];
 return view('blade-file',['rss' => $rss]);
 return view('blade-file')->with(['rss' => $rss]);
 return view('blade-file',compact('rss'));

all of these gives you same result in view file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM