HDTuto.com

How to Use PHP Code in Laravel Blade?



This article will give you example of laravel blade write php code. if you have question about laravel blade write php then i will give simple example with solution. Here you will learn how to write php code in blade file in laravel. it's simple example of how to write php code in laravel view. Let's see bellow example how to write php code in laravel blade.

Here, i will give you simple two way to write core php code in blade file in laravel framework. first if using @php that provided by laravel and i will suggest that one and another is using <?php that is using php syntax.

So let's see both example one by one:

Example 1: @php

I will suggest this syntax to use php code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

@php

$title = "How to Write PHP Code in Laravel Blade? - HDTuto.com";

$myArray = ['id'=>1,'name'=>'Hardik'];

@endphp

<h1>{{ $title }}</h1>

</body>

</html>

Example 2:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<?php

$title = "How to Write PHP Code in Laravel Blade? - HDTuto.com";

$myArray = ['id'=>1,'name'=>'Hardik'];

?>

<h1>{{ $title }}</h1>

</body>

</html>

You can use anyone, i hope it can help you...




April 23, 2020 | Category : Laravel



Blog Search