• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Laravel 5 controller sending JSON integer as string

phpjsonlaravellaravel-5php-5.6


PHP Snippet 1:

return response()->json(["foo" => "bar"], 200, [], JSON_NUMERIC_CHECK);

PHP Snippet 2:

return (int)Post::find(1)->id;

PHP Snippet 3:

class Controller extends BaseController {
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public static function json($json) {
        return response()->json($json, 200, [], JSON_NUMERIC_CHECK);
    }

PHP Snippet 4:

return self::json($all);

Related Snippets

Increase value by 1 on button click

mysql_result is defined but mysql_free_result warns it expected a resource

PHP array stringify

yii2 and mssql insert varbinary into model

Cache clear probem in Larave

How can I make Laravel return a custom error for a JSON REST API

Show date difference as "20" instead of "20 years ago"

Lexik JWT authentication problem "Invalid credentials"

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Laravel Route issues with Route order in web.php

Using Associative arrays

Reducing authentication calls on external API (Laravel 5.6)

Warning: sqlite_query() expects parameter 1 to be resource, string given

file_put_content...fail to open stream:Permission denied in Laravel 5

zsh: command not found: php

About Contact Privacy policy Terms and conditions