Skip to content

Allow to define JSON encoding options in Eloquent API Resources #38136

Closed Answered by tripleten
Gummibeer asked this question in Ideas
Discussion options

You must be logged in to vote

Don't we already have a method to set the encoding options in the API Resource?

You can do it by adding the below method either in your API collection or resource class:

/**
     * Customize the outgoing response for the resource.
     *
     * @param  \Illuminate\Http\Request
     * @param  \Illuminate\Http\Response
     * @return void
     */
    public function withResponse($request, $response)
    {   
        $response->header('Charset', 'utf-8');
        $response->header('Any-other-header', 'header-value');
        $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    }

Thoughts, @Gummibeer @mikemand & @nope123nope ?

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@Gummibeer
Comment options

@Gummibeer
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@NicoHood
Comment options

@NicoHood
Comment options

@NicoHood
Comment options

Answer selected by Gummibeer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
5 participants