I was wondering if this would be a way to go to create a command for a task, or at least if t would work?
Thanks in advance!
$schedule->command('someCommand')
->call('Path\To\MyController#method'{
})
->dailyAt('00:00');
Yes, there is a way to create your own custom commands. Read this tutorial to create your own artisan command:
https://laravel.com/docs/5.1/artisan
Related
guys.
I tried creating a migration, model and controller using the php artisan commands and it was all created, but with wrong permissions: if I want to modify something and then save it in these new files, I need to save using sudo, which is a waste of time. I'd like to know if there's a way to change those permissions when creating the files. The docker is already outside sudo.
Thanks a lot.
Run php artisan command with the user you will use to access this files later or change the permissions for the files after you create them.
Is it possible to execute command prompt from Laravel controller? If YES, then how can i execute a command and what is the best way to do this? If NO,is there any other way how i can do this?
I dont Know if I get it.
Cant you use
PHP system()?
If I'm wrong please explain clearly
http://php.net/manual/en/function.system.php
If you only need to run artisan commands (e.g. migrating the database) you can easily do that from your controller:
Route::get('/foo', function () {
$exitCode = Artisan::call('email:send', [
'user' => 1, '--queue' => 'default'
]);
//
});
Source: Laravel Docs
There are some packages available that give you a UI for calling Artisan commands, just search for "laravel artisan web".
If you need to execute other commands you should give us more information about what you're trying to do.
Not 100% sure what you mean with "command prompt" but you can execute commands directly from php with the exec function. This is often not a recommended approach though and I would suspect that it is possible that if you need to run exec there is a design issue in the application.
I would recommend that you consider other approaches to the problem and only use exec in very special conditions.
I want to implement my project like this.
Users post forms decide when to run the task scheduling
and add filter conditions to select data from database.
Can laravel5.1 achieve this target?
I think that laraval queue is something that you need :)
https://laravel.com/docs/5.1/queues
I have successfully integrated PHP RESQUE in my Ubuntu 14.
How can I get list of failed jobs in PHP to process them? I tried searching on web but could not find specific answer for PHP.
Please help. Thanks in advance.
You have two options: one is using the Resque-web UI: https://github.com/resque/resque-web if you want to install it from scratch or, better yet, there is a Docker container that makes it easy to get it up and running: https://hub.docker.com/r/ennexa/resque-web/~/dockerfile/
Resque-web has a tab to see the failed jobs and the option to reprocess them.
Programmatically, I don't think there is a built-in method that would allow that so I guess you would have to be creative here. For example, from resque-php Github page: You have the ability to retrieve a token identifying a job when you create it:
$token = Resque::enqueue('default', 'My_Job', $args, true);
With that information, you can then retrieve the job status:
$status = new Resque_Job_Status($token);
echo $status->get(); // Outputs the status
You will want to check for this:
Resque_Job_Status::STATUS_FAILED
This also might give you some ideas: https://github.com/chrisboulton/php-resque/issues/324
I am new to laravel. i know command to create database from laravel migration.
I have already created database in mysql. so how can i convert migration from that database.
You could use Jeffrey Way's generator tool for Laravel 4, and do them by hand. It is a very useful tool. https://github.com/JeffreyWay/Laravel-4-Generators (if you are using Laravel 5, use this package instead: https://github.com/laracasts/Laravel-5-Generators-Extended)
Or you could try out one of the following packages, they should convert your existing schema to Laravel migrations. I have not tried them, but have a look:
https://github.com/adamkearsley/laravel-convert-migrations
https://github.com/barryvdh/laravel-migration-generator
Also, read the following answer in another question, might be useful to you or others: Reverse engineering or Auto-Generations of Entities in Laravel?
For modern versions of Laravel you should probably use a package like https://github.com/kitloong/laravel-migrations-generator
I quick wrote this python script to make migration files out of an existing database.
https://github.com/aljorhythm/sql-to-laravel-migrations
After set up, just do
python retrieve-and-convert.py
If the accepted answer (at the time of editing this post) does not work for you, use this simple approach.
Check out this package by Kitloong is really easy to use.
https://github.com/kitloong/laravel-migrations-generator
After installation, just run something like this to export the migration to a location of your choice:
php artisan migrate:generate --path="path\to\existing\folder"
Example:
php artisan migrate:generate --path="C:\xampp\htdocs\laravel_bs4\database\migrations\my_new_migrations"
You should end up with migrations created from the database and saved in the location you have specified.
You can omit the --path option and simply run
php artisan migrate:generate
This would export it to the default Laravel's migration folder (which is something I usually do not want).
Be sure to follow the prompts. Sticking to the default is usually okay.
How about this?
Migrations Generator.It's for Laravel, 4, 5, 6, 7, but I don't know if it is for Laravel 8
Simple solution, to use online Laravel migration generator for your existing SQL table schema without installing any package. Just enter your SQL schema and get Laravel migration file.
Try: https://laravelarticle.com/laravel-migration-generator-online
If you don't mind using Doctrine 2 in your project instead of Eloquent that has reverse engineering built in.
For laravel 9 follow below link
https://laravel.com/docs/9.x/migrations#generating-migrations