Skip to content

Instantly share code, notes, and snippets.

@ricardobarantini
Created May 3, 2019 21:00
Show Gist options
  • Save ricardobarantini/8a25328c98516975e4b9900bd669b5bc to your computer and use it in GitHub Desktop.
Save ricardobarantini/8a25328c98516975e4b9900bd669b5bc to your computer and use it in GitHub Desktop.
Exemplo de código para retornar dados em json no Laravel
<?php
// ...
use App\Models\Aluno;
public function getAlunos($matricula)
{
$alunos = Aluno::where('matricula', $matricula)->get();
if ($alunos->count() > 0) {
$data['alunos'] = $alunos;
} else {
$data['mensagem'] = 'Nenhum aluno encontrado';
}
return response()->json($data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment