Menu.php 866 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use App\Repositories\Models\Model;
  4. class Menu extends Model
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $table = 'base_menus';
  10. protected $guarded = [];
  11. /**
  12. * The attributes excluded from the model's JSON form.
  13. *
  14. * @var array
  15. */
  16. protected $hidden = [];
  17. protected $casts = [
  18. 'meta' => 'json'
  19. ];
  20. const TYPE_MENU = 1;
  21. const TYPE_BTN = 2;
  22. public static function checkNameIsUnique($name, $ignore_id = 0)
  23. {
  24. return self::query()->where('name', $name)->where('type', self::TYPE_MENU)->where('id', '<>', $ignore_id)->exists();
  25. }
  26. public static function checkBtnPathIsUnique($path, $ignore_id = 0)
  27. {
  28. return self::query()->where('path', $path)->where('type', self::TYPE_BTN)->where('id', '<>', $ignore_id)->exists();
  29. }
  30. }