Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel雄辩:每次访问增加一个访问列_Php_Mysql_Laravel_Eloquent_Increment - Fatal编程技术网

Php laravel雄辩:每次访问增加一个访问列

Php laravel雄辩:每次访问增加一个访问列,php,mysql,laravel,eloquent,increment,Php,Mysql,Laravel,Eloquent,Increment,我的站点中有我的帖子模型。我的帖子模型有一列存储访问量。当用户访问我的帖子时,我的帖子应该增加1。 我确实知道如何做到这一点,但我的问题是,当我在我的模型中将它增加1时,它将增加2 我在控制器中编写了以下代码: $new_post_inst = Post::where('id','=',$id)->first(); $new_post_inst->increment('visit'); public function get_id($id) { // cat

我的站点中有我的帖子模型。我的帖子模型有一列存储访问量。当用户访问我的帖子时,我的帖子应该增加1。 我确实知道如何做到这一点,但我的问题是,当我在我的模型中将它增加1时,它将增加2

我在控制器中编写了以下代码:

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->increment('visit');
    public function get_id($id) {

    // cat

    $cat = Category::join('catrelations', 'catrelations.idcat', '=', 'categories.id')->orderBy('categories.id', 'ASC')->get();

    // menu

    $nav = Nav::orderBy('index', 'DESC')->get();

    $post = Post::find($id);

    $setting = Settings::find(1);

    $comments = Comment::where('post_id', '=', $id)->orderBy('id', 'asc')->get();

    $get_reply = array();

    $get_reply_id = array();

    //$counter = 0;

    //var_dump($comments);

    foreach ($comments as $comment) {

        $reply = Reply::where('parentId', '=', $comment->id)->get();

        if (!$reply->isEmpty()) {

            //$arr_reply[$comment->id] = $reply;

            //echo $comment->id.' has reply!!!!!<br>';

            //$reply_parent_id = $comment->id;

            $counter = 0;

            foreach ($reply as $replying) {

                $get_reply[$comment->id][$counter] = Comment::where('id', '=', $replying->comment_id)->get();

                //$comment_reply_id = $replying->comment_id;

                //$reply_arr = array();

                //$reply_arr[$comment->id] =  $comment_reply_id;

                //echo 'The reply is: '.$comment_reply_id.'<br>';

                foreach ($get_reply[$comment->id][$counter] as $key => $value) {

                    //($value->text);

                    $get_reply_id[] = $value->id;
                }

                $counter++;
            }

            //$counter++;


        }
    }

    $post_owner_info = User::select('id', 'first_name', 'last_name', 'image', 'desc')->find($post->user_id);

    $arr = array();

    $arr['comments'] = $comments;

    $arr['post'] = $post;

    //$arr['reply'] = $reply;

    //var_dump($get_reply);

    //var_dump($get_reply_id);
    $new_post_inst = Post::where('id','=',$id)->first();
    $new_post_inst->increment('visit');

    return View::make('blogsingle', compact('arr'))->with('setting', $setting)->with('post', $post)->with('nav', $nav)->with('get_reply', $get_reply)->with('get_reply_id', $get_reply_id)->with('cat', $cat)->with('post_owner_info', $post_owner_info);
}
这是我的控制器:

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->increment('visit');
    public function get_id($id) {

    // cat

    $cat = Category::join('catrelations', 'catrelations.idcat', '=', 'categories.id')->orderBy('categories.id', 'ASC')->get();

    // menu

    $nav = Nav::orderBy('index', 'DESC')->get();

    $post = Post::find($id);

    $setting = Settings::find(1);

    $comments = Comment::where('post_id', '=', $id)->orderBy('id', 'asc')->get();

    $get_reply = array();

    $get_reply_id = array();

    //$counter = 0;

    //var_dump($comments);

    foreach ($comments as $comment) {

        $reply = Reply::where('parentId', '=', $comment->id)->get();

        if (!$reply->isEmpty()) {

            //$arr_reply[$comment->id] = $reply;

            //echo $comment->id.' has reply!!!!!<br>';

            //$reply_parent_id = $comment->id;

            $counter = 0;

            foreach ($reply as $replying) {

                $get_reply[$comment->id][$counter] = Comment::where('id', '=', $replying->comment_id)->get();

                //$comment_reply_id = $replying->comment_id;

                //$reply_arr = array();

                //$reply_arr[$comment->id] =  $comment_reply_id;

                //echo 'The reply is: '.$comment_reply_id.'<br>';

                foreach ($get_reply[$comment->id][$counter] as $key => $value) {

                    //($value->text);

                    $get_reply_id[] = $value->id;
                }

                $counter++;
            }

            //$counter++;


        }
    }

    $post_owner_info = User::select('id', 'first_name', 'last_name', 'image', 'desc')->find($post->user_id);

    $arr = array();

    $arr['comments'] = $comments;

    $arr['post'] = $post;

    //$arr['reply'] = $reply;

    //var_dump($get_reply);

    //var_dump($get_reply_id);
    $new_post_inst = Post::where('id','=',$id)->first();
    $new_post_inst->increment('visit');

    return View::make('blogsingle', compact('arr'))->with('setting', $setting)->with('post', $post)->with('nav', $nav)->with('get_reply', $get_reply)->with('get_reply_id', $get_reply_id)->with('cat', $cat)->with('post_owner_info', $post_owner_info);
}
你可以这样试试

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->increment('visit',1);
你可以这样试试

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->increment('visit',1);
试试这个:

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->visit+=1;
$new_post_inst->save();
或者这个:

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->update(array('visit' => $new_post_inst->visit+1));
试试这个:

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->visit+=1;
$new_post_inst->save();
或者这个:

$new_post_inst = Post::where('id','=',$id)->first();
$new_post_inst->update(array('visit' => $new_post_inst->visit+1));

我四处搜索了一下,这可能是正在发出第二个请求的favicon图标。你是怎么申报的?或者你可以把它移走,看看它是否真的是favicon?

我四处搜索了一下,这可能是正在发出第二个请求的favicon图标。你是怎么申报的?或者您可以将其移除,看看它是否真的是favicon?

您可以向我们展示您的完整控制器和型号吗?您是否尝试过:$new\u post\u inst->increment('visit',1);您能向我们展示您的完整控制器和型号吗?您尝试过:$new\u post\u inst->increment('visit',1);我试过:$new\u post\u inst->increment('visit',1);现在,但这不是答案。我的数据库中保存了75次访问,但在我完成后,问题仍然存在,新的我的数据库中有77次访问。你能检查一下是否存在双重重定向吗?我如何找到是否存在双重重定向?我已经尝试过:$new\u post\u inst->increment('visit',1);现在,但这不是答案。我有75次访问保存在我的数据库中,但我的问题仍然存在,新的我有77次访问在我的数据库中。你能检查是否有双重重定向?我如何才能找到我是否有?不幸的是,没有任何主题工作。我不知道为什么它总是增加2!!!!请帮忙。不幸的是,这些主题都不起作用。我不知道为什么它总是增加2!!!!请帮忙。