How to get json_decode without quotes in PHP Laravel

Laravel 8 , Laravel 7 , Laravel , Laravel 6

Nicesnippets

1297

28-01-2021


Hi Guys

Today,I will learn you how to get json_decode without quotes in PHP laravel,you can understand a concept of laravel array json_decode example. you will learn laravel array json ". step by step explain laravel json encode array jquery file. we will explain json_decode without quotes example in laravel php.

If you created array with laravel controller and assign that array to jquery variable then it looks like bellow with quotes. it seems it's not json array

<script type="text/javascript">

var student = "{{ json_encode($student) }}";

console.log(student);

</script>

you will get output as like bellow:

But i will give you simple solution. we will use code php and @json laravel blade directive. let's see bellow two solution:

Controller Code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class StudentController extends Controller

{

/**

* Generate Image upload View

*

* @return void

*/

public function dropzone()

{

$students = [

[ 'id' => 1, 'name' => 'Dharmik' ],

[ 'id' => 2, 'name' => 'Mehul' ],

[ 'id' => 3, 'name' => 'Keval' ]

];

return view('student-view', compact('students'));

}

}

Solution 1: Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<script type="text/javascript">

var users = <?php echo json_encode($students) ?> ;

console.log(students);

</script>

</body>

</html>

Solution 2: Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<script type="text/javascript">

var students = @json($students);

console.log(students);

</script>

</body>

</html>

It will help you....