图片断开链接

时间:2018-11-01 11:31:04

标签: php laravel

我将需要您的帮助,因为我的图像URL在浏览器中似乎已损坏,因此可以肯定我所做的一切正确,或者我认为如此。我想向我的更新配置文件用户acc添加图像,以下是我的代码圈的结构。这是我的用户表架构

 *public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');

            $table->integer('role_id')->default(2);
            $table->string('name');
            $table->string('username')->unique();
            $table->string('email')->unique();
            $table->string('password');
            $table->string('image')->default('default.png');
            $table->text('about')->nullable();
            $table->rememberToken();

            $table->timestamps();
        });
    }*

,这是我的设置控制器,具有updateProfile方法

*public function updateProfile(Request $request)
    {
        $this->validate($request,[
            'name' => 'required',
            'email' => 'required|email',
            'image' => 'required|image',
        ]);
        $image = $request->file('image');
        $slug = str_slug($request->name);
        $user = User::findOrFail(Auth::id());
        if (isset($image))
        {
            $currentDate = Carbon::now()->toDateString();
            $imageName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
            if (!Storage::disk('public')->exists('profile'))
            {
             Storage::disk('public')->makeDirectory('profile');
            }
//            Delete old image form profile folder
            if (Storage::disk('public')->exists('profile/'.$user->image))
            {
                Storage::disk('public')->delete('profile/'.$user->image);
            }
            $profile = Image::make($image)->resize(500,500)->stream();
            Storage::disk('public')->put('profile/'.$imageName,$profile);
        } else {
            $imageName = $user->image;
        }
        $user->name = $request->name;
        $user->email = $request->email;
        $user->image = $imageName;
        $user->about = $request->about;
        $user->save();
        Toastr::success('Profile Successfully Updated :)','Success');
        return redirect()->back();*

,我使用了php artisan storage:link,这是我的视图,链接到我的public / profile目录

 *<a class="avatar" href="{{ route('author.profile',$post->user->username) }}"><img src="{{ Storage::disk('public')->url('profile/'.$post->user->image) }}" alt="Profile Image"></a>*

。预先感谢

1 个答案:

答案 0 :(得分:0)

这是我解决自己的问题的方式,并感谢所有尝试帮助我的人。

 *<a class="avatar" href="{{ route('author.profile',$post->user->username) }}"> 
               <img src="{{ asset('Storage/profile/'.$post->user->image) }}" alt="Profile Image"></a>*