PhpStorm and Laravel autocompletion - laravel

I decided to use PhpStorm for my new Laravel project, so I thought I wanted some autocompletion. I did read the guide from https://blog.jetbrains.com/phpstorm/2015/01/laravel-development-using-phpstorm/ and some of it works fine, but I got a problem.
I wanted to test my DB connection, so I just made a simple index() function like this
if(DB::connection()->getDatabaseName()) {
echo 'Connected to ' . DB::connection()->getDatabaseName();
}
Which works fine, but when I write DB and press Tab I write \DB:: instead of DB::. Then I include use Illuminate\Support\Facades\DB; and DB:: works. But when I added the facade, the autocompletion isn't the same at all and it cant find the methods but they works. It's really annoying.
Someone else had this problem and is there a solution for it?

In PhpStorm,
Settings => plugins
Search repository for laravel and install.
Then after add this package:
composer require barryvdh/laravel-ide-helper
You can find more help on github for this package:https://github.com/barryvdh/laravel-ide-helper

First, install the Laravel plugin for PhpStorm, then install laravel-ide-helper.
After that, generate ide-helper for your project)
php artisan ide-helper:generate
php artisan ide-helper:meta
For correct autocomplete model you must identify this model
use (model namespace)

You have to install the helpers - https://github.com/barryvdh/laravel-ide-helper

Figured it out :) Just att DB to your class and the problem is solved.
use DB;

Related

cannot access Component controller variables inside the component view

I have been running into this very weird issue with Laravel.
I had a problem where one of my component views was not able to read the variables defined in its class. It was kind of strange because I have several components running in my project and they all worked fine, except for this one.
So I created a fresh Laravel project to test some things out (Wanted to check if the problem was on my end, maybe I somehow messed up the project files).
I created a new component on a blank project using php artisan make:component top_nav
pre function basically is used as print_r which is in helper.php
Then I simply added a sql_data variable to the class component like so:
i tried many thing as much as i can do but still i can't access that variable
also clear cache of view
of laravel
change name of components but still can't work
kindly help me..........
you should
return view('components.top_nav', ['sql_data' => $sql_data]);
you are not passing the variable to the view
composer install
npm install && npm run dev
php artisan optimize
I just copied your screenshots into a new laravel installation and ran it with no problems.
Try setting the public property with a default value:
public $sql_data = 'testing'
If you try the above and still have issues, I'd like to confirm the output of AdminLogin::all().
PS:
TopNav instead of top_nav Class name please.

Class 'ConsoleTVs\Charts\ChartsServiceProvider' not found

I want to put a pie chart on my laravel project and install a library consoleTvs. But I decided to remove it from composer since I use a jquery instead.
When i try to run my project I use to have a error message
Class 'ConsoleTVs\Charts\ChartsServiceProvider' not found.
Without seeing ANY code it's very hard to help you.
I try to guess: you are not importing ChartsServiceProvider class so, still guessing, you can put at the start of your file
use App\Providers\ChartsServiceProvider;
So now you want to remove a library from composer.
i hope you remove it correctly. still you can follow below how to remove.
so remove that library code into your composer.json. and hit composer update.
so Hope you remove it correctly, so after removal you facing error of provider.
I guess on the time of installing you manually add a provider into your app.php file inside config folder.
So if, Am right, just go to your app.php file inside config folder and remove that provider as well as its alias too if you give it before.

Composer update not working because of a missing class in config/app.php?

Something strange happened to me today : a collegue changed something in config/app.php , so that a different class is used as a service provider instead of the original one.
The code for this new class is in a package that was added to composer.json.
I updated from SVN and got both new files, but then composer update didn't work, because this somehow uses the config/app.php , which was broken, because it didn't know the class, which of course would only be in vendor AFTER composer update !
So my question is : why would composer update need anything that is in config/app.php ? And how to prevent something like this in the future?
Go to your config/app.php file and comment out the provider which was added by your colleague. Run composer update and then uncomment it, maybe php artisan optimize too and then you should be good to go.
EDIT: When a new package has been added by someone else, you need to install it. You only need to run composer update when you want to update all of your packages to their latest versions, or the framework.

Namespacing in Laravel Spark install

I am trying to install Laravel Spark into an existing app. I have not changed the default namespace of "App".
I get the following error on install:
Class 'Laravel\Spark\Providers\SparkServiceProvider' not found
How can get around this error?
It means you didnt attach a class for laravel to detect it ..
Go to App/Config..open app.php..
scroll down.. youll see a providers list.. add a new line to it like
Laravel\Spark\Providers\SparkServiceProvider::class,
Save and Try again :)

Composer failing when I use Route::controller() in my routes.php

I'm working on migrating an existing Laravel 3 application over to Laravel 4.1, and routes are kicking my butt right now. Here is the problem I'm having- in the old application we made frequent use of Route::controller() in the routes file. When I bring those entries over to the new application they seem to work, but they cause composer to get nasty.
For example I have this route:
Route::controller('templates', 'AdminTemplatesController');
Which is working as a route. But when I run composer update I get this error:
{"error":{"type":"ReflectionException","message":"Class AdminTemplatesController does not exist","file":"\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/ControllerInspector.php","line":28}}
I've tried stripping down and using Artisan to create an entirely new controller- same test, same fail.
Any ideas what I'm doing wrong?
Looks like you have to do it in steps:
1) Disable all of your routes
2) Execute composer update and make the process pass, you don't need your routes to do that
3) Reenable the controller route and fix the issue Laravel is having by not finding it, which could be:
Controllers folder not being loaded in composer.json
Namespace not being loaded in composer.json
In all of those cases, you have to be sure that you have your controllers in any of the files of the folder:
vendor/composer
For example, if you have the controllers folder in the autoload->classmap of composer.json, the file will be:
vendor/composer/autoload_classmap.php
Remember that every time you change composer.json, you have to
composer dumpautoload
So it recreates those files.
EDIT:
About your comment, I had similar problem once when my file was printed in command line, was happening because I had:
<?
instead of
<?php
This makes difference for Laravel.
In Laravel 4 you use "Route::resource()". So your example would be Route::resource('templates', 'AdminTemplatesController');
http://laravel.com/docs/controllers#resource-controllers

Resources