How to do a visit counter in Laravel 5?

0

I am working on Laravel 5.3 and I am looking for some package or some data to make a visit counter for both a web in general, and for every article that contains the site. I'm more interested in each article.

    
asked by Cidius 23.09.2016 в 01:27
source

1 answer

1

You can do it in the following way.

you add use Cache;

Then you will have to add the following in your method.

public function show($id){

    $variable = nameModelo::find($id);
    if(Cache::has($id)==false){
        Cache::add($id,'contador',0.30);
        $variable->total_visitas++;
        $variable->save();
    }
    return view('index')->with('variable',$variable);
}

Then you go to your view index or where you put in the view and it would be type

<div aling="center">
    {{$variable->total_visitas}}
</div>

This is how I implement it in Laravel 5.1

    
answered by 23.09.2016 в 07:51