Center return message API - Laravel 5.6

0

Good night everyone,

Well, I'm a few days away looking for an alternative or better practice, but without success, I would like your opinion.

I'm developing an API in Laravel 5.6, and I would like to know a better practice for returning the messages in json.

I currently have following code, briefly:

classefilha.php

//Chamada para o metodo na classe pai
public function consulta(){
$this->mensagemRetorno($conteudo);
}

Classepai.php

//Mensagem padrao para retorno das infos
public function mensagemRetorno($conteudo){
return response()->header('Content-Type', $type)->json($conteudo);
}

In this way, I can not return the content, because the content of the return (method return message) directs to the call function (query).

I need to return the header that also contains the token (JWT), but in this way I can not.

How can I centralize all responses in a single method?

If possible, please advise me, I am newcomer to programming and laravel.

Thank you

    
asked by anonymous 27.06.2018 / 03:09

0 answers