如何使 ProfileViews 在 laravel 中计数?
How to make ProfileViews count in laravel?
我需要帮助。如何在 Laravel 8 中创建个人资料访客?我还没有写代码,我什至不知道如何完成这个任务。如果你能帮助我,我将不胜感激。
您可以在没有任何个人资料的情况下离开访客。他无需身份验证即可访问 public 个网页,因此只有登录用户才能拥有个人资料。
更新
使用 cookie 分两步提出骨架
1- 当用户在个人资料页面上发出请求时,生成一个唯一标识符并将其存储在具有足够长有效期的用户 cookie 中(如果它尚不存在)
2- 在向用户发送响应之前使用此唯一令牌注册一个新的观看次数(如果尚未完成)。
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;
use App\Http\Controllers\Controller;
public function getProfilePage(Request $request){
if(!Cookie::has('uniqueId')){
$uniqueId = Str::uuid(); // generate unique id for current user
Cookie::queue('uniqueId', $uniqueId, [live time in minutes]);
// save it using Cookie::queue
// one year for example as live time
}
// check if view count already exists for $uniqueId
// and save it in a persistent way if not
// other stuff ....
return ....
}
我需要帮助。如何在 Laravel 8 中创建个人资料访客?我还没有写代码,我什至不知道如何完成这个任务。如果你能帮助我,我将不胜感激。
您可以在没有任何个人资料的情况下离开访客。他无需身份验证即可访问 public 个网页,因此只有登录用户才能拥有个人资料。
更新
使用 cookie 分两步提出骨架
1- 当用户在个人资料页面上发出请求时,生成一个唯一标识符并将其存储在具有足够长有效期的用户 cookie 中(如果它尚不存在)
2- 在向用户发送响应之前使用此唯一令牌注册一个新的观看次数(如果尚未完成)。
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;
use App\Http\Controllers\Controller;
public function getProfilePage(Request $request){
if(!Cookie::has('uniqueId')){
$uniqueId = Str::uuid(); // generate unique id for current user
Cookie::queue('uniqueId', $uniqueId, [live time in minutes]);
// save it using Cookie::queue
// one year for example as live time
}
// check if view count already exists for $uniqueId
// and save it in a persistent way if not
// other stuff ....
return ....
}