Reputation: 7962
tl;dr - I already did composer sump-autoload
Question: I am using Intervention Image library. I am updating an existing app that has an Image class that represents an image model. I wish to use the Intervention Image Image class by it's full namespace name.
I narrowed down the fault I wish to resolve to an empty test project with a single route:
Route::get('/{sugar}.jpg', function($sugar)
{
$path = 'C:/some-path/';
$img = Intervention\Image\Image::make($path . $sugar . '.jpg');
return $img->response('jpg');
});
This is the problematic line:
$img = Intervention\Image\Image::make($path . $sugar . '.jpg');
It results in:
Call to undefined method Intervention\Image\Image::make()
However, the namespace appears to be correct:
https://github.com/Intervention/image/blob/master/src/Intervention/Image/Image.php
And if I remove the namespace and do:
$img = Image::make($path . $sugar . '.jpg');
It works perfectly! Only that this would collide with the existing Image class in the real app.
Thanks for reading this far. Any suggestions on how to debug this namespace issue?
Upvotes: 0
Views: 2885
Reputation: 121
Add use Intervention\Image\Facades\Image;
to the top of your controller class.
This helped for me getting access to the image controller.
It should or could like this:
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Response;
use Intervention\Image\Facades\Image;
class AdminController extends Controller{
Upvotes: 1
Reputation: 7962
It appears the class name is incorrect!
There appears to be a class named image but it's not the one I need.
The correct class name is ImageManagerStatic
.
You can do this to handle the name collision:
use Intervention\Image\ImageManagerStatic as someUniqueName;
You can also simply change the line in your config/app
from this
'Image' => 'Intervention\Image\Facades\Image',
to this
'someUniqueName' => 'Intervention\Image\Facades\Image',
Upvotes: 2