Reputation: 1309
I installed intervention image using composer.phar require intervention/image .
Adding the Image' => Intervention\Image\Facades\Image::class
, in aliases and Intervention\Image\ImageServiceProvider::class
, in 'providers' in config/app.php.
But still Class App\Http\Controllers\Image
not found.
If I write use Image; on the top of the controller then this happen : GD Library extension not available with this PHP installation. To solve it I uncommented the extension=gd in the php.ini file. But nothing change.
Pls can you tell me ,where I am wrong.
This is my code :
public function Store(Request $req){
//validation
$validation = $req->validate([
'brand_name' => 'required|unique:brands|min:3',
'brand_image' => 'required|mimes:jpg,jpeg,png'
]);
//file name and store
$brand_image = $req->file('brand_image');
$name_gen = hexdec(uniqid()).".".$brand_image->getClientOriginalExtension();
Image::make($brand_image)->resize(300,200)->save('image/brand/'.$name_gen);
$storingToDatabase = 'image/brand/'.$name_gen;
//Insertion
$brand = new Brand();
$brand->brand_name = $req->brand_name;
$brand->brand_image= $storingToDatabase;
$brand->created_at = Carbon::now();
$brand->save();
return back()->with('success','Image inserted successfully');
}
Upvotes: 2
Views: 4744
Reputation: 1
check if the column name in the table you want to insert name and image are the same and code it
modelname::create([ 'column_name' => $image_path
;
in model write. protected $fillable = ['file'];
Upvotes: 0
Reputation: 2196
You just can keep using Image
in your controller, but by adding at the beginning
use Intervention\Image\Facades\Image;
That will make use of the Intervention package instead.
Upvotes: 2