I want to make an alias like
php artisan go
instead of
php artisan serve
I will appreciate any other idea :-) .I also read this link and search a lot but it wasn't so clear and other questions were about making class
or .env
files and etc.
Thanks in advance
Update
This question is not duplicate of this because it's not contain calling php artisan
itself.
To create a new artisan command, we can use the make:command artisan command. This command will make a new command class within the app/Console/Commands catalog. In case the directory does not exist in our laravel project, it'll be automatically made the primary time we run the artisan make:command command.
Press Ctrl + Shift + ESC. Locate the php process running artisan and kill it with right click -> kill process. Reopen the command-line and start back the server. Note that you should be able to kill the process just by sending it a kill signal with Ctrl + C.
Reasons why php artisan serve not working You are running php artisan serve command in wrong directory. php artisan serve is laravel command only work with laravel project. Check project directory and run in root directory of your project.
Create the command using:
php artisan make:command GoCommand
Add this in the class:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\ConsoleOutput;
class GoCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'go';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$output = new ConsoleOutput;
$output->writeln("Laravel development server started: <http://127.0.0.1:8000>");
Artisan::call('serve');
Artisan::output();
}
}
Use the command:
php artisan go
Visit: http://127.0.0.1:8000/
and see the output in your console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With