"How to fix 'class not found' error in Laravel" - laravel

I need to create a form in Laravel. When I open the localhost it shows this error
"Class 'Collective\Html\FormFacade' not found (View: C:\xampp\htdocs\softwareProject\test\resources\views\studentForm.blade.php)"
How to fix this?

You need to edit composer.json file to require laravelcollective/html
By using composer in your terminal or command prompt type the following:
composer require "laravelcollective/html":"^5.4.0"
Second, add this provider to the providers array of config/app.php as below:
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
And finally add two class aliases to the aliases array of config/app.php:
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
For more details check docs
UPDATE:
If you're getting [UnexpectedValueException] Could not parse version constraint :5.4.0: Invalid version string ":5.4.0" error then you can insert this entry manually in composer.json. And after that then use composer update.
What you need now is just add "laravelcollective/html": "5.4.*", below the row with "laravel/framework":"5.4.*" as below:
"require": {
"php": ">=7.0.0",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.4.*",
"laravelcollective/html": "5.4.*", // Add this entry and then run composer update
"laravel/tinker": "~1.0"
},

Related

Class 'Artisaninweb\SoapWrapper\ServiceProvider' not found in vendor\laravel\framework\src\Illuminate\Foundation\Application.php

I want to add soap service to my laravel 5.3 project.I have added service provider
in config/app.php
'aliases' => [
'SoapWrapper' => Artisaninweb\SoapWrapper\ServiceProvider::class,
'SoapClient' => SoapClient::class,
],
In bootstrap/app,php I have added
$app->register(Artisaninweb\SoapWrapper\ServiceProvider::class);
my composer.json is like
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"laravelcollective/html": "^5.3.0",
"artisaninweb/laravel-soap": "0.2.5.10",
"hashids/hashids": "^1.0",
"maatwebsite/excel": "~2.1.0"
},
In my controller
use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
use SoapClient;
and cleared cache as and composer
composer dumpautoload -o
composer clearcache
Still I'm getting a fatal error
Fatal error: Class 'Artisaninweb\SoapWrapper\ServiceProvider' not
found in
C:\wamp64\www\pjct_name\vendor\laravel\framework\src\Illuminate\Foundation\Application.php
on line 610
What I have missed

class html not found laravel 5.0

i have included the following
i have Add to composer.json:
"illuminate/html": "5.0.*"
i have Add to the app.php providers array:
'Illuminate\Html\HtmlServiceProvider',
i have Add to the app.php aliases array:
a) 'Html' => 'Illuminate\Html\HtmlFacade',
b) 'Form' => 'Illuminate\Html\FormFacade',
when i try to update my composer in cmd i get the following error what can be the problem
C:\xampp>cd\xampp\htdocs\sites\project\laravel\mysitegud
C:\xampp\htdocs\sites\project\laravel\mysitegud>composer update
[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 8:
...amework": "5.0.*" "illuminate/html", "
---------------------^
Expected one of: 'EOF', '}', ':', ',', ']'
the following code below is for composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*"
"illuminate/html", "5.0.*" <!--this code is for illuminate-->
}, //is there any problem in the following code.i have noticed that laravel is key sensitive .may be i went wrong some where but i dont know where.
The second entry of your require array is formatted wrong. The delimiter/separator between key and value is a : when using JSON, not a simple ,
Current line
"illuminate/html", "5.0.*"
Correct line
"illuminate/html": "5.0.*"
Now run composer update or composer install depending on your projects status. It should install the HTML and Form addon correctly now.
Also don't forget to add the new Form and Html facade to your aliases
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
and the ServiceProvider
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
In case you are upgrading to L5, you should remove the old declarations.
Now run composer dumpauto followed by artisan optimize.

Class dompdf.wrapper does not exist laravel 4.2.0

I am trying to use the dompdf package with Lavarel 4.2.0 in my project authored by barryvdh, I tried installing three different versions of this package (0.6*, 0.6.1,0.5.2)
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "^1.6",
"barryvdh/laravel-dompdf": "0.5.2"
How ever each time I try to create a PDF file using
Route::get('/invoice', function()
{
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();
});
I get this error
Class dompdf.wrapper does not exist (vendor\laravel\framework\src\Illuminate\Container\Container.php)
/ hand back the results of the functions, which allows functions to be
// used as resolvers for more fine-tuned resolution of these objects.
if ($concrete instanceof Closure)
{
return $concrete($this, $parameters);
}
$reflector = new ReflectionClass($concrete);
// If the type is not instantiable, the developer is attempting to resolve
According to the docs, we need to install the 0.4.x versions for Laravel 4. Your project is using versions for Laravel 5.
composer.json:
"require": {
...
"barryvdh/laravel-dompdf": "0.4.*"
}
To resolve the dompdf service from the container, use 'dompdf', not 'dompdf.wrapper':
$pdf = App::make('dompdf');
Or, use the PDF facade:
use PDF;
...
$pdf = PDF::loadHTML('<h1>Test</h1>');
Be sure to register the service provider and facade in config/app.php.
I put in file config/app.php into providers section:
Barryvdh\DomPDF\ServiceProvider::class,
And into aliases section:
'PDF' => Barryvdh\DomPDF\Facade::class,
And I use this in my controller:
use PDF;
...
$pdf = PDF::loadView('panel.cooperation-offers.pdf', $showData);
Here is my composer.json:
...
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"barryvdh/laravel-dompdf": "0.6.*"
}, ...

Laravel 5 and Socialite

I have installed laravel/socialite in my project but I can't understand how to make it work...
I have this in my composer.json:
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0",
"laravel/socialite": "~2.0"
},
I have added in my config/app.php:
'Socialize' => 'Laravel\Socialite\SocialiteServiceProvider'
and:
'Laravel\Socialite\SocialiteServiceProvider',
Then:
composer dump-autoload
Added a new route:
Route::get('auth/facebook', 'Auth\AuthController#getFacebookLogin');
Add the new method:
/**
* #return mixed
*/
public function getFacebookLogin()
{
return \Socialize::with('facebook')->redirect();
}
But all I get is:
FatalErrorException in AuthController.php line 43: Call to undefined method Laravel\Socialite\SocialiteServiceProvider::with()
Where is the error?
You should add
'Socialize' => 'Laravel\Socialite\Facades\Socialite'
as an alias in your app.php.
It seems the Facade alias doesn't really work anymore for Socialite. I think the docs could use some love, in general, too (especially since I don't think it's supposed to be aliased as "socialize").
What I found to work was to alter your use statement to
use Laravel\Socialite\Contracts\Factory as Socialite;
and drop the alias entry altogether.

Cannot update yii2 via composer bower-asset/jquery could not be found

I was updating my yii2 via composer then reverted back to the old beta version.
Here is the error on my composer:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package bower-asset/jquery could not be found in any version, there may be a typ
o in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setti
ng
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Tried searching for bower-asset/jquery at packagist but it is not found.
Thanks for the help :)
Finally fixed it, just followed the steps on the UPGRADE.md doc
If you are using Composer to upgrade Yii, you should run the following command first (once for all) to install the composer-asset-plugin:
composer global require "fxp/composer-asset-plugin:^1.2.0"
(See http://www.yiiframework.com/doc-2.0/guide-start-installation.html#installing-from-composer for latest version.)
You may also need to add the following code to your project's composer.json file :
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
Hopes this helps :)
For me helps to remove folder ~/.composer and execute command:
php composer.phar global require "fxp/composer-asset-plugin:1.*"
Then just run again
php composer.phar update
Found a cleaner solution. Just add following repository in your composer.json file
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
and watch the magic
If you don't want to use fxp/composer-asset-plugin then all you have to do is to follow these simple instructions from Yii2 documentation.
Using asset-packagist repository
This way will satisfy requirements of the majority of projects, that need NPM or Bower packages.
Note: Since 2.0.13 both Basic and Advanced application templates are
pre-configured to use asset-packagist by default, so you can skip this
section.
In the composer.json of your project, add the following lines:
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
Adjust #npm and #bower aliases in you application configuration:
$config = [
...
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
...
];
Visit asset-packagist.org to know, how it works.
If you don't need the update for bower-asset, you can require yidas/yii2-composer-bower-skip before yiisoft/yii2. in composer.json file:
"require": {
"php": ">=5.4.0",
"yidas/yii2-composer-bower-skip": "~2.0.0",
"yiisoft/yii2": "~2.0.5",
"yiisoft/yii2-bootstrap": "~2.0.0"
}
After that, you can update Composer smoothly without bower-asset.
See https://github.com/yidas/yii2-composer-bower-skip
Just in case for anyone upgrading Yii 2.0.41 - 2.0.43,
should be noted that you need to install the "external" bower-asset.
Run the following
composer require yidas/yii2-bower-asset
Then, need to update the aliases inside config (depends on your structure) for the Yii to handle the new bower-asset folder.
// here is important part
'aliases' => [
'#bower' => '#vendor/yidas/yii2-bower-asset/bower',
],
//below is just another config just ignore. example purpose don't copy
'components' => [
'db' => [
Then, reload your Yii app. Should be fine.
-Extra-
Here is the example of the composer.json for anyone who need the updates to 2.0.43
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Application Template",
"keywords": ["yii2", "framework", "advanced", "application template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "2.0.43",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "~2.0#dev",
"yiisoft/yii2-redis": "~2.0.0",
"yiisoft/yii2-elasticsearch": "~2.0.0",
"bryglen/yii2-apns-gcm": "1.0.5",
"snhccm/baidu-push": "dev-master",
"google/cloud": "dev-master",
"minishlink/web-push": "6.0.7",
"understeam/yii2-fcm": "~0.1",
"yidas/yii2-bower-asset": "2.0.13"
},
"require-dev": {
"codeception/codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*"
},
"config": {
"process-timeout": 1800
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
As described in YII2 repository documentation: https://asset-packagist.org/site/about
We can solve this problem by adding aliases on those folders in our config.
It will looks like that:
$config = [
...
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
...
];
It works perfectly!
Simple and clean solution:
In composer.json just replace the bower-asset/jquery line with:
"yidas/yii2-bower-asset":"*"
I propose we add also bower-asset/datatables to the yidas/yii2-bower-asset
My Problems with accepted solution of adding fxp/composer-asset-plugin are that the plugin is significantly slowing down the composer system, impacts everywhere, isn't always portable across operating systems and environments, has errors with PHP7.2 relating to inconsistent method names. So, I prefer my quicker to develop, faster at runtime, more local, and more compatible solution.
I tried all the mentioned steps like adding following in main.php
$config = [
...
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
...
];
composer.json
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
Doing "composer install/update" was still not installing bower packages given by yii2-bootstrap.
I found, I was using composer.phar 2x to set this up. I downgraded composer.phar to 1x and all works well without having the need of fxp/composer-asset-plugin plugin.

Resources