0
votes

I'm Create a API with Lumen Using JWT, then the request set to GET this method show the detail about the data like reading page

I try to using Session Like Laravel but it's not working, and i know Lumen not using session + i using JWT token for authentication and this my code

public function show($storyId, $id)
    {
        $part = Story::find($id)->parts()->withCount('comments')->first();

        $link = 'story/'. $storyId.'/part/'.$id;

        if (!Session::has($link)) {
            $part->increment('viewers');
            Session::put($link,1);
        }

        return response()->json($part);
    }

so every request method GET call it increment the viewers during the token not expired, or like youtube viewers as long as browser not closed if i wrong to write a code or implement the code please suggest me for effective code

1

1 Answers

0
votes

I think the best approach to implement video views on your web app: create table with columns ('video_link',address_'ip') and every view store the video link with the viewer ip , so in the next of some visitor view you check if the current link video and vistor ip has exists on views table, if doesn't exist incrment video views count else nothing to do