dongtao4319 2015-10-03 14:03
浏览 150
已采纳

获取用户的电子邮件 - Laravel 5 PHP

I'm attempting to store the email address of any user who uploads a file into an "uploader_name" string variable. I've attempted using the following code whichout success - attempting to upload the file will result in a Class 'App\Http\Controllers\Auth' not found error message being thrown back. I know this is a pretty basic question, but I can't seem to find any answers which specifically work with Laravel 5.

This is what I'm trying to use currently without success.

$filelist->uploader_name = Auth::user()->email;

If it helps, here's the full function which saves some of the automatic information of the file.

public function store()
{
    $filelist = new Filelist($this->request->all());
    //store file details - thanks to Jason Day on the unit forum for helping with some of this
    $filelist->name = $this->request->file('asset')->getClientOriginalName();
    $filelist->file_type = $this->request->file('asset')->getClientOriginalExtension();
    $filelist->file_size = filesize($this->request->file('asset'));
    $filelist->uploader_name = Auth::user()->email;
    $filelist->save();
    // Save uploaded file
    if ($this->request->hasFile('asset') && $this->request->file('asset')->isValid()) {
        $destinationPath = public_path() . '/assets/';
        $fileName = $filelist->id . '.' . $this->request->file('asset')->guessClientExtension();
        $this->request->file('asset')->move($destinationPath, $fileName);

    }



    return redirect('filelists');
}
  • 写回答

2条回答 默认 最新

  • duan1989643 2015-10-03 14:24
    关注

    You get not found error, because you don't use the right namespace.

    You can resolve this if you use the use keyword like this:

    use Auth;
    
    public uploadController {
    ...
    }
    

    Or you can use the full namespace:

    $filelist->uploader_name = \Auth::user()->email;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算