I am new to OctoberCMS and i love the way it works. Currently i have created two plugins called as Products and Product Categories. I have crea
Ok. I have found out two ways to be able to achieve this and here below are those.
Way One
Product.php (plugins\technobrave\products\models)
<?php namespace Technobrave\Products\Models;
use Model;
use technobrave\productcategory\Models\ProductCategory as ProductCategory;
public function getCategoryOptions()
{
$fields = ProductCategory::lists('category_name','id');
print_r($fields);
}
Here above, i have just used use technobrave\productcategory\Models\ProductCategory as ProductCategory;
and in my method getCategoryOptions()
, i have just added this ProductCategory::lists('category_name','id');
and returned it to be able to fill dynamic categories in my dropdown. This works well.
Way Two
Product.php (plugins\technobrave\products\models)
<?php namespace Technobrave\Products\Models;
use Model;
use technobrave\productcategory\Models\ProductCategory as ProductCategory;
public function getCategoryOptions()
{
// getting only active categories
$get_categories = ProductCategory::all()->where('status',1);
$fields[''] = 'Select Product Category';
foreach ($get_categories as $current_category) {
$fields[$current_category->attributes['id']] = $current_category->attributes['category_name'];
}
print_r($fields);
}
Here above, i simply written a query in my method getCategoryOptions()
and got the records.
You can use whichever method which you prefer. Additionally, it would be great if i find better ways to implement the same thing.
Thanks