api.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. use Illuminate\Http\Request;
  3. /*
  4. |--------------------------------------------------------------------------
  5. | API Routes
  6. |--------------------------------------------------------------------------
  7. |
  8. | Here is where you can register API routes for your application. These
  9. | routes are loaded by the RouteServiceProvider within a group which
  10. | is assigned the "api" middleware group. Enjoy building your API!
  11. |
  12. */
  13. // 游客可以访问的接口
  14. Route::group([
  15. 'namespace'=> 'Api',
  16. ], function ($router){
  17. // 登录
  18. $router->post('authorizations', 'AuthorizationsController@login')->name('api.authorizations.login');
  19. // 全站搜索
  20. $router->get('search', 'SearchController@index')->name('api.search.index');
  21. // 文章点赞
  22. $router->get('blog/articles/{article}/upvote', 'BlogArticlesController@upvote')->name('api.blog.articles.upvote');
  23. });
  24. // 需要 token 验证的接口
  25. Route::group([
  26. 'namespace'=> 'Api',
  27. 'middleware'=> 'auth:api',
  28. ], function ($router){
  29. // 刷新token
  30. $router->put('authorizations/refresh', 'AuthorizationsController@refresh')
  31. ->name('api.authorizations.refresh');
  32. // 删除token
  33. $router->delete('authorizations/logout', 'AuthorizationsController@logout')
  34. ->name('api.authorizations.logout');
  35. // 获取当前登录用户信息
  36. $router->get('me', 'AuthorizationsController@me')->name('api.me.show');
  37. // 图片资源
  38. $router->post('images', 'ImagesController@store')->name('api.images.store');
  39. $router->post('images?action=update', 'ImagesController@update')->name('api.images.update');
  40. $router->delete('images', 'ImagesController@destroy')->name('api.images.destroy');
  41. // 分类
  42. $router->post('blog/categories', 'BlogCategoriesController@store')->name('api.blog.articles.store');
  43. // 评论
  44. $router->post('replies', 'RepliesController@store')->name('api.replies.store');
  45. $router->delete('replies/{reply}', 'RepliesController@destroy')->name('api.replies.destroy');
  46. });