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?
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 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.
I have a Laravel app and I need to check if a user is logged and who from a external script. I'm using the following lines to load Laravel and try to check it.
require_once __DIR__.'/../../../vendor/autoload.php';
$app = require_once __DIR__.'/../../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel')
->handle(Illuminate\Http\Request::capture());
/*if (Cookie::get(config('session.cookie')) != "") {
$id = Cookie::get(config('session.cookie'));
Session::driver()->setId($pericod);
Session::driver()->start();
}*/
$isAuthorized = Auth::check();
if(!$isAuthorized){
echo "NO AUTORIZADO";
exit();
}
With this lines I can access any Laravel function and I can check the login if I made GET request to the external scripts, but when the request is POST it always fails. I'm unable to check the login and I see that the session changes because can't get the existing session.
I have made many tests and I think that somethings of Laravel are not working fine, like routes or middlewares. I can made it work if I disable all encryption of the cookies and the session, but I want to use this security functions.
I'm using updated Laravel 5.7 and I had this code working in Laravel 5.4
Thank you for your help.
I discovered the problem,
The trick is that the route is external to laravel so laravel's route resolver identifies the current route as /.
It was working on GET requests because in my routes file I have the / route only as get. If I set the / route as any, everything works.
I wasn't seeing the problem because I was not terminating Laravel's execution. If I change the logged user verification to this, it shows the error:
$isAuthorized = Auth::check();
if(!$isAuthorized){
echo "NO AUTORIZADO";
$response->send();
$kernel->terminate($request, $response);
exit();
}
This two lines ends laravel execution and returns the error "405 Method Not Allowed".
$response->send();
$kernel->terminate($request, $response);
Thank you for your help.
I'm using Laravel 5.4
web.php
Route::delete('claim/{id?}', 'ClaimController#claimRemove');
myTest.php
$response = $this->json('delete', 'claim', [
'id' => $id
]);
When i run phpunit, i'm getting the
MethodNotAllowedHttpException
BUT if I run it via Postman or phpstorm rest client - it works fine, so the reason is somewhere in $this->json method. I also tried $this->call.
If I switch delete method to post in web.php and in my test file - test is passing well.
So, question is - why it's not working with DELETE method or how to test DELETE calls?:)
Thanks.
Seems like it was version issue. Didn't modify anything, but after two weeks just composer update and test passed fine.
If composer update simply solved your problem it sounds like that your route cache has not been updated with your latest route changes. Both composer update and composer install include normally a list of artisan commands such as route:clear as they are specified indirectly in the composer.json file when optimize is used.
Secondly, use this form below due to the fact the id is part of your route otherwise it will hit the route without an id. However it will also be acceptable because you have made the parameter optional.
$response = $this->json('delete', 'claim/' . $id, []);
The way you have defined your routes, the ID needs to be passed in the URL.
Replace
$response = $this->json('delete', 'claim', [
'id' => $id
]);
with
$response = $this->json('delete', 'claim/' . $id, []);
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.