Tagged: laravel

Want to remove useless 0 digits from number

Problem: sometimes website is having a number with .0 or .00 but it is useless and waste of space.

Solution: use floatval Laravel or PHP based Language; use parseFloat() in Javascript, for example:

echo  floatval(10.50); // 10.5
echo  floatval(10); // 10
echo  floatval(10.00); // 10
echo  floatval(10.1); // 10.1

In javascript:

var a = parseFloat("10.50"); // 10.5
var b = parseFloat("10"); // 10
var c = parseFloat("10.00"); // 10
var d = parseFloat("10.1"); // 10.1

Protect .env file in Laravel project in the testing server

Problem: In the testing server, the .env file is viewable (e.g ip/laravel_project/.env), people can view all the sensitive data like DB username and password.

24/3/2019

The original solution is worked. All you need to do is change the .env file permission to 640. Then generate the Application Encryption Key again:

php artisan key:generate
php artisan config:cache

Solution: Change .env file permission while not affecting Laravel running

sudo chmod 640 .env
php artisan key:generate
php artisan config:cache

18/03/2019

Put the hosting directory into /var/www but not /var/www/html, so that user can not access through http://IP/project_name/public/ but to domain name. You can also Restrict directory access in Apache by allow some ip only in order to protect .env file and other sensitive information.