SystemTermController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\DhammaTerm;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Response;
  6. use Illuminate\Support\Facades\Http;
  7. class SystemTermController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return Response
  13. */
  14. public function index()
  15. {
  16. //
  17. }
  18. /**
  19. * Store a newly created resource in storage.
  20. *
  21. * @return Response
  22. */
  23. public function store(Request $request)
  24. {
  25. //
  26. }
  27. /**
  28. * Display the specified resource.
  29. *
  30. * @param DhammaTerm $dhammaTerm
  31. * @return Response
  32. */
  33. public function show(string $lang, string $word)
  34. {
  35. //
  36. $url = "https://staging.wikipali.org/api/v2/channel-name/_System_Grammar_Term_{$lang}_";
  37. $response = Http::get($url);
  38. if ($response->successful()) {
  39. $channelId = $response['data']['uid'];
  40. $term = DhammaTerm::where('channal', $channelId)
  41. ->where('tag', ':abbr:')
  42. ->where('word', $word)
  43. ->first();
  44. if ($term) {
  45. return $this->ok($term);
  46. } else {
  47. return $this->error('no term');
  48. }
  49. } else {
  50. return $this->error('no channel');
  51. }
  52. }
  53. /**
  54. * Update the specified resource in storage.
  55. *
  56. * @return Response
  57. */
  58. public function update(Request $request, DhammaTerm $dhammaTerm)
  59. {
  60. //
  61. }
  62. /**
  63. * Remove the specified resource from storage.
  64. *
  65. * @return Response
  66. */
  67. public function destroy(DhammaTerm $dhammaTerm)
  68. {
  69. //
  70. }
  71. }