Permission.php 918 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use Carbon\Carbon;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Cache;
  6. class Permission extends Model
  7. {
  8. /**
  9. * @var string
  10. */
  11. protected $table = 'base_permissions';
  12. protected $guarded = [];
  13. /**
  14. * The attributes excluded from the model's JSON form.
  15. *
  16. * @var array
  17. */
  18. protected $hidden = [];
  19. public static function byUrlGetDescription($url, $method)
  20. {
  21. return Cache::tags('model')->remember('model:permission:byUrlGetDescription:' . $url . ':' . $method, Carbon::now()->addDays(1), function () use ($url, $method) {
  22. $info = self::query()->where('url', $url)->where('method', $method)->select(['id', 'name', 'nickname', 'module'])->first();
  23. if ($info) {
  24. return $info->toArray();
  25. }
  26. return false;
  27. });
  28. }
  29. }