繁体   English   中英

Laravel NotFoundHttpException没有模型的查询结果

[英]Laravel NotFoundHttpException No query results for model

我有错误NotFoundHttpException没有模型[App \\ ThreadForum]的查询结果

我的web.php

Route::get('/threads','ThreadForumController@index');
Route::post('/threads','ThreadForumController@store');
Route::get('/threads/create','ThreadForumController@create');
Route::get('/threads/{thread}','ThreadForumController@show')->name('threads.show');

我的模特

namespace App;

use Illuminate\Database\Eloquent\Model;

class ThreadForum extends Model
{
    protected $fillable = [
        'user_id','title','body'
    ];

    public  function  path(){
        return route('threads.show',$this->id);
    }
    public function  replies(){
        return $this->hasMany('App\Reply');
    }

    public function creator(){
        return $this->belongsTo('App\User', 'user_id');
    }

    public  function  addReply($reply){
        $this->replies()->create($reply);

    }
}

我的控制器

namespace App\Http\Controllers;

use App\ThreadForum;
use Illuminate\Http\Request;

class ThreadForumController extends Controller
{
    public function  __construct()
    {
        $this->middleware('auth')->only('store');
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $threads = ThreadForum::all();
        return view('threads.index', compact('threads'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('threads.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        dd('store');
        /*$thread = ThreadForum::create([
            'user_id'=>auth()->id(),
            'title'=>$request['title'],
            'body'=>$request['body']
        ]);
        redirect($thread->path());*/
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\ThreadForum  $threadForum
     * @return \Illuminate\Http\Response
     */
    public function show(ThreadForum $thread)
    {
        return view('threads.show',compact('thread'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\ThreadForum  $threadForum
     * @return \Illuminate\Http\Response
     */
    public function edit(ThreadForum $threadForum)
    {

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\ThreadForum  $threadForum
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, ThreadForum $threadForum)
    {

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\ThreadForum  $threadForum
     * @return \Illuminate\Http\Response
     */
    public function destroy(ThreadForum $threadForum)
    {
        //
    }

}

所有函数都运行良好,但是当我运行post('/ threads')来存储新记录时,我得到了错误。 我尝试使用dd('store')进行调试,但没有看到此文本,只有错误。 我该如何解决? 谢谢。

我无法发表评论,但要转储,您必须使用dd($request)而不是dd($store)

编辑:我认为问题在于显示方法。 您使用紧凑型,但是上面没有任何变量。 因此,您无法传递任何内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM