Laravel Send URL with JSON
Ad
i send url with json with this code
return response()->json([
'code' => '200',
'message' => 'success',
"resource" => url()."/packages/calibre/images/products/".$artwork->image
]);
but when i try to test the response, it's show the link
http:\/\/localhost:8000\/packages\/calibre\/ etc..
how to fix it? it's have double slash and backslash (/)
Ad
Answer
Ad
This works fine,
$artwork->imag = 'img.jpg';
return response()->json([
'code' => '200',
'message' => 'success',
"resource" => url("/packages/calibre/images/products/{$artwork->imag}")
]);
Response in Postman:
{
"code": "200",
"message": "success",
"resource": "http://laravel.dev/packages/calibre/images/products/img.jpg"
}
Response in Web browser:
{"code":"200","message":"success","resource":"http:\/\/laravel.dev\/packages\/calibre\/images\/products"}
If you wish to remove slashes from the encoded URL do this:
return response(json_encode([
'code' => '200',
'message' => 'success',
"resource" => url('/packages/calibre/images/products/')
], JSON_UNESCAPED_SLASHES))->header('Content-Type', "application/json");
Response in web browser
{"code":"200","message":"success","resource":"http://verimarked.dev/packages/calibre/images/products"}
Ad
source: stackoverflow.com
Related Questions
Ad
- → I can't convert Json to string [OctoberCms]
- → Uncaught TypeError Illegal invocation when send FormData to ajax
- → Laravel Send URL with JSON
- → how to write react component to construct HTML DOM
- → AJAX folder path issue
- → Chaining "Count of Columns" of a Method to Single Query Builder
- → Laravel - bindings file for repositories
- → Good solution to work with rest-api like SPA with redux?
- → getting the correct record in Angular with a json feed and passed data
- → Transformer usage on laravel/dingo API
- → Google options Page not saving - Javascript
- → Ember.js JSON API confusion
- → How can I query Firebase for an equalTo boolean parameter?
Ad