ErrorException: ??? ?? ? 'name'? ???? ?????.
P粉187677012
2023-08-31 10:33:00
<p>?? ?? ??? ???? ?? ?? ???? ???? ????. ??? ???????? ??? ?? ? ??? ???? ?? CRUD API? ????? ???? ???? ??????? ????? ?? ?? ??? ?????. </p>
<???>
<p>quote ???? JSON? ?? ???? ? ?? ??: SyntaxError: ??? ?? ?? '<', "? ??? JSON? ????</p>
<p>??? JSON ?? ??? ??????: <!-- ErrorException: ???? ?? ?? ?
??? "??"
C:UsersmjverOneDriveDocumentsCodingclient-apiroutesapi.php on
238?</p>
</???>
<p>?????? $data["name"] ??? ?? ???? ????? ??? ???? ????. ?? ?? ??? ?? ?? ?? ?? ????? ??? ?? ??? ??? ????.</p>
<p>?? ?? ??? ??? ????</p>
<p>調(diào)??api.js?? API
<pre class="brush:php;toolbar:false;">async sendOrder(){
console.log(this.cart);
const ?? = APIController.CreateOrder(this.cart.name, this.cart.qty, this.cart.option, this.cart.price, this.orderNum, this.cart.fee, this.cart.date, this. ID);
if(??){
store.dispatch('clearCart');
}
},</pre>
<p>api.js 文件中的 API ??:</p>
<pre class="brush:php;toolbar:false;">CreateOrder: (??, ??, ??, ??, ?? ??, ???, ??, ??? ID) => {
responseClone? ?????;
const csrfToken = document.cookie.match(/XSRF-TOKEN=([^;]+)/)[1];
???(
?? == "" ||
?? == "" ||
?? == "" ||
?? == "" ||
???? == "" ||
?? == "" ||
userId == ""
) {
??? ??;
} ? ?? {
return fetch(API_BASE + "/orders/create", {
??: "POST",
??: {
"??? ??": "application/json",
"X-CSRF-TOKEN": csrfToken
},
??: JSON.stringify({ ??, ??, ??, ??, ?? ??, ???, ??, userId })
}).then((??) => {
responseClone = response.clone();
response.json() ??
})
.then(??? => {
if(???.??){
Alert("??? ????? ???????!")
??? ??;
} ? ?? {
throw data.response.error;
}
}, (rejectionReason) => {
console.log('???? JSON? ?? ???? ? ??? ??????: ', ReasonReason, responseClone);
responseClone.text()
.then((bodyText) => {
console.log('??? JSON ?? ??? ???: ', bodyText);
});
}).catch(err => {
??(err);
});
}
},</pre>
<p>api.php 文件中的 php ??由:</p>
<pre class="brush:php;toolbar:false;">Route::post('/orders/create', function($request ??){
$data = $request->all();
if(!Orders::where('orderNo', '=', $data['orderNo'])->exists()){
$order = ??::??([
"??" => $data["??"],
"??" => $data["??"],
"??" => $data["??"],
"????" => $data["????"],
"??? ID" => $data["??? ID"],
"??" => $data["??"],
"???" => $data["???"],
"??" => $data["??"],
]);
if(empty($order->id)){
?? [
"??" => ??,
"??" => [
"??" => "????? ??? ??????"
]
];
} ? ?? {
?? [
"??" => ??,
"??" => [
"??" => $??
]
];
}
} ? ?? {
?? [
"??" => ??,
"??" => [
"??" => "???? ??? ?? ?????"
]
];
}
});</pre>
<p>?? 訂單模型文件:</p>
<pre class="brush:php;toolbar:false;">class Orders? ??? ?????.
{
HasFactory? ?????.
??? $fillable = [
'??',
'??',
'??',
'????',
'??? ID',
'??',
'??',
'??',
];
?? ?? ?? (){
return $this->hasMany(Product::class);
}
}</pre>
<p>如果您能幫助我解決這個(gè)問題,我將不勝感激,因?yàn)槲乙呀?jīng)為此苦苦掙扎了一段時(shí)間。</p>
?? ??? ??? ? ???. console.log(this.cart.name)? ????? "???? ??"? ??? ??????. ? ??? ??? ?? state.cart? ?? ??? ??? ?? ??? ???? ????? ?? ?? ?????. ?? ? ??? ????? ?? ? ?? ??? ?? ???? ?? ?????. ??? ? ???? ??? ????.
???
??: this.cart? ??? ?? ????? ?? for ??? ???? ????? ?? ? ??? ???? ??? ?? ???? ??????? ???? ??? ???? ???.
?? +0
P粉187677012