In this tutorial, we will learn Laravel 8 PHP json_decode without quotes Example


If you created an array with a laravel controller and assign that array to jquery variable then it looks like bellow with quotes. 

and it seems it's not json array:

<script type="text/javascript">
    var users = "{{ json_encode($users) }}";
    console.log(users);
</script>


 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' => 'Mark' ],
            [ 'id' => 2, 'name' => 'Pitter' ],
            [ 'id' => 3, 'name' => 'Michel' ]
        ];
  
        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 =  ;
  
    console.log(users);
</script>
</body>
</html>

May this example help you.