0

I'm learning Laravel PHP and I was trying to display some contents like images and audio in a PHP webpage. However, it didn't display any images but only plain texts. So I tried to install some HTML packages by pasting some lines of codes to composer.json file and app.php file like what they said in Undefined namespace html (adding a css file to blade) laravel. After running XAMPP, I obtained an error:

Class "Illuminate\Html\HtmlServiceProvider" not found

My PHP version is 8.0.8 (latest) and my Laravel version is 8.52.0 Here is my require in composer.json:

"require": {
        "php": "^7.3|^8.0",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.40",
        "laravel/tinker": "^2.5",
        "illuminate/html": "~5.0"
    },

And here is the app.php one:

'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,
        //Collective\Html\HtmlServiceProvider::class,
        //Illuminate\Html\HtmlServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notificadtions\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,

        /*
'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,
        'Date' => Illuminate\Support\Facades\Date::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,
        'Form'=> Illuminate\Html\FormFacade::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Html'=> Illuminate\Html\HtmlFacade::class,
        'Http' => Illuminate\Support\Facades\Http::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,
        'RateLimiter' => Illuminate\Support\Facades\RateLimiter::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,

    ],

Please help!

  • Check here for your problem https://stackoverflow.com/questions/28541051/class-illuminate-html-htmlserviceprovider-not-found-laravel-5 – Abed Putra Jul 30 '21 at 03:53
  • It seems like my Laravel version isn't compatible with the HTML class. There are some pages saying that HTML is deprecated from Laravel after a specific version of it. Is there any other way to fully display HTML codes in PHP pages? – Hacker Rhino Jul 30 '21 at 04:03
  • 1
    It's odd that composer allowed you to install it to begin with. Normally you'd get version conflict errors to indicate the set of packages can't all be fulfilled – apokryfos Jul 30 '21 at 04:20

2 Answers2

2

Do not take this as an attack to you, but I get really frustrated seeing this questions over and over again...

If you have any problems with a package, ALWAYS go to the source of truth... In this case it would be Packagist (it is the official "source" for composer packages) and it will tell you where it comes from and more...

So, if you do that, it will get you here and you will see a beautiful red legend saying:

This package is abandoned and no longer maintained. The author suggests using the laravelcollective/html package instead.

So, you click that recommended package and you got to a new Packagist page, showing the main repo on the right side (github). When you go to that page, you can see a main page in the readme, so you go there.

In that page, the first thing you will see is the documentation related to it, and the first "element" it shows is HTML, the one you want to use (showing you the available doc's versions for laravelcollective/html)...

So you click on that one and see how it is to just use that class/helper/service...


One more thing, as the repo or the main page does not say the Laravel versions it support, always check the source code's composer file. You will see it requires some illuminate/xxxx: ^6.0|^7.0|^8.0, that means that the current Laravel supported version is >= 6.x but not <= 5.8. So Laravel 8 is supported.

That check works for any package that has a constraint with a Laravel version. If you don't see any of that, then it should be usable by any Laravel version...

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
0

For .css and .js files, you may want to just put them into public/css and public/js folder and then include them in Bladeview templates in your resources/views folder. Them you return this Blade view via the help of controller and view() helper. For more information please consult Laravel document

Huy Phạm
  • 888
  • 9
  • 24
  • Hello. I also tried this command: composer require laravelcollective/html And it has errors: - illuminate/html[dev-master, v5.0.0] require illuminate/http ~5.0 -> found illuminate/http[v5.0.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require. Do you have any solution for it? – Hacker Rhino Jul 30 '21 at 04:06
  • You have to delete that `illuminate/http` and require `laravelcollective/html`... – matiaslauriti Jul 30 '21 at 04:24
  • @matiaslauriti I successfully installed laravelcollective/html and it still prompts out an error: Class HTML not found at the line which is "{{ HTML::image('resources/views/Assets/kifflom.jpg', 'alt text', array('class' => 'css-class')) }}" – Hacker Rhino Jul 30 '21 at 05:05
  • @HackerRhino that is because, if you **see my answer** and go to the [documentation](https://laravelcollective.com/docs/6.x/html), you will see that `HTML::image` (the new way of writing it is `Form::xxxxxx`) does not exist... You will have to manually create the image as an HTML ``. **Read my answer and the documentation please**. This is the old [`HTML::image` source code](https://github.com/illuminate/html/blob/3d1009bb8e0f25720c914af5c1f4015dd373c9ef/HtmlBuilder.php#L84-L98)... – matiaslauriti Jul 30 '21 at 05:09
  • @matiaslauriti I did what you said, just create a normal HTML tag image and it worked. But it didn't really show the image. Here is the result. https://drive.google.com/file/d/1ddXfB8F9XkUhc2pJ9dENiwVJCiN0rlKx/view?usp=sharing – Hacker Rhino Jul 30 '21 at 05:20
  • @HackerRhino Mark my answer as correct and create a new question about this, as it could be a simple mistake related to the Image URL, but it is not related to this question and can get out of topic. – matiaslauriti Jul 30 '21 at 05:28
  • @matiaslauriti Even I use "{{ Html::image('resources/views/Assets/kifflom.jpg', 'alt text', array('class' => 'css-class')) }}", it also works but still results the same as the tag. But PHPStorm even says "undefined class Html" when dragging the mouse into it. – Hacker Rhino Jul 30 '21 at 05:29