There are no commands defined in the "backup" namespace - laravel

I have tried installing Laravel Backup for Database paulvl/backup
I have followed the instructions on how to install and configure it to my Laravel application. I am however stuck at the point where you actually run the backup command. I get this error:
$ php artisan backup:mysql-dump
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "backup" namespace.
Any help would highly be appreciated
Here is the provider array in config/app.php

From the package docs:
Once the package's installation completes, the final step is to add the service provider. Open config/app.php, and add a new item to the providers array:
Backup\BackupServiceProvider::class,
These commands will be automatically registered since the BackupServiceProvider does that:
public function register()
{
$this->registerMysqlDumpCommand();
$this->registerMysqlRestoreCommand();
}

Related

Cannot locate class of installed package

I'm writing a laravel package which contains spatie/laravel-sitemap.
I already included several external packages and I didn't encountered any issues, but for some reason I'm not able to integrate this one.
What I did is the usual:
composer require spatie/laravel-sitemap
Then I have created a Console command that have as handle method the following content:
public function handle()
{
SitemapGenerator::create(config('app.url'))
->configureCrawler(function (Crawler $crawler) {
$crawler->ignoreRobots();
})
->writeToFile(public_path('sitemap.xml'));
$this->line('<info>Sitemap generated');
}
when I execute the command registered as:
php artisan myapp:sitemap
I get:
Class "Spatie\Sitemap\SitemapGenerator" not found
The reference imported are:
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;
I also tried composer update and composer dump-autoload, same problem.
Any help?
register package class in providers array in config/app.php
Spatie\Sitemap\SitemapServiceProvider;
in the bottom of app.php file
i hope it was useful.
you can publish package using this.
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=sitemap-config
then
composer dump-autoload
for more details please check the document https://github.com/spatie/laravel-sitemap under Configuration

Service Provider not booting in Laravel 5.8

I've created a new service provider to observe a model (App\Providers\EloquentEventServiceProvider.php), like so:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Staff;
use App\Oberservers\StaffObserver;
class EloquentEventServiceProvider extends ServiceProvider
{
public function boot()
{
Staff::observe(StaffObserver::class);
}
}
I've also added it to the config file (config\app.php):
return [
...
'providers' => [
...
App\Providers\EloquentEventServiceProvider::class,
...
]
...
]
The observer methods aren't working though. If I move Staff::observe(StaffObserver::class); to the AppServiceProvider class, it works just fine. So clearly this is an issue with getting my service provider to boot. I've tried php artisan config:clear, php artisan clear-compiled, composer update and composer dump but none have work. Any help is greatly aprpeciated.
your Oberservers name is wrong, as mentioned in the laravel doc observers laravel doc it should be Observers which means all of your observers should be within App\Observers instead of App\Oberservers.
so here we have 2 solutions :
1- if you want to keep the namespace App\Oberservers, you should run these 2 commands below because autoloading of the files may not work properly because we created a new folder Oberservers:
# Autoloading of files
composer dump
# Configure the cache
php artisan config:cache
2- the second solution is to just rename your actual Oberservers folder to Observers, in that way the autoloading of files will work well.

Calling passport:client from route, "there are no commands defined in the "passport" namespace"

I have an issue where the passport namespace is not available when I call passport:client. I set up a brand new Laravel project with version 5.6.34 where I installed Laravel passport according to the documentation. I also checked a similar question and followed all steps there with no sucess.
Calling php artisan passport:client --password --name="Test" from the command line works without any issues and I can see the client in the database.
However if I create a route in routes/web.php like so:
<?php
use Illuminate\Support\Facades\Route;
use \Illuminate\Support\Facades\Artisan;
Route::get('/', function () {
Artisan::call('passport:client', [
'--password' => true,
'--name' => "Test client",
'--quiet' => true,
]);
});
and use the Artisan facade to call the command I get the error below when I navigate to http://homestead.test/.
Symfony \ Component \ Console \ Exception \ CommandNotFoundException
The command "passport:client" does not exist.
I have added Laravel\Passport\PassportServiceProvider::class in the providers array in config/app.php.
How can I call the passport:client command from a web route?
We have a Laravel application that has several hundred database connections which are handled dynamically. In the admin interface you can create a new project and thus a new database where we need to generate a client.
My other option is the instantiate a ClientRepository and call the createPasswordGrantClient() method but I would like to avoid this if possible. I am curious to know why the namespace is available when called on the CLI but not via a request. I can call other commands such as migrate:fresh via a request but passport:client will fail even if it is part of the migration or inside another command.
According to this link, I ran the below commands.
composer update
php artisan config:cache
php artisan migrate
php artisan passport:install
This helped me.

After rename app folder and namespace artisan make shows Exception: Unable to detect application namespace

I've renamed my app folder to aplicativo and changed the namespace to aplicativo. Everything works but artisan make commands.
I changed namespace through composer.json
"psr-4": {
"aplicativo\\": "aplicativo/",
}
Plus command:
artisan app:name aplicativo
You won't get this to work. You can rename the namespace (as you did with the command), but you can't rename the directory because it's hardcoded as app.
You can see the source here.
Then... if your using composer try this command
composer dump-autoload
The good news is that Laravel has now added support for custom App path. You can override the App path by adding the following code in bootstrap/app.php (or provider).
/*...*/
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
// override the app path since we move the app folder to somewhere else
$app->useAppPath($app->basePath('src'));
Similarly, you can change other paths (database, language, storage, etc.). You can find all the available methods here.

how to create new module in Laravel

Is there any simple way to create new module in Laravel, if yes then please explain in detail.
Need to create new custom module in Laravel for users, product etc but didnt understand how to proceed with the same.
These packages will not help you if you don't understanding what exactly are you doing. I really recommend you to start with this tutorial, for example.
You should be right to go with
php artisan module:make <module_name>
You can also create multiple modules at once doing this:
php artisan module:make Users Products
this command will create all the resources you need like controller, seed class service provider and scaffold all the routes. If you dont want all this create new module with the following command
php artisan module:make Products --plain
After research found solution on GITHub :
https://github.com/jaiwalker/setup-laravel5-package
This might be better way to create a new package.
If anybody have better solution, then please share.
To install through Composer, by run the following command:
composer require nwidart/laravel-modules
The package will automatically register a service provider and alias.
Optionally, publish the package's configuration file by running:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
By default the module classes are not loaded automatically. You can autoload your modules using psr-4 (composer.json). For example :
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
Creating a module is simple and straightforward. Run the following command to create a module.
php artisan module:make <module-name>
It is also possible to create multiple modules in one command.
php artisan module:make Blog User Auth
You can refer this open source project to create module https://asgardcms.com/ - A modular multilingual CMS built with Laravel 5.

Resources