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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27374613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:19:45  来源:igfitidea点击:

Laravel / Intervention Image Class - class not found

phpclasslaravelimage-resizing

提问by Tomas Turan

I just installed Intervention Image Class following instructions from here: http://image.intervention.io/getting_started/installation

我刚刚按照这里的说明安装了干预图像类:http: //image.intervention.io/getting_started/installation

I also added these 2 lines into config/app.php file:

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

'Intervention\Image\ImageServiceProvider'

'Image' => 'Intervention\Image\Facades\Image'

'干预\图像\图像服务提供者'

'图像' => '干预\图像\立面\图像'

When I open my website, i get this error:

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

Class 'Intervention\Image\ImageServiceProvider' not found

Why is that and what should I do now?

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

回答by Qamar Uzman

Step 1:

第1步:

Add "intervention/image": "dev-master"to the “require” section of your composer.jsonfile.

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

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

Step 2:

第2步:

Run CMD;
$ composer install

If you've got this warning:

如果您收到此警告:

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

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

do $ composer updateand then $ composer install

$ composer update然后$ composer install

Step 3:

第 3 步:

open the config/app.phpfile. Add this to the $providersarray.

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

Intervention\Image\ImageServiceProvider::class

Step 4:

第四步:

Next add this to the $aliasesarray.

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

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

Step 5:

第 5 步:

If there is an error;

如果有错误;

Class 'Intervention\Image\ImageServiceProvider' not found

未找到“干预\图像\图像服务提供者”类

try

尝试

$ composer update

回答by Morteza Rajabi

Try this, It works for me.

试试这个,它对我有用。

use Intervention\Image\Facades\Image as Image;

回答by Polarix

composer require intervention/image

solves definitively the problem.

彻底解决问题。

回答by Gediminas

Try add \symbol before Image:

尝试在\之前添加符号Image

\Image::make();

It helped for me on Laravel 5.3 and Intervention 2.3

它在 Laravel 5.3 和 Intervention 2.3 上对我有帮助

回答by Syahrul Ostid

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

add new code "intervention/image": "dev-master"in composer.json, and cmd

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

$ composer update

回答by Turan Zamanl?

just write that on the controller

把它写在控制器上

use Image;

使用图像;

config/app.php providers

config/app.php 提供者

Intervention\Image\ImageServiceProvider::class,

Intervention\Image\ImageServiceProvider::class,

Alias

别名

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

'图像' => Intervention\Image\Facades\Image::class,

回答by Udara Gunawardhana

In laravel 5.8 you can easily fix that error.

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

first open config folder app.php file add providers

首先打开config文件夹app.php文件添加提供者

   Intervention\Image\ImageServiceProvider::class,

then goto aliases and add the

然后转到别名并添加

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

open the the if you want to image upload controller add the

打开如果你想图片上传控制器添加

  use Image;

providers

提供者

           '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

别名

      '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
],

Controller

控制器

  <?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
  }