Undefined class Route (Laravel in PhpStorm) - laravel

How can I fix this alert in PhpStorm?
And also how to get autocompletion for Route and other Facades?

Check the Laracasts walkthrough
1) Go to: https://github.com/barryvdh/laravel-ide-helper
2) Click on the gist
Generated version for L5: https://gist.github.com/barryvdh/5227822
3) Click on "Raw" to get the current version (as of June 22, 2016 it is):
https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php
4) Make sure you're in your root directory (this is mine)
cd /var/www/html/project
5) Download the gist:
wget https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php
6) Add "_ide_helper.php" to the .gitignore file
sudo nano .gitignore
Add "_ide_helper.php" on a new line at the bottom
7) Download the .gitignore and _ide_helper.php files into PhpStorm
This is what my PhpStorm project directory looks like afterwards:
8) After the files are downloaded into PhpStorm, the "Undefined class" error will disappear and autocompletion will now work. Might need to restart it.

There is greate IDE support for Laravel shipped from Baryvdh:
https://github.com/barryvdh/laravel-ide-helper
after you install it you just call in the console:
php artisan ide-helper:generate
which generate alll facede shortcuts in _ide_helper.php file (which you have to exclude from git)
There is also something special for PhpStorm:
php artisan ide-helper:meta
which will give Laravel container context for example:
$foo = app(Foo::class);
PhpStorm will know that the $foo variable is type of Foo class.

I know this is an old thread, but it is still relevant. For me, I decided to add the following to my routes/web.php since I don't want to have to worry about regenerating meta data for the app.
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
Edit: The above does not add any overhead to PHP as the use simply acts as a reference for PHP.

I solved this problem simply by installing the Laravel idea plugin.
Use the following link:
https://laravel-idea.com/
You can install it on your phpstorm.
Its good feature is that you can use it for 30 days for free and pay the amount after satisfaction.

Related

after Update laravel 6.2 [App\Http\Controllers\Auth\ConfirmPasswordController] does not exist

I update laravel from v 6.0 to v6.2 and after the finish, I try php artisan route:list
This error
I had the same issue, i fixed it with the following solution:
Create a empty file named "ConfirmPasswordController.php" in the folder App/Http/Controllers/Auth
Go to https://github.com/laravel/laravel/tree/master/app/Http/Controllers/Auth en open the file named "ConfirmPasswordController.php"
Copy all the file contents to your newly created file and save it.
This should fix the error.
Edit
The problem is, were updating the composer dependencies, but not the core application. But de composer dependencies expect you to update the core. They refer to files on the core application that not exists (because the application is not up-to-date).
See: How to update Laravel Application (not the composer dependencies)
This has been fixed. Just update to Laravel 6.4
Step1. Create ConfirmPasswordController.php file in app/Http/Controllers/Auth/ path.
Step2. ConfirmPasswordController.php paste this content to ConfirmPasswordController.php file.
From v6.0.0 to v6.2.0 the following addition and modifications were made.
Added app/Http/Controllers/Auth/ConfirmPasswordController.php
Modified app/Http/Controllers/Auth/ForgotPasswordController.php
Modified app/Http/Controllers/Auth/ResetPasswordController.php
Modified app/Http/Kernel.php
Modified config/auth.php
Modified resources/lang/en/validation.php
You can see the diff of v6.0.0 to v6.2.0 here.
Create ConfirmPasswordController.php manually and It's may be duplicate of - duplicate
1 ) Open file vender/laravel/framework/src/Illuminate/Routing/Router.php".
2 ) and comment these
// $this->get('password/confirm', 'Auth\ConfirmPasswordController#showConfirmForm')->name('password.confirm');
// $this->post('password/confirm', 'Auth\ConfirmPasswordController#confirm');

Laravel pdf issue: failed to open stream: No such file or directory by using barryvdh/laravel-dompdf package

I am update composer and use barryvdh/laravel-dompdf package.
the problem is when i click the button it show me error like image below:-
Is that anyway to change the folder path? or am I missing code to modify path to download the pdf file?
You need to run this command:
php artisan vendor:publish
Then, try to create a fonts directory in the storage directory.
i.e. storage/app/fonts. Also, remember to make it writable.
For maximum execution time of 30 seconds exceeded, this is not laravel related issue but it's about php configuration issue. Please see this and fix it: http://php.net/manual/en/info.configuration.php#ini.max-execution-time
You can also see this answer: https://stackoverflow.com/a/30290770/6000629
Hope this will helps you!
Try this:
$pdf = PDF::loadView('pdf/personalpdf', compact('user','result'))->setOptions(['defaultFont' => 'sans-serif']);
It worked for me, I didn't make any file/folder
Just remove the reference to css external file in your cart.placeOrder.blade
Note: This directory must exist and be writable by the webserver process.
under the config file thats what it say: therefore you should create the fonts directory inside the storage.
"font_cache" => storage_path('fonts/'),

Is NetBeans not accepting _ide_helper from Laravel?

Using NetBeans 8.2 with Laravel, I'm setting the _ide_helper.php to my project as described in his link https://github.com/barryvdh/laravel-ide-helper,
it was set on terminal the command
composer require barryvdh/laravel-ide-helper
then after, it was added into config/app.php the line
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
and for last, the command on the project folder
php artisan ide-helper:generate
but nothing has changed apparently. No auto complete, no references. Here are some images comparing what is expected and what is happening.
Expected
Happening
Plus, NetBeans is marking an error inside the ide_helper file which confuses the syntax by the name of the function ('if'). I'll put an image of the part showing the error
Error_NetBeans_ide_helper
I've rebooted NetBeans, tried downloading and setting directly the file, but no lucky. Is the function 'if' causing the problem? Or is NetBeans not accepting the _ide_helper?

Laravel 5.1 remove controller

I have simple question on Laravel 5.1. I have created a controller using php artisan command:
php artisan make:controller PageSettings
However it was mistake, because I really wanted to create this controller in Admin folder like this:
php artisan make:controller Admin/PageSettings
Now I want to get rid of my old PageSettings controller. Is it ok just to delete my old PageSettings.php manualy? Or there is something more what needs to be done?
If you only created it and found that you did it wrong, you can manually remove the file and that's it. However when you already added routes to this controller in routes.php you should remove them from routes.php file or alter the file to reflect your new controller.
It is OK to manually delete controller. Just check routes.php if you have some route to that controller and delete it also.
I had an issue with just deleting the file. I tried running my PHPUnit test suite and got an error that looked like this:
Warning: include(): Failed opening '/user/home/me/some/file.php' for inclusion (include_path='.:') in /usr/home/me/some/vendor/composer/ClassLoader.php on line 444
I had to run composer update then composer dump-autoload. After that, everything worked just fine.
Yeah, you can delete manually without tension.
I will suggest you for avoiding more mistakes, you "phpStrom" software, from using this, if you delete manually any file from by click right of mouse->Refactor->safe delete then before deleting they will give all places which were using your file. by clicking "do refactor" you can delete it.

Artisan packages error

I'm having some trouble with artisan/packages.. I've added a package to my composer file and ran composer update and an error was returned:
PHP Warning: require(/home/xxx/public_html/bootstrap/autoload.php): failed to open stream: No such file or directory in /home/xxx/public_html/artisan on line 16
I can see that require path is incorrect, my structure is like so:
/home/xxx/bootstrap
/home/xxx/app
/home/xxx/vendor
/home/xxx/public_html
I hadn't changed any of the paths and everything seemed to work out of the box with this structure, basically removing the public folder and pushing everything up a directory.
I've opened up Artisan tried a couple of paths that kept failing so i've changed them to absolute:
require '/home/xxx/bootstrap/autoload.php';
It seemed to work from here on, but at the end of the process got another error:
Writing lock file
Generating autoload files
[RuntimeException]
Could not scan for classes inside "app/commands" which does not appear to be a file n or a folder
Rather than continue to mess it up i thought now would be a good time to clear it up, any ideas how to fix this?
Make sure you are using php 5.3 or higher.
Run php -v
Try creating an empty "app/commands" folder, fixed the issue for me!

Resources