'image source not readable
I want to upload an image from external source but I get an error that image source not readable, I really do not know whether the URL for the image is incomplete or it is another issue here is my code
<?php
namespace App\Http\Controllers;
use Intervention\Image\Facades\Image;
use App\Models\User;
use Illuminate\Http\Request;
class ProfilesController extends Controller
{
public function index(\App\Models\User $user)
{
// if (!isset($user)){
// return abort(404);
// }else{
// $user = User::find($user);
// return view('profiles.index',[
// 'user'=> $user,
// ]);
// }
return view('profiles.index',compact('user'));
}
public function edit(\App\Models\User $user)
{
$this->authorize('update',$user->profile);
return view('profiles.edit',compact('user'));
}
public function update(User $user){
$this->authorize('update',$user->profile);
$data = request()->validate([
'title'=>'required',
'description'=>'required',
'url'=>'url',
'image'=>'',
]);
if(request('image')){
$imagePath = (request('image')->store('profile','public'));
$image = Image::make(public_path("storage/{$imagePath}"))->fit(100,100);
$image->save();
auth()->user()->profile->update(array_merge(
$data,
['image'=>$imagePath]
));
}
return redirect("/profile/{$user->id}");
}
}
any help guys?, i will really appreciate below is the error
Intervention\Image\Exception\NotReadableException Image source not readable
Solution 1:[1]
use Image;
$destinationPath = public_path('storage/{$imagePath}');
$img = Image::make($image->path());
$img->resize(100, 100, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['imagename']);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Martin Amu |