标签:forum 搭建 obj turn primary route avatar tle show
首先我们注册resource路由:
Route::get(‘/‘, ‘PostsController@index‘); Route::resource(‘discussions‘, ‘PostsController‘);
在PostsController的show方法返回一个视图:
public function show($id) { // 取到单条帖子 $discussion = Discussion::findOrFail($id); // 返回视图 return view(‘forum.show‘, compact(‘discussion‘)); }
创建show.blade.php
@extends(‘app‘) @section(‘content‘) <div class="jumbotron"> <div class="container"> <div class="media"> <div class="media-left"> <a href="#"> <img class="media-object img-circle" src="{{ $discussion->user->avatar }}" alt="64x64" width="64px"> </a> </div> <div class="media-body"> <h4 class="media-heading">{{ $discussion->title }} <a class="btn btn-primary btn-lg pull-right" href="#" role="button">修改帖子 ?</a> </h4> {{ $discussion->user->name }} </div> </div> </div> </div> <div class="container"> <div class="row"> <div class="col-md-9"> <div class="blog-post"> {{ $discussion->body }} </div> </div> </div> </div> @stop
在首页展示页面加上a标签
<div class="media-body"> <h4 class="media-heading"><a href="/discussions/{{ $discussion->id }}">{{ $discussion->title }}</a></h4> {{ $discussion->user->name }} </div>
标签:forum 搭建 obj turn primary route avatar tle show
原文地址:http://www.cnblogs.com/Alex-sk/p/6658579.html