This is the program i need the below output
But i am getting this output
But i am getting all the subcategories inside the category where is my problem i know its some where in the loop
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Exception;
use Hash;
use DB;
class Rewards extends Model
{
/**
* The database table using by the model
*
* @var string
*/
protected $primaryKey = 'id_category';
public static function getrewardcategory()
{
$firstarray = array();
$secondarray = array();
$thirdarray = array();
//Taking the top main categories - Bronze,silver
$mainrewards=\DB::table('product_for')->get();
//Taking the rewards category
$rewardcategory = DB::table('product_category')->where('parent_id','0')->where('mainparent','2')->get();
foreach ($rewardcategory as $recat)
{
//Taking the rewards sub category
$rewardssubcategory=DB::table('product_category')->where('parent_id','>','0')
->where('mainparent','2')
->get();
foreach ($rewardssubcategory as $resubcat)
{
if($resubcat->parent_id ==$recat->id_category )
{
$rewardssubcategories = array('r_sub_categories_id' =>$resubcat->id_category,
'r_sub_categories_name' =>$resubcat->name,
'r_sub_categories_image' => "Sub cat Image URL"
);
array_push($firstarray,$rewardssubcategories);
}
}
}
foreach ($rewardcategory as $recat)
{
$rewardscategories = array('r_categories_id' =>$recat->id_category,
'r_categories_name' => $recat->name,
'r_sub_categories' => $firstarray
);
array_push($secondarray,$rewardscategories);
}
foreach ($mainrewards as $rewards)
{
$rewards = array('r_id' =>$rewards->id_product_for,
'r_name' => $rewards->product_for,
'r_image' => "image_url",
'r_categories' => $secondarray
);
array_push($thirdarray,$rewards);
}
return $thirdarray;
}
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SMIubu
via IFTTT
Aucun commentaire:
Enregistrer un commentaire