模型没有查询结果?但为什么?

时间:2016-03-22 14:46:24

标签: php laravel model

就像在标题中写的那样,我得到了一个:

No query results for model [App\Models\Thread\Comment]. 

错误讯息。在我尝试删除线程后,我收到此错误。有趣的是,此错误消息显示"评论模型没有结果。但我不想删除一个帖子,而不是评论。如果线程有一些评论并不重要,我每次尝试都会收到此错误消息。我无法说出原因,因为我还没有改变评论模型。有人可以看看吗?

我的评论模型:

<?php
namespace App\Models\Thread;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    public $table = 'comments';
    public $fillable = [
        'comment',
        'thread_id',
        'user_id',
    ];

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

线程模型:

<?php
namespace App\Models\Thread;

use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    public $table = 'thread';
    public $fillable = [
        'thread',
        'content',
        'user_id',
        'themen_id',
    ];

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

    public function threadthema()
    {
        return $this->belongsTo('App\Thread\Thema', 'thema_id', 'id');
    }
}

删除路线:

Route::delete('/show/{id}', ['as' => 'destroycomment', 'uses' => 'Test\\TestController@destroycomment']);

线程+注释所在的刀片:

http://pastebin.com/0NUPx18C

在控制器中销毁方法:

public function destroy($id)
{
    $thread = Thread::query()->findOrFail($id);
    $thread->delete();
    return redirect(action('Test\\TestController@startpage', [Auth::user()->id]));
}

0 个答案:

没有答案