Laravel-尝试显示特定线程的结果为空
我的数据库充满了数据,显示了所有的数据工作。但是如果我试图只显示一个特定的线程,我会得到一个空的结果,我不知道为什么 web.phpLaravel-尝试显示特定线程的结果为空,laravel,laravel-5,Laravel,Laravel 5,我的数据库充满了数据,显示了所有的数据工作。但是如果我试图只显示一个特定的线程,我会得到一个空的结果,我不知道为什么 web.php 将放映路线重命名为以下名称: Route::get('/threads/{thread}', 'ThreadsController@show'); 您正在加载的是线程对象,而不是线程对象。根据本教程,路径::get'/Threads/{id}','ThreadsController@show'; 应该进行相同的操作,但是我使用{id}再次得到一个空结果。你能解释
将放映路线重命名为以下名称:
Route::get('/threads/{thread}', 'ThreadsController@show');
您正在加载的是线程对象,而不是线程对象。根据本教程,路径::get'/Threads/{id}','ThreadsController@show'; 应该进行相同的操作,但是我使用{id}再次得到一个空结果。你能解释一下为什么{id}不起作用吗?部分名称应该与函数中提示的类型变量相同。
<?php
namespace App\Http\Controllers;
use App\Thread;
use Illuminate\Http\Request;
class ThreadsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$threads = Thread::latest()->get();
return view('threads.index', compact('threads'));
//return $threads;
}
/**
* 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 \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function show(Thread $thread)
{
//return view('threads.show', compact('thread'));
return $thread;
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function edit(Thread $thread)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Thread $thread)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function destroy(Thread $thread)
{
//
}
}
php artisan --version
Laravel Framework 5.4.32
Route::get('/threads/{thread}', 'ThreadsController@show');