2014-09-04 55 views
2

這裏做數組從收集的github要點鏈接:https://gist.github.com/gupta2205/b33dcf762876e5df34d9Laravel在控制器文件

//trying to make array out of fetured petitions 
// i guess i am doing something wrong in writing it 
//do i need "foreach" here ? to get individual petition->call_to_action access and set key value in array or how can i do it ? please suggest 

    $featureList = array(
    '0' => 'before '.Petition::getFeaturedPetitions()->call_to_action.'petition', 
    '1'=> 'before '.Petition::getFeaturedPetitions()->call_to_action.'petition', 
      ) 

回答

2

你可能會做這樣的事情:

$featureList = array(); 

foreach(Petition::getFeaturedPetitions() as $petition) 
{ 
    $featureList[$petition->id] = 'before '.$petition->call_to_action.'petition'; 
}