Model
1 2 3 4 5 6 7 8 9 |
class Category extends Model { public $belongsToMany = [ 'products' => [ 'pms\Models\Product', 'table' => 'pms_product_category' ], ]; } |
Controller:
1 2 3 4 5 |
$category = Category::whereRaw("REPLACE(name,' ','-') = '{$categoryname}'")->first(); //This line will delete product relation table of this category //Unknown reason. $category->products = []; |