Hi Developers,
Lets learn How to Use PHP Code in Laravel Blade . In this lets dicuss How to Use PHP Code in Laravel Blade it was necessary to know How to Use PHP Code in Laravel Blade using the blade directives. Using PHP Code in Laravel Blade will reduce the workload in the controller file and also useful in creating the switch statements .
Sometimes we need to use php code inside the blade file for some variable declarations etc. To solve this Laravel provides some default blade directives.
In this example we use the core PHP in the laravel blade file
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$title = "Hello World - ITSolutionsGuides";
?>
<h1>{{ $title }}</h1>
</body>
</html>
Unlike above example , this example was suggested by the laravel community
@php @endphp this syntax was suggested by the Laravel
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
@php
$title = "Hello World - ITSolutionsGuides";
@endphp
<h1>{{ $title }}</h1>
</body>
</html>
We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides