Laravel /干预图像类 - 未找到类

时间:2014-12-09 08:44:32

标签: php class laravel image-resizing

我刚刚按照此处的说明安装了干预图片类:http://image.intervention.io/getting_started/installation

我还在config / app.php文件中添加了这两行:

  

'干预\图片\ ImageServiceProvider'

     

'图像' => '干预\图片\外墙\图片'

当我打开我的网站时,我收到此错误:

Class 'Intervention\Image\ImageServiceProvider' not found

为什么这样,我现在该怎么做?

8 个答案:

答案 0 :(得分:48)

第1步:

"intervention/image": "dev-master"添加到composer.json文件的“require”部分。

"require": {
    "laravel/framework": "4.1.*",
    "intervention/image": "dev-master"
},

第2步:

Run CMD;
$ composer install

如果您收到此警告:

  

警告:锁定文件与composer.json中的最新更改不是最新的。您可能会过时的依赖项。运行更新以更新它们。

执行$ composer update然后$ composer install

第3步:

打开config/app.php文件。将其添加到$providers数组。

Intervention\Image\ImageServiceProvider::class

第4步:

接下来将其添加到$aliases数组。

'Image' => Intervention\Image\Facades\Image::class

第5步:

如果有错误;

  

类'干预\ Image \ ImageServiceProvider'未找到

尝试

$ composer update

答案 1 :(得分:13)

试试这个,它适合我。

use Intervention\Image\Facades\Image as Image;

答案 2 :(得分:4)

composer require intervention/image

绝对解决了这个问题。

答案 3 :(得分:2)

尝试在\之前添加Image符号:

\Image::make();

它对Laravel 5.3和Intervention 2.3有帮助

答案 4 :(得分:2)

"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
    "laravel/framework": "4.2.*",
    "intervention/image": "dev-master"
},

在composer.json中添加新代码“intervention / image”:“dev-master”, cmd

$ composer update

答案 5 :(得分:2)

只需在控制器上写下

  

使用Image;

配置/ app.php 提供商

  

干预\图片\ ImageServiceProvider ::类,

别名

  

'图像' =>干预\图片\外墙\图片::类,

答案 6 :(得分:0)

在laravel 5.8中,您可以轻松修复该错误。

首先打开配置文件夹app.php文件添加提供程序

   Intervention\Image\ImageServiceProvider::class,

然后转到别名并添加

    'Image' => Intervention\Image\Facades\Image::class

打开要添加图像的控制器

  use Image;

提供者

           'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    Illuminate\Cache\CacheServiceProvider::class,
    Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
    Illuminate\Cookie\CookieServiceProvider::class,
    Illuminate\Database\DatabaseServiceProvider::class,
    Illuminate\Encryption\EncryptionServiceProvider::class,
    Illuminate\Filesystem\FilesystemServiceProvider::class,
    Illuminate\Foundation\Providers\FoundationServiceProvider::class,
    Illuminate\Hashing\HashServiceProvider::class,
    Illuminate\Mail\MailServiceProvider::class,
    Illuminate\Notifications\NotificationServiceProvider::class,
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Pipeline\PipelineServiceProvider::class,
    Illuminate\Queue\QueueServiceProvider::class,
    Illuminate\Redis\RedisServiceProvider::class,
    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    Intervention\Image\ImageServiceProvider::class,

    /*
     * Package Service Providers...
     */

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    // App\Providers\BroadcastServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,

],

别名

      'aliases' => [

    'App' => Illuminate\Support\Facades\App::class,
    'Arr' => Illuminate\Support\Arr::class,
    'Artisan' => Illuminate\Support\Facades\Artisan::class,
    'Auth' => Illuminate\Support\Facades\Auth::class,
    'Blade' => Illuminate\Support\Facades\Blade::class,
    'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
    'Bus' => Illuminate\Support\Facades\Bus::class,
    'Cache' => Illuminate\Support\Facades\Cache::class,
    'Config' => Illuminate\Support\Facades\Config::class,
    'Cookie' => Illuminate\Support\Facades\Cookie::class,
    'Crypt' => Illuminate\Support\Facades\Crypt::class,
    'DB' => Illuminate\Support\Facades\DB::class,
    'Eloquent' => Illuminate\Database\Eloquent\Model::class,
    'Event' => Illuminate\Support\Facades\Event::class,
    'File' => Illuminate\Support\Facades\File::class,
    'Gate' => Illuminate\Support\Facades\Gate::class,
    'Hash' => Illuminate\Support\Facades\Hash::class,
    'Lang' => Illuminate\Support\Facades\Lang::class,
    'Log' => Illuminate\Support\Facades\Log::class,
    'Mail' => Illuminate\Support\Facades\Mail::class,
    'Notification' => Illuminate\Support\Facades\Notification::class,
    'Password' => Illuminate\Support\Facades\Password::class,
    'Queue' => Illuminate\Support\Facades\Queue::class,
    'Redirect' => Illuminate\Support\Facades\Redirect::class,
    'Redis' => Illuminate\Support\Facades\Redis::class,
    'Request' => Illuminate\Support\Facades\Request::class,
    'Response' => Illuminate\Support\Facades\Response::class,
    'Route' => Illuminate\Support\Facades\Route::class,
    'Schema' => Illuminate\Support\Facades\Schema::class,
    'Session' => Illuminate\Support\Facades\Session::class,
    'Storage' => Illuminate\Support\Facades\Storage::class,
    'Str' => Illuminate\Support\Str::class,
    'URL' => Illuminate\Support\Facades\URL::class,
    'Validator' => Illuminate\Support\Facades\Validator::class,
    'View' => Illuminate\Support\Facades\View::class,
    'Image' => Intervention\Image\Facades\Image::class
],

控制器

  <?php

   namespace App\Http\Controllers;

  namespace App\Http\Controllers;

  use Illuminate\Http\Request;
  use Illuminate\Validation\Rule;
  use DB;
  use App\User;
  use Auth;
  use Image;
  class ImageController extends Controller{
    //code
  }

答案 7 :(得分:-1)

Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    Illuminate\Cache\CacheServiceProvider::class,
    Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
    Illuminate\Cookie\CookieServiceProvider::class,
    Illuminate\Database\DatabaseServiceProvider::class,
    Illuminate\Encryption\EncryptionServiceProvider::class,
    Illuminate\Filesystem\FilesystemServiceProvider::class,
    Illuminate\Foundation\Providers\FoundationServiceProvider::class,
    Illuminate\Hashing\HashServiceProvider::class,
    Illuminate\Mail\MailServiceProvider::class,
    Illuminate\Notifications\NotificationServiceProvider::class,
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Pipeline\PipelineServiceProvider::class,
    Illuminate\Queue\QueueServiceProvider::class,
    Illuminate\Redis\RedisServiceProvider::class,
    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    Intervention\Image\ImageServiceProvider::class,

删除照明