Skip to content

Commit b9a73c4

Browse files
author
shellus
committed
优化文章链接,解决restful url冲突
1 parent ad5d632 commit b9a73c4

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

app/Http/Controllers/ArticleController.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public function __construct()
1717
{
1818
$this -> model = new Article();
1919
}
20-
public function index($slug_or_category_id){
21-
if($slug_or_category_id){
22-
if(is_numeric($slug_or_category_id)){
23-
\App\Category::findOrFail($slug_or_category_id)
24-
-> articles;
25-
}else{
26-
27-
}
28-
}
20+
public function index(){
21+
// if($slug_or_category_id){
22+
// if(is_numeric($slug_or_category_id)){
23+
// \App\Category::findOrFail($slug_or_category_id)
24+
// -> articles;
25+
// }else{
26+
//
27+
// }
28+
// }
2929

3030
return view('article.list',[
3131
'list_type' => 'default',

app/Http/Controllers/ShopCartController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function index()
2121
// dump($item -> goods -> showUrl());
2222
// }
2323
return view('shop_cart/list', [
24-
'models' => ShopCart::whereUserId(\Auth::user()->id) -> get(),
24+
'models' => ShopCart::whereUserId(\Auth::user()->id) -> orderBy('id', 'desc') -> get(),
2525
]);
2626
}
2727

app/Http/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666

6767
// Article Routes...
6868

69-
Route::get('/article/{article_id}/{tag_id}', ['as' => 'article.tag.add','uses' => 'ArticleController@getTagAdd']);
70-
Route::get('/article/{slug_or_id}', ['as' => 'article.index','uses' => 'ArticleController@index']);
7169
Route::resource('/article', 'ArticleController');
7270

71+
72+
Route::get('/tag/{id}/{tag_id}', ['as' => 'tag.add_to_article','uses' => 'ArticleController@getTagAdd']);
7373
Route::get('/tag/{slug_or_id}', ['as' => 'article.tag.index','uses' => 'ArticleController@getTag']);
7474
Route::resource('/tag', 'TagController');
7575

resources/views/article/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
add:
2222
<ul class="list-inline">
2323
@foreach (\App\Tag::all() as $tag)
24-
<li><a title="{{ $tag -> description }}" href="{{ route('article.tag.add',[$model->id, $tag->id]) }}"><span class="label label-info">{{ $tag->title }}</span></a></li>
24+
<li><a title="{{ $tag -> description }}" href="{{ route('tag.add_to_article',[$model->id, $tag->id]) }}"><span class="label label-info">{{ $tag->title }}</span></a></li>
2525
@endforeach
2626
</ul>
2727
<form class="form-inline" style="display: inline-block" action="{{ route('tag.store') }}" method="post">

resources/views/layout.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626

2727
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
2828
<ul class="nav navbar-nav">
29-
<li><a href="/">首页</a></li>
29+
<li><a href="{{ route('index') }}">首页</a></li>
30+
<li><a href="{{ route('article.index') }}">文章</a></li>
3031
<li><a href="{{ route('goods.index') }}">商品</a></li>
32+
3133
</ul>
3234

3335
<ul class="nav navbar-nav navbar-right">

0 commit comments

Comments
 (0)