File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -360,12 +360,26 @@ public function showCategory($id)
360360
361361 public function showCategoryBySlug ($ seo_url_key )
362362 {
363- return $ this ->showCategory (BlogCategory::where ('seo_url_key ' , $ seo_url_key )->firstOrFail ()->id );
363+ $ categoryId = BlogCategory::where ('seo_url_key ' , $ seo_url_key )->value ('id ' );
364+ if (!$ categoryId ) {
365+ return response ()->json ([
366+ 'success ' => false ,
367+ 'message ' => '分类不存在 '
368+ ], 404 );
369+ }
370+ return $ this ->showCategory ($ categoryId );
364371 }
365372
366373 public function showArticleBySlug ($ seo_url_key )
367374 {
368- return $ this ->showArticle (BlogArticle::where ('seo_url_key ' , $ seo_url_key )->firstOrFail ()->id );
375+ $ articleId = BlogArticle::where ('seo_url_key ' , $ seo_url_key )->value ('id ' );
376+ if (!$ articleId ) {
377+ return response ()->json ([
378+ 'success ' => false ,
379+ 'message ' => '文章不存在 '
380+ ], 404 );
381+ }
382+ return $ this ->showArticle ($ articleId );
369383 }
370384
371385 // 格式化响应数据
Original file line number Diff line number Diff line change 6868 // 文章接口
6969 Route::get ('articles ' , 'listArticles ' )->name ('v1.blog.articles.index ' );
7070 Route::get ('articles/{id} ' , 'showArticle ' )->name ('v1.blog.articles.show ' );
71- Route::get ('articles/by-slug/{seo_url_key} ' , 'showCategoryBySlug ' )->name ('v1.blog.categories.show.slug ' );
71+ Route::get ('articles/by-slug/{seo_url_key} ' , 'showArticleBySlug ' )->name ('v1.blog.categories.show.slug ' );
7272 });
7373
7474});
You can’t perform that action at this time.
0 commit comments