I'm back with other problem that just can't solve with Laravel and Vue, i'm very new working with Vue and maybe that's why i'm having so much hard time. Here is the problem: In the Vue view, i get one value that changes, until here everything is working but the problem is, i have to pass this value to the controller so i can make some other operations, here's the code:
This is the select that triggers the change of values:
<b-col md="4" sm="12">
<b-form-group label="Tipo: " label-for="tipo">
<input type="hidden" v-model="maintenance.typeId" name="tipoId" id="tipoId">
<b-form-select v-model="selecionado" id="tipo" name="tipo" :options="options" :readonly="mode === 'remove'" @change="selecionar"></b-form-select>
</b-form-group>
</b-col>
That's the function that'll change the values and theoretically pass this value to the controller:
selecionar(value){
const kind = this.selecionado
const url = this.rotatipoautcomp
axios.get(`${url}?${kind}=` + kind, this.manutencoes).then(res => {
this.manutencoes = res.data
console.log(`${url}?${kind}=`)
console.log(res.data)
})
}
This is the function in the controller:
public function axiosServices()
{
$tipo = Input::get('selecionado');
$tipoSelection = TecManutencaoTipo::where('tipo', '=', (string)$tipo);
\Log::info($tipoSelection);
$tiposSelected = TecManutencaoTipo::select('manutencao AS value')
->where('tipo', '=', $tipoSelection->tipo)
->get();
$dados = [];
if($tiposSelected) {
$dados = $tiposSelected;
//\Log::info($tipo);
return $dados;
} else {
return response()->json($dados, 422);
}
}
My route for this case in particular:
Route::get('axios-tipo', ['as'=>'tecelagem.manutencao.cadastro.axios-tipo', 'uses' => 'TecelagemManutencaoController@axiosServices']);
What i want to do is to take this value, pass to the controller and do a select so i can populate this:
<b-col md="4" sm="12">
<b-form-group label="Manutenção: " label-for="manutencao">
<input type="hidden" v-model="maintenance.manutencao" name="manutencaoId" id="manutencaoId">
<!--<b-form-input id="manutencao" placeholder="Informe o nome da manutenção..." :readonly="mode === 'remove'" />-->
<b-form-input list="input-list1" id="manutencao" placeholder="Informe o nome da manutenção..." :readonly="mode === 'remove'"></b-form-input>
<b-form-datalist id="input-list1" :options="manutencoes"></b-form-datalist>
</b-form-group>
</b-col>
The error that i'm getting is this:
GET http://localhost:8000/portal-cambos/tecelagem/manutencao/cadastro/axios-tipo?0=0 500 (Internal Server Error)
In the laravel log i get this:
laravel.ERROR: Object of class Illuminate\Database\Eloquent\Builder could not be converted to string
As i've said before, i'm very new and, don't know what exactly i'm doing wrong here.
Any help will be very appreciated.
Thanks in advance.
return response()->json($dados, 422);
? should bereturn response()->json(['dados' => $dados], 422);
– Derek Pollard\Log::info($tipoSelection);
– Derek PollardObject of class Illuminate\Database\Eloquent\Builder could not be converted to string
is an issue in your controller - you're trying to convert a model into a string, which is what's causing the issue. Most likely, it's the log statement – Derek Pollard