/ / लारवेल 4.2 पेज व्यू काउंटर - लार्वेल, लार्वेल -4

लारवेल 4.2 पेज व्यू काउंटर - लार्वेल, लार्वेल -4

इसलिए मैंने अपने ऐप में इस पेज व्यू काउंटर को जोड़ा, जो एक कलाकार पेज पर प्रत्येक यात्रा को गिनता है। अभी यदि आप पृष्ठ को ताज़ा करते हैं तो काउंटर प्रत्येक ताज़ा है।

मेरा सवाल यह है कि मैं इसे केवल दिन के अनूठे दौरे गिनने के लिए कैसे बना सकता हूं?

मेरा नियंत्रक:

        if ( $artist ) {

$getartist   = $this->_artist->get($artist, "slug");

if ( $getartist ) {

$getsongs = $this->_song->collections($input, $getartist->id, "ASC");
$this->_artist->updateVisits($getartist->id);
$data = [
"is_artist"   => true,
"artist"      => $getartist,
"songs"       => $getsongs,
"randomsongs" => $this->randomsongs,
];
return $this->view("index", $data);

}

}

काउंटर के लिए कोड है:

$this->_artist->updateVisits($getartist->id);

फिर मेरे कलाकारप्रशासन में:

public function updateVisits($artist_id)
{
$artist = $this->model->where("id",$artist_id)->first();
$artist->visits = $artist->visits+1;
$artist->save();
}

यदि उपयोगकर्ता पेज को रिफ्रेश करता है तो मैं काउंटिंग को कैसे रोक सकता हूं?

उत्तर:

जवाब के लिए 0 № 1

ठीक है मैं कुकीज़ के साथ इस के आसपास एक समाधान मिला मेरे कोड का उपयोग करता है।

public function updateVisits($artist_id)
{
$artist = $this->model->where("id",$artist_id)->first();

// Check if cookies exist
if(!isset($_COOKIE["visited_id" . $artist_id])) {
// If not set cookie and pass counter
setcookie("visited_id" . $artist_id, $artist_id, time()+30);  /* expire in seconds */
$artist->visits = $artist->visits+1;
$artist->save();

// If cookie exist on user computer
} else {
//do nothing
}
}

जवाब के लिए 0 № 2

सबसे पहले a जोड़ें date मैदान पर DB table। फिर अपने फ़ंक्शन को निम्न में बदलें-

public function updateVisits($artist_id)
{
$artist = $this->model->firstOrCreate(["id" => $artist_id,"your_date_field_name"=>date("Y-m-d")]);
$artist->visits = $artist->visits+1;
$artist->save();
}

और जोड़ने के लिए मत भूलना id, your_date_field_name पर fillable होने के लिए सरणी mass आबंटित।