Php 将值从vue传递到控制器laravel时出现问题
我又遇到了另一个无法用Laravel和Vue解决的问题,我是Vue的新手,也许这就是为什么我有这么多困难的时间。 问题是: 在Vue视图中,我得到一个变化的值,直到这里一切正常,但问题是,我必须将该值传递给控制器,以便进行其他操作,代码如下: 这是触发值更改的选择:Php 将值从vue传递到控制器laravel时出现问题,php,laravel,vue.js,Php,Laravel,Vue.js,我又遇到了另一个无法用Laravel和Vue解决的问题,我是Vue的新手,也许这就是为什么我有这么多困难的时间。 问题是: 在Vue视图中,我得到一个变化的值,直到这里一切正常,但问题是,我必须将该值传递给控制器,以便进行其他操作,代码如下: 这是触发值更改的选择: <b-col md="4" sm="12"> <b-form-group label="Tipo: " label-for="tipo">
<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>
这是控制器中的功能:
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);
}
}
特别是我在本案中的路线:
Route::get('axios-tipo', ['as'=>'tecelagem.manutencao.cadastro.axios-tipo', 'uses' => 'TecelagemManutencaoController@axiosServices']);
我要做的是获取该值,传递给控制器并进行选择,以便填充该值:
<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>
我得到的错误是:
获取500(内部服务器错误)
在laravel日志中,我得到以下信息:
laravel.ERROR:无法将类Illumb\Database\Eloquent\Builder的对象转换为字符串
正如我之前所说,我是个新手,不知道我到底做错了什么
任何帮助都将不胜感激
提前谢谢。@DerekPollard,谢谢你帮助我,找出这里的错误 换线
axios.get(`${url}?{kind}=` + kind, this.manutencoes).then(res => {
用于:
控制器中的功能现在是:
public function axiosServices()
{
$tipo = Input::get('tipo');
//dd($tipo);
//return response()->json($tipo);
//\Log::info($tipo);
//$tipoSelection = $this->TecManutencaoTipoM->where('tipo', '=', $tipo)->get();
//return response()->json($tipoSelection);
//\Log::info($tipoSelection);
$tiposSelected = TecManutencaoTipo::select('manutencao AS value')
->where('tipo', '=', $tipo)
->get();
$dados = [];
if($tiposSelected) {
$dados = $tiposSelected;
//\Log::info($tipo);
return $dados;
} else {
//return response()->json(['dados' => $dados], 422);
return response()->json($dados, 422);
}
}
现在正在按预期工作。
再次感谢。@DerekPollard,谢谢你帮助我,找出这里的错误 换线
axios.get(`${url}?{kind}=` + kind, this.manutencoes).then(res => {
用于:
控制器中的功能现在是:
public function axiosServices()
{
$tipo = Input::get('tipo');
//dd($tipo);
//return response()->json($tipo);
//\Log::info($tipo);
//$tipoSelection = $this->TecManutencaoTipoM->where('tipo', '=', $tipo)->get();
//return response()->json($tipoSelection);
//\Log::info($tipoSelection);
$tiposSelected = TecManutencaoTipo::select('manutencao AS value')
->where('tipo', '=', $tipo)
->get();
$dados = [];
if($tiposSelected) {
$dados = $tiposSelected;
//\Log::info($tipo);
return $dados;
} else {
//return response()->json(['dados' => $dados], 422);
return response()->json($dados, 422);
}
}
现在正在按预期工作。
再次感谢。谢谢@DerekPollard帮我的忙,我尝试过,得到的错误和以前一样。你对这一行也这样做了吗<代码>返回响应()->json($dados,422)代码>?应该是
returnresponse()->json(['dados'=>$dados],422)代码>是的,我做了,错误是一样的,我想这可能是我的vue函数中的某个东西,但我不确定具体是什么。另外,删除这行:\Log::info($tipoSelection)
类的对象Illumb\Database\Eloquent\Builder无法转换为字符串
是控制器中的一个问题-您正在尝试将模型转换为字符串,这是导致该问题的原因。很可能是日志语句感谢@DerekPollard帮助我,我尝试过并得到与以前相同的错误。你对这行也做了同样的操作吗<代码>返回响应()->json($dados,422)代码>?应该是returnresponse()->json(['dados'=>$dados],422)代码>是的,我做了,错误是一样的,我想这可能是我的vue函数中的某个东西,但我不确定具体是什么。另外,删除这行:\Log::info($tipoSelection)
类的对象Illumb\Database\Eloquent\Builder无法转换为字符串
是控制器中的一个问题-您正在尝试将模型转换为字符串,这是导致该问题的原因。很可能是log语句