John Davidson

php - Laravel getting javascript file as locale

0 comments
Message:


I am using Datapicker in Laravel project. I also implemented localalization there. The problem is Laravel is getting pikaday.js file as locale at first session. However, when I set locale manually as /en everything works fine untill the end of the session. How can I deal with this problem?


dd(\app()->getLocale()); is showing this:



Here is the middleware for localization:



This is the way of how I am importing js files for Datepicker.




My Answer:
To solve this issue, you can try the following steps:

1. Make sure that you have set the default locale in your `config/app.php` file. You can set it like this:

php
'locale' => 'en',


2. Check if the locale is being set correctly in your middleware. You can do this by adding a `dd(\app()->getLocale());` statement in your middleware to see if the locale is being set correctly.

3. If the locale is not being set correctly, you can try setting the locale manually in your middleware before loading the Datepicker JavaScript file. You can do this by adding the following code in your middleware:

php
app()->setLocale('en');


4. Make sure that you are including the Datepicker JavaScript file after setting the locale in your middleware. This will ensure that the Datepicker is loaded with the correct locale.

By following these steps, you should be able to resolve the issue of Laravel getting the JavaScript file as the locale at the first session.

Rate this post

4 of 5 based on 1753 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us