【问题标题】:laravel api using passport to fetch data from product?laravel api 使用护照从产品中获取数据?
【发布时间】:2018-12-20 14:48:12
【问题描述】:

在 laravel 中使用 sql 查询从产品表中获取数据需要帮助

通过 laravel 护照 api 认证。

【问题讨论】:

    标签: laravel api laravel-5.6 laravel-passport


    【解决方案1】:

    使用 laravel passport api 身份验证处理访问令牌。

    【讨论】:

      【解决方案2】:

      在你的 api.php 中创建一个路由

      Route::middleware(['auth:api', 'throttle:60'])->group(function () {
          Route::get('products', 'Api\ProductController@getProducts');
      }
      

      在您的 ProductController 中编写 getProducts 函数

      public function getProducts(){
          return Product::all();
      }
      

      使用 Authorization 标头向 /api/products 发送获取请求。它的价值将是您的访问令牌。不要忘记在它之前添加'Bearer'。 (您的访问令牌和承载字之间有空格)。

      我建议你使用 Postman 来完成这项工作。

      【讨论】:

      • 什么是域??
      • 对不起,复制粘贴错误
      • 没有授权可以吗?
      • 如果你在 auth:api 中间件之外设置你的路由,那么你不需要认证
      猜你喜欢
      • 2023-04-03
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 2017-12-09
      相关资源
      最近更新 更多