laravel 5.2 config constant does not work on server - laravel

i seperate my strings and put them in Constant directory in textConstant.php file , in my localhost everythings are okey but when i uploads my code on my server the string fade out and nothing show in my screen ,
here is my constant file :
return [
'title' => 'test',
'book' => 'book_test',
];
and here is my code that use constant :
<button>{{config('Constants.textConstant.book')}}</button>
please help me to solve my problem because my site cannot be usable, thanks alot :)

Try to run the following code over commandline if you have enabled the cache.
php artisan config:clear
php artisan config:cache.

In CMD;
Write first
php artisan config:clear
Then
php artisan config:cache
Hope this will work.

Related

Assets are not linking in my laravel project

after running php artisan serve my project is running on http://127.0.0.1:8000/.
I am inserting files on logo folder my inserting code is
$request->file('logo')->store('logo', 'public');
this code is inserting files inside \storage\app\public\logo\
Now when I try to view this file in image there is no image showing
my image view code is
http://127.0.0.1:8000/storage/logo/eoFICKlGoU8yDoJrLGYfKFsx6Yq4uGvDs5yC9WQ7.png
my filesystem default is 'default' => env('FILESYSTEM_DISK', 'public'),
also in the env it FILESYSTEM_DISK = public
I have tried
php artisan config:clear
php artisan storage:link
php artisan optimize:clear
But still failed to show the image in . Please help I have tried many method available on stackoverflow
Simply run, php artisan storage:link.
The problem might be that your storage is not linked to your public folder.

How to change default language in Laravel?

I want my site to only be in swedish language. How to accomplish this?
In my lang/sv/ folder I have six files.
auth.php
pagination.php
passwords.php
sv.json
validation-inline.php
validation.php
The page source says html lang="sv" but everything is in english.
Also the email verification is in english.
This is what I have done so far.
In app\config\app.php I have change this
'locale' => 'sv',
'fallback_locale' => 'sv',
In my terminal I have run these commands.
composer dump-autoload
php artisan config:clear
php artisan view:clear
php artisan cache:clear
php artisan event:clear
php artisan optimize:clear
What else can I do?
I'm using Laravel 8.12.
I solved it. I had the sv.json file in the wrong folder.
It should be in lang folder not in lang\sv\ folder.

Laravel 5.6 env('APP_BASE_URL') returns null

In staging and production environment, when I try to get my custom defined variable from .env file, it returns null. I have tried creating new Key for APP and cleared all sort of caches, but result is same.
APP_NAME="App - Staging"
APP_ENV=staging
APP_KEY=<HIDDEN_KEY>
APP_DEBUG=true
APP_LOG_LEVEL=none
APP_URL=https://staging.app.com
APP_BASE_URL="https://app-staging.app.com"
Clearing Cache
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:cache
But when using following in blade view gets nothing
env('APP_BASE_URL') returns null
It is because you have run php artisan config:cache. If you are using config:cache, your env() calls should only be made in your config files.
See here: https://laravel.com/docs/5.6/configuration#configuration-caching
This post solved my issue, I defined custom config in config/app.php
https://laracasts.com/discuss/channels/laravel/accessing-custom-environment-variable
/*
|-------------------------------------------------------------------------
| Custom config variables
|-----------
|
*/
'base_url' => env('APP_BASE_URL', 'http://localhost'),
Then in .env I definded:
APP_BASE_URL="https://app-staging.app.com"
Finally cleared the cache, worked.
In blade view
{{ config('app.base_url') }}
Yes it will return only null
If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.
See the laravel documentation https://laravel.com/docs/5.6/configuration#configuration-caching

Getting messages feature in Debugbar to work in Laravel

I've installed Debugbar for Laravel as described in the steps on the website https://laravel-news.com/laravel-debugbar; and tried to make use of the Messages feature by placing the following below in my code.
Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
But when I run my website, I get the error message from Laravel saying:
1/1
FatalErrorException in HistoryController.php line 11:
Class 'App\Http\Controllers\Debugbar' not found
I have to go like /Debugbar::info(...) or put use Debugbar at the top of my code to not get the error message. Why can't I use it straight like Debugbar::info(...)?
To be able to reference the facade without prefixing it with \ you should add
use Barryvdh\Debugbar;
to the top of your controller.
after adding setting code in /config/app.php
you can use it as a facade
app('debugbar')->info('info message');
or
debugbar()->info('message');
no need use
I think you should try this :
first you add below code in config/app.php
in provider section
'Barryvdh\Debugbar\ServiceProvider',
in aliases section
'Debugbar' => 'Barryvdh\Debugbar\Facade',
after you should clear the cache like:
php artisan config:cache
php artisan cache:clear
php artisan config:clear
Hope this work for you !
Firstly, Go to the terminal and install by typing:-
composer require barryvdh/laravel-debugbar
In second step, Check your laravel verision:-
php artisan --version
In third if your laravel version is greater than 5(Laravel 5.x)
add the ServiceProvider to the providers array in config/app.php
Barryvdh\Debugbar\ServiceProvider::class,
add this to your facades in app.php:
'Debugbar' => Barryvdh\Debugbar\Facade::class,
Finally, published vendor configuration by command:-
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
After vendor published clear cache,route,view by command
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan dump-autoload -o

After upgrading laravel 5.1 to 5.2 \App::environment() always returning "production"

I upgraded laravel 5.1 to 5.2, everything looks good.
But when try to access the app environment not getting what expected.
When i dd($_ENV) this is what i get
"APP_ENV" => "vagrant"
"APP_DEBUG" => "true"
"DB_HOST" => "localhost"
But When dd(\App::environment());
"production"
P.S. even I checked in tinker: dd(env('APP_ENV')) gives me "vagrant"
but dd(\App::environment()) gives me "production".
Dont you think it is odd :(
This is wierd :(
Anyone face this problem ??
you missed a step in the upgrade process:
Configuration
Environment Value
Add an env configuration option to your app.php configuration file that looks like the following:
'env' => env('APP_ENV', 'production'),
P.S. You can check the value from the artisan command:
php artisan env
Sometimes when you changed in your .env file it does not take correct values from that, the problem is due to some configuration cache.Try running following commands, hope will work
php artisan config:cache
php artisan config:clear
php artisan cache:clear

Resources