Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel access JsonResponse content

    // In Controller 
    // Method 1: Consumes get_json()
	public function test_json()
    {
        $res = $this->get_json();

        // dd($res->getData());
        // {
        //     "error": "Error Message"
        //     "success": false
        // }

        $data = $res->getData();

        dd($data->error); // 'Error Message'
    }
	// Methos 2; returns json
    public function get_json()
    {
        return response()->json(['error' => 'Error Message','success' => false], 403);
    }
 
PREVIOUS NEXT
Tagged: #laravel #access #JsonResponse #content
ADD COMMENT
Topic
Name
1+2 =