Brand.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\models;
  3. use Illuminate\Database\Eloquent\SoftDeletes;
  4. /**
  5. * Created by PhpStorm.
  6. * Author: 芸众商城 www.yunzshop.com
  7. * Date: 2017/2/27
  8. * Time: 上午9:11
  9. */
  10. class Brand extends BaseModel
  11. {
  12. use SoftDeletes;
  13. public $table = 'yz_brand';
  14. protected $guarded = [''];
  15. protected $fillable = [''];
  16. /**
  17. * @param $pageSize
  18. * @return mixed
  19. */
  20. public static function getBrands($search = [])
  21. {
  22. //deleted_at字段是int所以加上whereNull
  23. // return self::uniacid()->whereNull('deleted_at');
  24. $result = self::uniacid()->whereNull('deleted_at');
  25. if ($search['id']){
  26. $result->where('id',$search['id']);
  27. }
  28. if ($search['name']){
  29. $result->where('name','like','%'.$search['name'] .'%');
  30. }
  31. return $result;
  32. }
  33. /**
  34. * @param $id
  35. * @return mixed
  36. */
  37. public static function getBrand($id)
  38. {
  39. return self::where('id', $id)
  40. ->first();
  41. }
  42. public function keywordGetBrand($keyword)
  43. {
  44. return self::uniacid()->where('name','like','%'.$keyword .'%')->select(['id','name']);
  45. }
  46. }