图像保留在我的数据库中,但不显示在前端



我正在用Laravel 5.2做一个项目。我需要创建、编辑和显示用户配置文件。用户配置文件应具有上传的用户图像。下面是我的控制器的代码片段。这是为了保留用户照片,将其放在名为图像的文件中。照片保留在数据库中,它不会放在图像文件夹中,也不会显示在前端。

public function store(UserRequest $request)
{
    /*   User::create($request->all());
       */
    $input=$request->all();
    $input['password']=bcrypt($request->password);
    if ($file=$request->file('photo_id')){
        $name= time() . $file->getClientOriginalName();
        $file->move('images',$name);
        $photo=Photo::create(['file'=>$name]);
        $input['photo_id']=$photo->id;

    }
    User::create($input);
    return redirect('admin/users');
}

这也是我的前端表来显示图像。

 <tr>
       <td><a href="{{route('admin.users.edit', $user->id)}}">{{$user->name}}</a></td>
       <td>{{$user->email}}</td>
       <td><img height='50' src="/images/{{ isset($user->photo)?$user->photo['file']:"has no photo"}}" alt=""></td>
       <td>{{$user->is_active = 1 ? 'Active':'Non-Active' }}</td>
       <td>{{$user->role['name'] }}</td>
       <td>{{$user->created_at->diffForHumans()}}</td>
       <td>{{$user->updated_at->diffForHumans()}}</td>
                            </tr>

我需要将图像放入图像文件夹中,保留在数据库中并显示在前端。请问有人吗?

更改此行

<td><img height='50' src="/images/{{ isset($user->photo)?$user->photo['file']:"has no photo"}}" alt=""></td>

并使用

<td><img height='50' src="{{ url('images/' . AppPhoto::find($user->photo_id)->file) }}" alt=""></td>
//Include valid Photo.php location that you create. I just use demo...

最新更新