| 123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Components;
- use Illuminate\Support\Facades\Gate;
- trait AsyncResponse{
- protected function gate(string $authorityName)
- {
- if(!Gate::allows($authorityName)){
- echo json_encode(["success"=>false,"data"=>"无权操作"]);
- exit();
- }
- }
- public function error(string $message)
- {
- echo json_encode(["success"=>false,"data"=>$message]);
- exit();
- }
- public function success($message = null)
- {
- $result = ["success"=>true];
- if ($message)$result["data"] = $message;
- echo json_encode($result);
- exit();
- }
- }
|