修改头像后保存到octobercms数据库

save an avatar in octobercms database after i modified it

在使用干预图像调整用户头像后,我尝试将其存储在 octobercms 数据库中,如下代码:

        if (Input::hasFile('avatar')) {


    $file= Input::file('avatar');

  $filenamewithextension =   $file->getClientOriginalName();


   //get filename without extension
           $filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);


  //get file extension
      $extension = $file->getClientOriginalExtension();


   //filename to store
           $filenametostore = $filename.'_'.time().'.'.$extension;





            Storage::put('public/profile_images/'. $filenametostore, fopen($file, 'r+'));
            Storage::put('public/profile_images/thumbnail/'. $filenametostore, fopen($file, 'r+'));



    //Resize image here
           $thumbnailpath ='storage/app/public/profile_images/thumbnail/'.$filenametostore;


             $img = Image::make($file->getRealPath());
             $img->crop(request('w'), request('h'), request('x1'), request('y1'));


      $img->save($thumbnailpath);

        $user->avatar=  $filenametostore;


        }

我收到这个错误:

The avatar must be an image.
C:\wamp643\www\october3\vendor\october\rain\src\Database\Traits\Validation.php line 340

我真的不知道该怎么办,我是初学者

请帮帮我!!

你只是设置文件名,你应该在那里设置图像的完整路径。

Assuming you have already avatar attachment relation in user model

public $attachOne = [
    'avatar' => ['System\Models\File']
];

replace

$user->avatar = $filenametostore;

with

$user->avatar = storage_path($thumbnailpath);

也许应该有用。

如有疑问请评论。