source

Laravel API Allutive Where 절과 Vue가 작동하지 않음

nicesource 2022. 11. 4. 21:25
반응형

Laravel API Allutive Where 절과 Vue가 작동하지 않음

내 질문은 왜 내 장소 절이 작동하지 않는가?vue(vuex) 프로젝트에서 Laravel API를 사용하고 있습니다.

여기 컨트롤러 기능이 있습니다.

    public function specific_client(Request $request) {
            $id = $request->id;
            return JsonResource::collection(
            Measurement::where('client_id', '=',$id)
            ->with(['clients', 'measurement_data'])->get());
    }

vuetify도 사용합니다.이렇게 하면 client_id를 얻을 수 있습니다.

<v-select v-model="cnr" :items="clients" item-text="clientnumber" item-value="id" :hint="cnr" solo></v-select>

My store.js:

        fetchClientMeasurements({commit}, cnr) {
            axios.post("http://localhost:8000/api/clientnr", cnr)
                .then(response => {
                    console.log(response.data.data);
                    console.log(cnr);
                    commit("setMeasurements", response.data.data);
                });
         },

My API Route:

Route::post('clientnr', [MeasurementController::class, 'specific_client']);

콘솔 로그 "cnr"을 실행하면 올바른 ID는 반환되지만 데이터는 반환되지 않습니다.where 절에서 $id를 치환하면 올바른 정보가 반환됩니다.내가 어디선가 저지른 멍청한 실수라고 생각하지만, 그게 내가 여기 온 이유야.

에는 엑시오스라는 .id파라미터를 지정합니다.

axios.post("http://localhost:8000/api/clientnr", cnr)

그래야 한다

axios.post("http://localhost:8000/api/clientnr", {id: cnr})

언급URL : https://stackoverflow.com/questions/69987030/laravel-api-eloquent-where-clause-with-vue-not-working

반응형