至此,我們可以新建、顯示、列出文章了。下面我們添加一些鏈接,指向這些頁面。
打開 app/views/welcome/index.blade.php 文件,添加:
~~~
{{ link_to_route('articles.index', 'My Blog') }}
~~~
link_to_route 是 Laravel 內置的視圖幫助方法之一,根據提供的文本和地址創建超鏈接。這上面這段代碼中,地址是文章列表頁面。
接下來添加到其他頁面的鏈接。先在 app/views/articles/index.blade.php 中添加“New Article”鏈接,放在
標簽之前:
~~~
{{ link_to_route('articles.create', 'New article') }}
~~~
點擊這個鏈接后,會轉向新建文章的表單頁面。
然后在 app/views/articles/create.blade.php 中添加一個鏈接,位于表單下面,返回到 index 動作:
~~~
{{ link_to_route('articles.index', 'Back') }}
~~~
最后,在 app/views/articles/show.blade.php 模板中添加一個鏈接,返回 index 動作,這樣用戶查看某篇文章后就可以返回文章列表頁面了:
~~~
{{ link_to_route('articles.index', 'Back') }}
~~~