【发布时间】:2019-06-16 12:29:21
【问题描述】:
我有一个名为 PostController 的控制器和一个名为 Post 的模型。
这是我的 PostController:
use Illuminate\Http\Request;
use App\Post;
class PostsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$posts = Post::all();
return view('posts.index')->with('posts',$posts);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
}
这是我的 post.index :
@if (count($posts) > 1)
@foreach ($posts as $item)
<div class="card-header mb-3">
<h3><a href="/posts/{{ $item->id }}">{{ $item->title }}</a></h3>
<small>Created At {{ $item->created_at }}</small>
</div>
@endforeach
@else
<p>No Post Found</p>
@endif
看下图:
当我点击帖子 1 时,为什么 laravel 会运行 show 方法(如图所示)?
这是否意味着每次我们单击链接时, show 方法都会起作用?
【问题讨论】:
标签: php laravel function methods controller