0

我需要帮助。如何在Laravel 8中创建个人资料访问者?我还没有编写代码,我什至不知道如何完成这项任务。如果您能帮助我,我将不胜感激。

4

1 回答 1

1

您可以在没有任何个人资料的情况下离开访问者。他无需身份验证即可访问公共网页,因此只有登录用户才有个人资料。

更新

使用 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 ....
}
于 2021-01-29T15:32:54.977 回答