File: /home/imensosw/public_html/amanda/app/Product.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
use SoftDeletes;
protected $fillable = [
'name', 'price', 'units', 'description', 'image','type','status','category_id','fileType'
];
public function orders(){
return $this->hasMany(Order::class);
}
public static function checkProductExistAlongCategoryId($id)
{
$result = Product::where('products.category_id',$id)->count();
if($result>0){
return 1;
}
else{
return 0;
}
}
public static function checkProductExistAlongTagId($id)
{
// $result = \DB::table('product_tag')->where('product_tag.tag_id',$id)->count();
$result = Product::leftjoin('product_tag','product_tag.product_id','products.id')
->where('product_tag.tag_id',$id)->count();
if($result>0){
return 1;
}
else{
return 0;
}
}
}