I am trying to retrieve an array using axios to do the ajax request, but the result is always empty. Funny is that same request works just fine with artisan tinker!
Let's see some code:
route/web.php file
Route::get('/trocaCarros/{id}', 'VitrineController@trocaCarros')->name('trocaCarros');
The Vuejs method:
methods: {
umaMarca() {
// alert(marca.value);
axios.get('/trocaCarros/' + marca.value).then(response => this.vitrine = response.data);
}
The VitrineController.php
public function trocaCarros(Request $request)
{
$marca = $request->id;
$umaMarcaModelo = Modelo::where('marca_id','=', $marca);
return response()->json($umaMarcaModelo);
}
The browser response is:
{}
But, when I did it at the Tinker:
Psy Shell v0.8.11 (PHP 7.1.6 — cli) by Justin Hileman
$marca = 212
=> 212
Then...
$modelo = App\Modelo::where('marca_id','=', $marca)->get();
It returns 6 results, as I have in database, like:
=> Illuminate\Database\Eloquent\Collection {#994
all: [
App\Modelo {#995
id: 880011,
descricao: "Accord",
marca_id: "212",
categoria_id: "1",
ativo: 1,
created_at: "2017-08-03 18:35:19",
updated_at: "2017-08-03 19:41:36",
},
App\Modelo {#996
id: 880012,
descricao: "City",
marca_id: "212",
categoria_id: "1",
ativo: 1,
created_at: "2017-08-03 18:47:26",
updated_at: "2017-08-03 18:47:26",
},
... and more 4 others
Does anyone know what I missed?
->get()in the first one?