Accessing Laravel .env variables in blade
Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications.
Here is full explanation:
https://www.youtube.com/watch?v=Q1ynDMC8UGg
php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan view:clear
php artisan route:clear
How to call .env {{ env('APP_NAME} }} to laravel blade template?
In fact you should never use env
helper directly in your application. All env should be put into config file and you should use config instead to avoid problems when config files are cached.
APP_NAME
env is put into config file by default (see https://github.com/laravel/laravel/blob/master/config/app.php#L16 ) so in your Blade file you should use:
@section('project_title', config('app.name'))
Laravel - accessing .env variables
Route::get('/test', function () {
return "it is".config('app.name');
});
How to access the laravel .env variables inside javascript?
You can just echo out the env variable as a javascript string in your view:
<script>
var name = '{{ env('NAME') }}';
alert(name);
</script>
And your .env file would look like this:
NAME=Alex
Why Laravel Policy is not working in View/Blade?
You need to pass the actual instance of the question (and you don't need to pass the user class) if the policy is regarding a specific question:
@can(App\Policies\QuestionPolicy::UPDATE, $question)
<a class="text-sm font-light text-gray-600" href="#">Edit</a>
@endcan
@can(App\Policies\QuestionPolicy::DELETE, $question)
<a class="text-sm font-light text-gray-600" href="#">Delete</a>
@endcan
$user
in the policy is always the currently signed in user.
Related Topics
$Stmt->Execute():How to Know If Db Insert Was Successful
MySQL Get a Random Value Between Two Values
Extract a Substring Between Two Characters in a String PHP
How to Replace All Xhtml/HTML Line Breaks (<Br>) with New Lines
Explode() into $Key=>$Value Pair
How to Pass Variables from JavaScript to PHP
Sum Specific Values in a Multidimensional Array (Php)
How to Solve Error 404 When Deploying Laravel Project to Cpanel
Errorbag Is Always Empty in Laravel 5.2
In PHP Can Someone Explain Cloning VS Pointer Reference
PHP Crop Image to Fix Width and Height Without Losing Dimension Ratio
Resetting MySQL Root Password with Xampp on Localhost