I am trying to debug my application and I had few log statements using Log facade. For now, I run the application using artisan serve and it will write the log message to the log file and to get a real time log message I run.
tail -f laravel.log
Is there any way I can directly print the log message to the same console/terminal that is running php artisan serve?
You can do this using following. This works anywhere..
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$output->writeln("<info>Error message</info>");
This will print the message in terminal / console that is running php artisan serve
tail -f storage/logs/laravel.log & php artisan serve
Based on #aquasmit answer:
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$output->writeln("<info>Info message</info>");
Note the added \ before Symfony.
The standard "error_log" PHP function does what you want.
Related
I have a doubt, I know that to call only laravel commands I have to use the command Artisan::call('command name') but how can I do it if I want to execute the following task
Artisan::call('cat archive | php artisan project:method'); //NOT WORK
cat name_file | php artisan project:method
For example I want to execute the command
CAT /tmp/archive.eml | php artisan command:name_method
Since what I want to do is to read files with cat that are in another directory through a foreach and enter the command that manipulates the data of those files.
I am writing a console command. This command also calls another command.
Basically say: php artisan command:one. So inside command one, I call php artisan command:two.
They both have interactions ($this->info()) stating the progress or state of the current operations. But when I run php artisan command:one I can't see this displayed info from php artisan command:two, though php artisan command:two has its own output info and progress state.
How do I ensure to see the progress and states from php artisan command:two which is called in php artisan command:one?
Using Artisan::call() doesn't redirect called command's output to original command's output.
To call another Artisan command and save its output you should use $this->call() from your command.
I often do something like this:
php artisan route:list
php artisan migrate
php artisan db:seed
Only artisan command name is changed. I know how to get all parameters of previous command except last: !:1- (in my case it gives me artisan). But maybe exist shortcut that gives me command name with all arguments except last (in my case php artisan)? I know I can use alias a="php artisan" for such purpose, but general shortcut for any command will be very useful.
The same trick applies, just change 1 to 0
!:0-
What about a function? I called it rms for route; migrate; seed
rms () { php "$1" "route:list"; php "$1" migrate; php "$1" "db:seed"; }
Hello, I am working on app in which i need to use phpmd as php artisan phpmd(i ). means make phpmd as local command and use in project.requirement is when i clone the project no additional things should be required and one can freely run `php artisan phpmd` command.which work same as `phpmd`
command will be like php artisan phpmd <file> <ruleset>
I guess you're already have your Artisan command ready and working. Then best approach will be creating .bat script for Windows and .sh script for Unix systems and placing it in Laravel project's root directory.
For example, phpmd.bat file can look like that:
php artisan phpmd %1 %2
When you'll clone the project, you can just run phpmd someFile someRuleset from Laravel project directory and it should work exactly as php artisan phpmd someFile someRuleset command.
For Ubuntu, Mac and other Unix OS .sh file will look similar:
#!/bin/sh
php artisan phpmd $1 $2
This question already has answers here:
How to keep Laravel Queue system running on server
(20 answers)
Closed 4 years ago.
I have implemented Laravel queue.The thing is i have to run the command php artisan queue:listen every time.Is there any way that the jobs get executed automatically without running any command.
Here's a one-liner to put into your crontab (let it run, let say, every 5 minutes):
cd /path/to/your/project && jobs -l | grep `cat queue.pid` || { nohup /usr/bin/php artisan queue:listen & echo $! > queue.pid; }
two variables here:
1. /path/to/your/project -- is your Laravel project root. Effectively, the folder, where php artisan would work;
2. /usr/bin/php -- path to PHP executable on the server (which php)
Yes, if you use Linux you can use for example supervisor which will run php artisan queue:listen (you need to add this command to supervisor configuration file) and it will make sure all the time this command is running.