AsyncResponse.php 556 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Components;
  3. use Illuminate\Support\Facades\Gate;
  4. trait AsyncResponse{
  5. protected function gate(string $authorityName)
  6. {
  7. if(!Gate::allows($authorityName)){
  8. echo ["success"=>false,"data"=>"无权操作"];
  9. exit();
  10. }
  11. }
  12. public function error(string $message)
  13. {
  14. echo json_encode(["success"=>false,"data"=>$message]);
  15. exit();
  16. }
  17. public function success($message)
  18. {
  19. echo json_encode(["success"=>true,"data"=>$message]);
  20. exit();
  21. }
  22. }