ItSolutionStuff.com

Laravel PHP json_decode without quotes Example

By Hardik Savani • May 14, 2024
Laravel

This article will give you example of laravel without decode " example. 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.

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 users = "{{ json_encode($users) }}";

console.log(users);

</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 DropzoneController extends Controller

{

/**

* Generate Image upload View

*

* @return void

*/

public function dropzone()

{

$users = [

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

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

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

];

return view('dropzone-view', compact('users'));

}

}

Solution 1: Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<script type="text/javascript">

var users = @json($users);

console.log(users);

</script>

</body>

</html>

Solution 2: Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<script type="text/javascript">

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

console.log(users);

</script>

</body>

</html>

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Last 7 Days Record in Laravel?

Read Now →

Laravel Import Large SQL File using Seeder Example

Read Now →

Laravel Sanctum SPA API Authentication Example

Read Now →

Laravel 8 Sanctum API Authentication Tutorial

Read Now →

Laravel Carbon Get Previous Month Example

Read Now →

Laravel Firebase Push Notification Tutorial

Read Now →

Laravel 8 Resource Route and Controller Tutorial Example

Read Now →

Angular 10 Display JSON Data in Table Example

Read Now →

Laravel Eloquent Where Like Query Example Tutorial

Read Now →

Laravel Create JSON File & Download From Text Example

Read Now →