Laravel localization not working in all routes - php

I Blog in Laravel v5.6
when translate new route it doesn't work for me
but old route like login and register and landing pages it working as well when i going in new route it's not
Switch Lang page
Route::get('locale/{locale}', function ($locale) {
Session::put('locale', $locale);
return redirect()->back();
// this link will add session of language when they click to change langauge
})->name('locale');
Route::get('/{username}', 'ProfileAccountController#index')->name('profile')->middleware('admin.user');
when i going to this route it's not working and navbar and footer it's back to key, remove all code in this page and test the lang it's not work too.
I use all of this command and nothing
php artisan config:cache
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
Thank you.

My suggestions:
Use middle-wear for changing languages and use https://github.com/spatie/laravel-translatable like this for more comfortable usage.
Also check this Change language in Laravel 5 might help you.

Had similar issues with Route closures. Try moving you're session setters/getters to a Controller and not within a Route closure.
https://laravel.com/docs/5.7/session#using-the-session
This will probably solve your issues.

Related

How can I resolve RouteNotFoundException?

I'm trying to develope a program with Laravel, I have a problem with a Route, it shows me that is not define but it's already defined, also, I'm using Ajax.
This is the Error
This is my Ajax with URL and Route
And I tried to put the Route in that part of the code, but when I put there I get other problem.
I have tried this
Thank so much for your help.
After adding new route you need to clear cache. So run this commands:
php artisan cache:clear
php artisan route:cache
And check again
You have same controller method two time define and you did changed only route name? so it can return error. remove first route then it will work fine.
Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('client.schedules.destory');
Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('orders.schedules.store');
please remove Route::post('schedule/destory', 'Client\SchedulesController#destory')->name('client.schedules.destory'); route.

Laravel Keep caching though cleared

I have an annoying problem on Laravel, Though I clear all cached it's still caching. I've try to rename routes as like :
Route::get('/damn', function () {
dd(1);
});
it's should show me 1 but I when I try to check on browser the web still show me the normal view.
I was try with
php artisan config:cache
php artisan route:cache
php artisan cache:clear
and It's keep caching till I run
php artisan optimize
when I edited the route again , It's caching again and again and always must to run artisan optimize
Anyone can help me out ?
You can simply place the below code in your routes/web.php file of Laravel application. Then access this URL in the browser to clear the cache of Laravel application.
Route::get('/clear-cache', function() {
Artisan::call('cache:clear');
return "Cache is cleared";
});
Maybe have another route with the same uri and it returns a view.

Laravel sometimes doesn't load new controller

I'm facing a problem in Laravel. It seems that sometimes the Laravel framework loads an old version of a controller.
I created a new function and sometimes Laravel found it and sometimes it returns that the method does not exist.
What could be the problem in this case?
This is my function:
public function test(){
echo 'Here'; exit();
return view('welcome');
}
The Page sometimes show only Here (which is correct) and sometimes it redirects me to the welcome blade without showing the Here message.
Please make sure you are define the url in web.php within route folder
or use this command
php artisan cache:clear
php artisan config:cache

Laravel 5.2 Only one specific route not found, but it does exist

No matter what I try, the route /authenticate/{code} returns a NotFoundHttpException.
My route in routes.php:
Route::get('/authenticate/{code}', ['as' => 'authenticate', 'uses' => 'FrontendController#getAuthenticate']);
When I am calling the route:
URL::route('authenticate', $code)
On my local machine it runs it just fine, but on my production server, it takes me to a NotFoundHttpException page.
It does site inside of the web middleware group.
I have tried (with no success):
resetting the github repo on the server (fresh install)
composer update
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear
composer dump-autoload
changing the route from authenticate to authenticate-email
What could it be? Every other route on the site works, it is just this one that doesnt.
The only thing I can think to advise is switching from using the URL Facade to using the built in helper function $url = route('authenticate', ['code' => $code]); I only say this because I can't seem to find in the docs how you hint at URI parameters when using URL::route() :)
I also ran into this issue. I deleted the route, then copy another working route and changed the route name and parameters with the one. And It Worked
I don't know if you solved this but I just had exactly the same problem, nothing I did would make the route work. It was a really simple route: Route::get('/search', ['middleware' => 'shop_session','uses' => 'Cinder\StoreController#viewProducts']);
Did all the things you did. In the end I moved the route to the top of my routes file, ran php artisan route:cache and it worked.
Not a great answer and I've got no idea why it worked but it did. Maybe worth a try?

How to rollback effects of php artisan make:auth in laravel 5

I am new to laravel.
I was in middle of my project. I googled for login validation in laravel 5.
I found this command
php artisan make:auth
it Created several classes and also modified my welcome.blade.php
there was several code in welcome.blade.php.
Now How to rollback effects of this command.
Please Help.
Look at the make:auth command source code to understand what exactly files this command added or changed and revert changed back.
manually you have to remove following files
auth/login.blade.php
auth/register.blade.php
auth/passwords/email.blade.php
auth/passwords/reset.blade.php
layouts/app.blade.php
home.blade.php
Go to routes/web.php, delete the created routes by the command make:auth. Remove these two lines and your project will work fine as before.
Auth::routes();
Route::get('/home', 'HomeController#index');
The answer is NO.
There is no way you can rollback make:auth command as yet in laravel..
You can remove auth manually be removing auth from app controller and and auth route. And if you were lucky enough to have welcome file opened in some IDE then there was a chance of ctrl+z bcause IDEs keep back in memory,., but other then that there is no way retrieving backup the data.
we can simply remove below line form wep.php routes folder.
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
you can also remove the view files: like auth folder ,app.blade.php, home.blade.php

Categories