Lumen class Artisan not found - php

I am working on an Lumen project.
I try to use
Artisan::call('my-command')
But PHP says me the class Artisan is not defined.
I have already enable Facade with the following command :
$app->withFacades();
So the Log class works after use Log; line.
I have already add the use Artisan line.
But it doesn't works.
The following command works in CLI:
php artisan my-command
Do you have any idea ?

This error occured because I use a wrong use sentence :
use Artisan; // Doesn't work
I must use this absolute use sentence :
use Illuminate\Support\Facades\Artisan;
I hope it will be helpful

Related

Laravel 5.4 - How to use EDI Vendor Library

I have installed EDI Library through composer command.
Library Link.
https://github.com/php-edifact/edifact
But in this, they did not give how to register your library in App file.
So can please help me how to register it. They are giving examples of how to use this.
I am just writing simple code.
$x = [1,5,8,9];
$c = new Parser($x);
But the above code is giving an error.
Class 'Parser' not found
Try using new EDI\Parser($x). You need to tell php in what namespace to find the class you are looking for.
Run this command in your command prompt
composer require sabas/edifact
Use in the top of the file like:
namespace EDITest;
use EDI\Parser;

'There are no commands defined in the "baum" namespace' error when using "baum" for implementing Nested Set

For implement of a Nested Set for my news category I want to use Baum package.
After installing this Package via Composer and add BaumServiceProvider to config/app.php providers, I try to install a new Model named Category via Below command:
php artisan baum:install MODEL
But I faced to the following error :
[InvalidArgumentException]
There are no commands defined in the "baum" namespace.
Of course I ran php artisan command and But there were no command named Baum on generated commands list.
What should I do?
First you have to add the code below in config/app.php:
Baum\Providers\BaumServiceProvider::class
If the problem still persists configuration files may be cached. Just call:
php artisan config:clear
Make sure that you added
Baum\Providers\BaumServiceProvider::class
To the providers array in the app.php file located in config/app.php
Whenever I know that I have added something into Laravel's core files, and it's not working from the command line, I typically just run
php artisan optimize
to regenerate all of the classes, and it will typically work. Running this command is something that I find myself doing fairly often.
In AppServiceProvider.php (app\Providers) you can modify register function: public function register()
{
$this->app->register(\Baum\Providers\BaumServiceProvider::class);
}
Not sure why 5.2 have error, just tweak a bit myself.
Try add this on APP/Console/kernel.php
protected $commands = [
//Commands\Inspire::class,
// Register Baum nestedset command
Commands\BaumCommand::class,
Commands\InstallCommand::class
];
and create two files and copy BaumCommand.php and InstallCommand in /vendor/baum/baum/src/Baum/console.
then change a namespace at the top.
namespace Baum\Commands;
to
namespace App\Console\Commands;

Laravel 5 error Class 'App' not found in

I am currently learning laravel 5 and wanted to implement the repository concept.
as I understand. I should put an ioc.php and the config folder and put my bindings their
Here is my config/ioc.php
<?php
App::bind('QuestionRepository', 'IQuestionRepository');
App::bind('AnswerRepository', 'IAnswerRepository');
I get an error Class 'App' not found in
try prefixing App with \ like \App
For my case in lumen 5.4, undefined 'App' class issue solved by facade definition:
use Illuminate\Support\Facades\App;
In my case, my .env file contained a value with spaces after checking out a new project.
Running php artisan optimize for the first time would throw this error because my Exception handler was trying to use the '\App' global alias for the App facade. Commenting that code showed the real error;
"Dotenv values containing spaces must be surrounded by quotes."

Laravel 5: "class App\Commands\Command not found"

In Laravel 5, I just ran php artisan make:command doMagicStuff to create a generic command with a die() statement in the handler. Whenever I try to `$this->dispatch(new DoMagicStuff()), however, I get:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'App\Commands\Command' not found
If I remove extends Command it works, though obviously not correctly.
Is there some reason it can't find App\Commands\Command ? (Note: In ./app/Commands, there is no Command.php, so that is a hint, though it might live under the vendor directory. I did a grep for "class Command", but no luck.
Did you clone the repo from github? The repository there has a Command.php with nothing in it, just empty abstract. My projects also have it, so... weird.
Here: https://github.com/laravel/laravel/tree/5.0/app/Commands
Whenever you create a command, it is namespaced as namespace App\Commands; and you extends Command, so it will look in the App\Commands dir for a Command class, since it exists in the repo, it should exist in your copy too.

Laravel Class Socialite not found

What I did:
Added "laravel/socialite": "~2.0" to composer.json
Run composer update
Added provider 'Laravel\Socialite\SocialiteServiceProvider' to app.php
Added alias 'Socialite' => 'Laravel\Socialite\Facades\Socialite' to app.php
After all this steps I created a new Controller Class which looks like that:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AuthController extends Controller {
public function login()
{
return \Socialite::with('facebook')->redirect();
}
}
But i still got this error: PHP Fatal error: Class '\Socialite'
Edit
composer dump-autoload fixed probably the error, but it's still not working correctly.
In your Controllers file add
use Laravel\Socialite\Facades\Socialite;
Just below use Illuminate\Http\Request; in your controller add use Socialize;
Check if you have set your alias as "Socialize" as in the Socialite docs says to do this way:
'Socialize' => 'Laravel\Socialite\Facades\Socialite',
It as very confusing to me as well
I had the same issue. Clearing the config cache helped me in this situation:
php artisan config:clear
First of all use ::class, on your config/app.php
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
Second, call the class in your controller
use Socialite;
Third, try clear the config
php artisan config:clear
And lastly check the redirect URL if its working
http://yoursite.com/your_redirect
If anyone still encounters this problem even after trying above solutions, please clear the cache. Most of the time classes and all are cached because of which this error occurs.
php artisan config:clear
'Socialite' => 'Laravel\Socialite\Facades\Socialite' is a mistake that I did too.
It must be declared as 'Socialite' => Laravel\Socialite\Facades\Socialite::class
I had the exact same problem and after the usual half hour of raging I realised that there was a trailing space at the end of my registration line i.e.
'Laravel\Socialite\SocialiteServiceProvider ',
Once I'd removed the space funnily enough it worked!
'Laravel\Socialite\SocialiteServiceProvider',
Once again the woes of copy and paste raise their ugly heads!
in laravel 6 or above, try running this command
composer require laravel/socialite

Categories