api.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. use Illuminate\Http\Request;
  3. use Illuminate\Support\Facades\Route;
  4. /*
  5. |--------------------------------------------------------------------------
  6. | API Routes
  7. |--------------------------------------------------------------------------
  8. |
  9. | Here is where you can register API routes for your application. These
  10. | routes are loaded by the RouteServiceProvider within a group which
  11. | is assigned the "api" middleware group. Enjoy building your API!
  12. |
  13. */
  14. Route::middleware('auth:api')->get('/user', function (Request $request) {
  15. return $request->user();
  16. });
  17. Route::get('/product/test', function (Request $request) {
  18. $productService = new \App\MicroApi\Services\ProductService();
  19. $product = new \App\MicroApi\Items\ProductItem();
  20. $product->brand_id = 1;
  21. $product->sku = \Illuminate\Support\Str::random(16);
  22. $product->name = "微服务架构";
  23. $product->slug = 'microservice';
  24. $product->description = "基于 Laravel + Go Micro 框架构建微服务系统";
  25. $product->cover = 'https://qcdn.xueyuanjun.com/wp-content/uploads/2019/06/94fe5973d09b0ad753082b6b1ba46f3d.jpeg';
  26. $product->price = 199;
  27. $product->sale_price = 99;
  28. $product->quantity = 1000;
  29. $newProduct = $productService->create($product);
  30. dd($productService->getById($newProduct->id, true));
  31. });