I use vue.js as frontend and laravel as backend.
I want to run artisan command from code when I click button.
My artisan command : "php artisan crawler:crawl 2"
If you are vue and laravel expert It's very foolish question for you.
Please waste your short time to help me.
Make a route to call the function:
Route::get('/crawl', function() {
Artisan::call('crawler:crawl 2');
return 'crawl ran';
});
Make method in view to call it.
Related
In my application i have a laravel backend with two spas consuming api from it. Now i want to manage my routes by using wildcard routes where i give both routes prefixes before the wildcard route takes effect. Here is an example
Route::prefix('creditors')->group(function () {
Route::any('/{all}', function () {
return view('creditor');
})->where(['all' => '.*']);
});
Now the issue us if i visit something like /creditors/login the spa returns a 404 not found. I want my spa to start handling routing after "creditors/". How do i go about this?
First remove this code :
->where(['all' => '.*']);
Second use these commands :
php artisan cache:clear
php artisan route:cache
And finally try again.
I'm sorry if you are confused or misunderstood because i can't explain it very well. I already saved my web.php but i didn't know why it won't read my new saved web.php. it will read my previously saved web.php which is the view of login.blade.php, my new saved web.php is the view of download.blade.php and it still the view of login.blade.php. i thought that maybe it always return to the view of my previously saved web.php.
Previously in web.php:
Route::get('/', function () {
return view('login');
});
Previously in the terminal
/css/login.css
New saved web.php:
Route::get('/', function () {
return view('download');
});
After saved web.php in terminal:
/css/login.css
And after i make a new route like:
Route::get('/help', function () {
return view('help');
});
and when i use /help it says that 404|Page Not Found
And of course i already make the new help.blade.php and the css
Please help thank you
Here's the code in web.php
You can use php artisan route:list to show which routes have been set from your web.php.
If changes in your web.php don't reflect in that list or on your site chances are your routes are cached. In that case, run
php artisan route:clear
to clear the cache and re-read from your web.php file.
More on the topic:
Route Caching
Try php artisan route:clear to remove the route cache file
Or php artisan optimize:clear to remove the cached bootstrap files (all cached from your app)
I have deployed new code to my Forge server. This code includes new routes (web, api, with and without auth).I have run php artisan optimize, but all the new routes return a 404.
The php artisan route:list command display the new routes. I am getting crazy...
Help!?
thanks
OK, someone gave me the solution on Laravel's Slack. I had to relaunch PHP fpm on my Forge server, in order to reset the OPCache.
I have laravel using crud generator package, that run with controller with this command
Artisan::call("crud:generate", [
"name" => ucwords(str_singular($request->input('table'))),
"--fields" => $fields
]);
after the controller run, it's show error because the route is not exist. One thing that i know is the crud generator code is fine, but the artisan proccess is not done yet, so it's show error.
After waiting a few of second, and i pres F5 for refreshing page, it's not showing error anymore.
How to make my controller redirect after the artisan call done?
Is there any possibility to turn on and turn off Laravel 5 maintenance without php artisan up and down commands when my website is being hosted ?
What I've done:
Route::get('site/shutdown', function(){
return Artisan::call('down');
});
Route::get('site/live', function(){
return Artisan::call('up');
});
The first route is working fine. But when I call site/live the site still is shuted down. What can cause this problem ?
If your project is already down, you cannot call another function.
What happens after you run php artisan down is that it creates a file named down inside storage/framework. After running php artisan up the file is removed.
You can create the file manually inside storage/framework. It will down your project. When you want to take your project live again, just remove the file.
I think the right answer is missing here..
You could add your route to app/http/middleware/CheckForMaintenanceMode.php
protected $except = [
//here
];
So It never would be off.
when you run artisan down. site is not available so when try to call up, your IP can't access site.
you must call down with your IP exception.
php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16
or add ::1 to local.
to make that in route without command
try to save this command in specific one and call it.
Laravel 8 introduced secret in maintenance mode, in which you can bypass the maintenance mode by providing a secret, then your Artisan::call would work.
You could add your routes to the $except var in CheckForMaintenanceMode middleware to bypass the check. Then your site/live route would work just fine.
In order to make your site live again using an url, you can create a live.php file which you put in laravel's public folder and then visit http://your.domain/live.php .
In the live.php file you need something like this: (check your projects directory structure if you don't use the default public folder!)
<?php
unlink(dirname(__FILE__) . "/../storage/framework/down");
header("Location: your.domain");
die;
just put
Artisan::call('up');
without route function.