api.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. use Illuminate\Http\Request;
  3. use Illuminate\Support\Facades\Route;
  4. use App\Http\Resources\UserResource;
  5. use App\Http\Resources\GameResource;
  6. use App\Http\Resources\CommentResource;
  7. use App\Http\Resources\CriticResource;
  8. use App\Http\Resources\Game_genreResource;
  9. use App\Http\Resources\GenreResource;
  10. use App\Http\Resources\ReviewResource;
  11. use App\Http\Resources\SpecializationResource;
  12. use App\Models\User;
  13. use App\Models\Game;
  14. use App\Models\Comment;
  15. use App\Models\Critic;
  16. use App\Models\Game_genre;
  17. use App\Models\Genre;
  18. use App\Models\Review;
  19. use App\Models\Specialization;
  20. /*
  21. |--------------------------------------------------------------------------
  22. | API Routes
  23. |--------------------------------------------------------------------------
  24. |
  25. | Here is where you can register API routes for your application. These
  26. | routes are loaded by the RouteServiceProvider within a group which
  27. | is assigned the "api" middleware group. Enjoy building your API!
  28. |
  29. */
  30. Route::middleware('auth:api')->get('/user', function (Request $request) {
  31. return $request->user();
  32. });
  33. Route::get('/user/{id}', function (string $id) { return new UserResource(User::findOrFail($id)); });
  34. Route::get('/users', function () { return UserResource::collection(User::all()); });
  35. Route::get('/game/{id}', function (string $id) { return new GameResource(Game::findOrFail($id)); });
  36. Route::get('/games', function () { return GameResource::collection(Game::all()); });
  37. Route::get('/comment/{id}', function (string $id) { return new CommentResource(Comment::findOrFail($id)); });
  38. Route::get('/comments', function () { return CommentResource::collection(Comment::all()); });
  39. Route::get('/critic/{id}', function (string $id) { return new CriticResource(Critic::findOrFail($id)); });
  40. Route::get('/critics', function () { return CriticResource::collection(Critic::all()); });
  41. Route::get('/game_genre/{id}', function (string $id) { return new Game_genreResource(Game_genre::findOrFail($id)); });
  42. Route::get('/game_genres', function () { return Game_genreResource::collection(Game_genre::all()); });
  43. Route::get('/genre/{id}', function (string $id) { return new GenreResource(Genre::findOrFail($id)); });
  44. Route::get('/genres', function () { return GenreResource::collection(Genre::all()); });
  45. Route::get('/review/{id}', function (string $id) { return new ReviewResource(Review::findOrFail($id)); });
  46. Route::get('/reviews', function () { return ReviewResource::collection(Review::all()); });
  47. Route::get('/specialization/{id}', function (string $id) { return new SpecializationResource(Specialization::findOrFail($id)); });
  48. Route::get('/specializations', function () { return SpecializationResource::collection(Specialization::all()); });