Laravel-Backpack / basset

Better asset helpers for Laravel apps.
MIT License
155 stars 11 forks source link

Artisan::call commands wont work for basset #94

Closed Apeshy101 closed 1 year ago

Apeshy101 commented 1 year ago

Artisan::call('basset:clear');

This code would return The command "basset:clear" does not exist.

promatik commented 1 year ago

Hi @Apeshy101, that's true! The commands are only loaded on console mode.

@tabacitu do you think we should provide the commands for the app? Or keep the scope on console mode?

@Apeshy101 can you give us an example where you need this?

Apeshy101 commented 1 year ago

Hi @promatik

Thannks for responding, we are building a product which other developers purchase and install on their server.

From experience, 90% of our buyers are usually inexperienced developers and we offer product on “no coding knowledge required” basis.

To facilitate ease of use, we usually provide uses access to edits and customizations via a ui (just like Wordpress)

We also make an installer that comes with the products which takes care of and verifies all requirements.

On this specific use case, after installation is done, the installer runs several artisan commands to complete the set up.

For example, instead of accessing a shell, user can click on a button which clears cache by invoking the artisan command, etc

In this specific use case, after installation via our web installer, it should initialize the basset and cache it.

Also, most of users purchase for low level usage and mostly use shared hosting.

promatik commented 1 year ago

@Apeshy101, today I was taking a shower and just realised this is much easier than what I first though 😅

In order to have any package command available at your app's code, just go to App\Console\Kernel.php and add the command their;

App\Console\Kernel.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        \Backpack\Basset\Console\Commands\BassetClear::class,
    ];

You can now do;

Artisan::call(BassetClear::class)
// or
Artisan::call("basset:clear")