I created a button for the user to be able to clear cache routes and views.
<div class="col-6">
clear cache
</div>
I'm using Artisan::call but it does not work. Where is my problem?
Route::get('/clearcache', function() {
Artisan::call('view:clear');
Artisan::call('cache:clear');
Artisan::call('route:clear');
return show_message(true, 'clear cache ');
})->name('cache.clear');
If I remove the show_message() function, your code works.
Route::get('/clearcache', function() {
Artisan::call('view:clear');
Artisan::call('cache:clear');
Artisan::call('route:clear');
})->name('cache.clear');
Change the route, run php artisan serve. Then hit the route directly in your browser: http://127.0.0.1:8000/clearcache
Another option...
php artisan optimize:clear
Artisan::call('optimize:clear');
This will return you the following.
Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
Caches cleared successfully!
All cache types that exist in your Laravel application will be cleared entirely, except Events cache.
Related
i wrote url like that
use App\Http\Controllers\DashController;
Route::get('/admin/special', [DashController::class, 'addSpecializations'])->name('add.sp');
this is controller
public function addSpecializations()
{
return view('dashboard.add-specializations');
}
when i tried to open it i can't even though all route work
after that i wrote this code in view's file
<a href="{{route('add.sp')}}">
so i faced this issue
Route [add.sp] not defined.
In case your routes are cached, run php artisan route:clear. In development, don't cache anything, including views and config.
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 had some weird issues in the past with Laravel routing, however they could usually be fixed with some form of logical solution, eg. clearing the route cache, or a genuine user error...
But this one is very strange. I have been developing this site for a few weeks and using the /admin routes for some time, but today anything related to /admin or logging in is resulting in a 404 | not found from Laravel. And now even adding any new routes is not working, including very basic ones.
eg. the home page is routed like this:
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home'])->name('home');
But adding:
Route::get('/test', [App\Http\Controllers\FrontendController::class, 'home'])->name('test');
To my web.php routes is also bringing me to a 404.
Just to explain my development environment, I am on Windows and I have tried serving this with both "php artisan serve", and also with XAMPP, but both are giving me the same issue. I won't bother explaining the XAMPP set up, because this was literally working yesterday and nothing has changed, but with php artisan serve it takes me to "http://127.0.0.1:8000/".. this doesn't require any special hacking.. it usually just works.
What have I done differently today?
So all I have done today is:
Added a new command with "php artisan make:command SomeCommandIStartedMaking"
This surely hasn't screwed anything up? I've even deleted the command and reset to my last commit just in case and still the routes are screwed.
In my windows "hosts" file I added "127.0.0.1 somedomain.com"
So this sounds like the kind of thing that would have an effect on routing, and it's where I first noticed the issue.. but since then I have "ipconfig /flushdns", I have removed the entries from my host file, and I have cleared my laravel routes and caches, but still the issue remains.
I am really stuck on this one. Also finally! I have done a route:list and I can clearly see the routes showing up like expected, but I can assure you that nothing has changed since yesterday so this seems like another issue.
Here is a dump of web.php, because I know this will be asked for:
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
// Frontend
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home'])->name('home');
Route::get('/instagram-gallery', [App\Http\Controllers\FrontendController::class, 'instagramGallery'])->name('instagram-gallery');
Route::get('/{pageAlias}', [App\Http\Controllers\PageController::class, 'index'])->name('page');
Route::post('/contact-send', [App\Http\Controllers\PageController::class, 'contactSend'])->name('contact-send');
Route::get('/test', [App\Http\Controllers\FrontendController::class, 'home'])->name('test');
// Admin
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'is_admin']], function(){
Route::get('/', [App\Http\Controllers\AdminController::class, 'index'])->name('admin');
Route::get('/search/{table}', [App\Http\Controllers\AdminController::class, 'search'])->name("admin-search");
Route::get('/browse/{table}', [App\Http\Controllers\AdminController::class, 'browse'])->name("admin-browse");
Route::get('/create/{table}', [App\Http\Controllers\AdminController::class, 'create'])->name("admin-create");
Route::get('/edit/{table}/{id}', [App\Http\Controllers\AdminController::class, 'edit'])->name("admin-edit");
Route::get('/manage-account', [App\Http\Controllers\AdminController::class, 'manageAccount'])->name("admin-manage-account");
Route::get('/documentation/{subject?}', [App\Http\Controllers\AdminController::class, 'documentation'])->name("admin-documentation");
Route::post('/create/{table}/action', [App\Http\Controllers\AdminController::class, 'createAction'])->name("admin-create-action");
Route::post('/edit/{table}/{id}/action',[App\Http\Controllers\AdminController::class, 'editAction'])->name("admin-edit-action");
Route::post('/delete', [App\Http\Controllers\AdminController::class, 'deleteAction'])->name("admin-delete-action");
Route::post('/wysiwyg-upload', [App\Http\Controllers\AdminController::class, 'wysiwygUpload'])->name("wysiwyg-upload");
Route::post('/manage-account-action', [App\Http\Controllers\AdminController::class, 'manageAccountAction'])->name("admin-manage-account-action");
});
require __DIR__.'/auth.php';
One thing to add, is that "/contact" resolves just fine which is using the '/{pageAlias}' route as shown above, so some are working and some aren't. How should I trouble shoot this I don't even know where to start :(
Any help would be hot! This is so frustrating haha! Thanks in advance..
This might due to cache so run following commands
php aritsan config:clear
php artisan route:clear
To use single command:
PHP artisan optimize
The problem is the order of your routes - the code will run line by line trying to find a matching route.
Once it hits
Route::get('/{pageAlias}', [App\Http\Controllers\PageController::class, 'index'])->name('page');
It will match /test and naturally stop - never reaching your next route.
To solve this, your specific route /test needs to be defined before your general "catch-all" route /{pageAlias}
I have Laravel set up. I am running multiple domains to it. Before yesterday I had one top level domain and a few sub domains. I added another TLD yesterday and everything started working weird. Specifically, when trying to log into the admin section it redirects to the home page. I have one admin but server domains coming to the site. My route group it:
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() {
Sometimes is actually brings me into the admin but as soon as I click on a link I get logged out and redirected to the home page. I keep seeing 401 errors in the console as well.
What would cause this?
edit
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() {
Route::get('/', 'AdminController#index');
Route::get('/pages', 'AdminController#pages');
Route::get('page/create', 'AdminController#createPagePage');
Route::post('createPage', 'AdminController#createPage');
Route::get('/page/edit/{page_id}', 'AdminController#editPagePage');
Route::post('editPage', 'AdminController#editPage');
});
$redirectTo = '/';
If you are using Linux, try to check the session file permissions and change them so the app can write session keys on that file and if it doesn't work, try to change the session driver to database.
how to change the session driver?
Go to your .env file and change SESSION_DRIVER=file to SESSION_DRIVER=database.
create a session migration: php artisan session:table.
composer dump-autoload.
Finally migrate (php artisan migrate).
Have you setting the SESSION_DOMAIN right?
One thing you may notice is that session isn’t saved when the user is logged-in in one store and goes to another. To fix that issue, we’ll need to add a SESSION_DOMAIN variable to our .env file, for example:
SESSION_DOMAIN=’.example.com’
That’s all, now user session will be shared across all shops/subdomains in our app.
https://medium.com/#maxkostinevich/how-to-build-multi-domain-laravel-application-e6d87d5e507b
If you are confident with the domain setup correctly. Please verify these few things.
1. Your config/session.php is correctly setup to support multiple domains.
'driver' => env('SESSION_DRIVER', 'file'), // check /storage folder writtable recursivelly.
'domain' => env('SESSION_DOMAIN', null), // verify if single domain is not given in .env or in settings.
'same_site' => null // it should not be strict if you have ajax request across these domain. I mean from javascript you may try to request to other domain.
etc...
2. Confirm, if your routes are not group under domain specific. something like:
Route::group(['domain' => 'xxx'], function($params)
{
// your routes..
});
3. If there is any hardcoded domain verification/conditions or redirection added in code.
4. Any values in .env poiting to single domain.
5. Also don't forgot to clear the cache/compiled view/routes and delete the temp files once. like generated files inside /app/bootstrap & /storage
// Clear Application Cache
php artisan cache:clear
// Clear route cache
php artisan route:cache
// Clear config cache
php artisan config:cache
// Clear compiled view files
php artisan view:clear
6. Any thirdparty package might contains the domain settings. Make sure to verify the files in your /config folder.
7. Check the url rewrite settings in .htaccess
8. Do confirm if there is any proxy settings are there or any software installed on server - very rare case.
In case still having issue, please restart the apache/nginx service once because sometimes the config changes not effected after change that might need server restart.
Hopefully it helps.
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.