简体   繁体   中英

No query results for model [App\Models\XXXX]

I'm getting this error message when updating the data via the PUT method on Postman.

No query results for model [App\Models\Post].

Code

public function store(Request $request)
    {
        $post = $request->isMethod('put') ? Post::findOrFail
        ($request->post_id): new Post;

        $post->id= $request->input('id');
        $post->title= $request->input('title');
        $post->body= $request->input('body');

        if($post->save()){
            return response($post);
        }
    }

在此处输入图像描述

Reference: https://github.com/Devgroup-Asia/lumenblog/blob/main/app/Http/Controllers/PostsController.php

The issue is due to this below code.

 Post::findOrFail($request->post_id)

Post with $request->post_id doesnot found. You may be missing to send post_id from form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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