Laravel 8 PHP json_decode without quotes Example
Hi Guys,
In this blog, I will show you example of laravel without decode " example. you can understand a concept of laravel array json_decode example. We will talk about aravel 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' => '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>
It will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial