TaxRateController.php 959 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\TaxRate;
  5. class TaxRateController extends Controller
  6. {
  7. use AsyncResponse;
  8. public function get()
  9. {
  10. return TaxRate::query()->get();
  11. }
  12. public function index()
  13. {
  14. $taxRates = TaxRate::query()->orderByDesc("id")->paginate(50);
  15. return view("maintenance.taxRate.index",compact("taxRates"));
  16. }
  17. public function save()
  18. {
  19. $this->gate("税率-编辑");
  20. $value = request("value");
  21. if (!is_numeric($value) || $value>=100)$this->error("非法值");
  22. if (request("id"))$taxRate = TaxRate::query()->where("id",request("id"))->update(["value"=>$value]);
  23. else $taxRate = TaxRate::query()->create(["value"=>$value]);
  24. $this->success($taxRate);
  25. }
  26. public function destroy()
  27. {
  28. $this->gate("税率-删除");
  29. $this->success(TaxRate::destroy(request("id")));
  30. }
  31. }