在数据库React Shopify应用程序的通过值期间获得错误
我正在学习使用 php+laravel/react js 创建Shopify自定义应用程序, 我创建了一个具有一些字段的表单,并且该字段数据将存储在数据库中,但是当我发送数据时,它会出现错误。
在此过程中,当我通过 axios.post('/wp_share_cart',data)不起作用时,我不知道为什么。
组件文件代码:whatsappsharecart.jsx
import {gql, useQuery} from '@apollo/client';
import {Banner, AppProvider} from '@shopify/polaris';
import React from 'react';
import {Component} from 'react';
import ReactDOM from 'react-dom';
import {Loading} from '@shopify/app-bridge-react';
import app from "/css/app.css";
import { useReducer, useState } from 'react';
import axios from 'axios';
import { useNavigate } from 'react-router-dom'
import {Provider, useAppBridge, TitleBar} from '@shopify/app-bridge-react';
function WhatsappSharecart() {
const [wp_enable, setWpEnable] = useState("No");
const [buttonlabel, setButtonlabel] = useState("Share on WhatsApp");
const [cartmessage, setCartmessage] = useState("Hey! There Watch My Cart.");
const [buttonposition, setButtonposition] = useState("Default");
const [bitlyenable, setBitlyenable] = useState("No");
const [bit_token, setBitToken] = useState("Enter Bitly Access Token");
const handleChange = (event) => {
setWpEnable(event.target.value);
setButtonposition(event.target.value);
setBitlyenable(event.target.value);
}
/*const handleSubmit = event => {
event.preventDefault();
alert(`Whatsapp Share Cart Enable: ${wp_enable}`)
alert(`Button Label Is: ${buttonlabel}`)
alert(`Cart Message on Whatsapp Share Link Is: ${cartmessage}`)
alert(`Whatsapp Button Position on Cart Page Is: ${buttonposition}`)
console.log(buttonlabel);
}*/
const handleSubmit = event =>{
event.preventDefault();
const data = {
wp_enable: wp_enable,
buttonlabel: buttonlabel,
cartmessage: cartmessage,
buttonposition: buttonposition,
bitlyenable: bitlyenable,
bit_token: bit_token
}
/*fetch( '/api/wp_share_cart', {
method:'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify()
})
.then(response => {
return response.json();
})
.then(data => {
//update the state of links
});*/
axios.post('/wp_share_cart', data)
.then((response) => {
console.log(response .data)
}).catch((error) => {
console.log(error)
});
}
const handleAlternate = event => {
event.preventDefault();
alert(`Bitly Short URL Enable: ${bitlyenable}`)
alert(`Bitly Generic Access Token: ${bit_token}`)
}
return (
<div className="wp_share_cart">
<h1>General Configuration</h1>
<form onSubmit={handleSubmit}>
<fieldset>
<label>
<p>Whatsapp Share Cart Enable</p>
<select value={wp_enable} onChange={handleChange}>
{/*<option value="">--Please choose an option--</option>*/}
<option value="Yes">Yes</option>
<option value="No"> No </option>
</select>
</label>
<label>
<p>Button Label Text</p>
<input type="text"
value={buttonlabel}
onChange={(e) => setButtonlabel(e.target.value)}
name="wp_share_cart_label"/>
</label>
<label>
<p>Cart Message on Whatsapp Share Link</p>
<textarea value={cartmessage} onChange={(e) => setCartmessage(e.target.value)} />
</label>
<label>
<p>Whatsapp Button Position on Cart Page</p>
<select value={buttonposition} onChange={(e) => setButtonposition(e.target.value)}>
{/*<option value="">--Please choose an option--</option>*/}
<option value="Default"> Dafault </option>
<option value="Left"> Left </option>
<option value="Center"> Center </option>
<option value="Right"> Right </option>
</select>
</label>
</fieldset>
<button type="submit">Save Configuration</button>
<h1>Enable Bitly Short URL Settings</h1>
<fieldset>
<label>
<p>Bitly Short URL Enable</p>
<select value={bitlyenable} onChange={handleChange}>
{/*<option value="">--Please choose an option--</option>*/}
<option value="Yes">Yes</option>
<option value="No"> No </option>
</select>
</label>
<label>
<p>Bitly Generic Access Token</p>
<textarea value={bit_token} onChange={(e) => setToken(e.target.value)} />
</label>
</fieldset>
<button type="submit" onClick={handleAlternate}> Save Configuration</button>
</form>
</div>
)
}
export default WhatsappSharecart;
控制器文件:insertwpdatacontroller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class InsertwpdataController extends Controller
{
public function index()
{
return view('products');
}
public function wp_share_cart(Request $request)
{
//dd('test132');
$wp_enable = $request->input('wp_enable')
$buttonlabel = $request->input('buttonlabel')
$cartmessage = $request->input('cartmessage')
$buttonposition = $request->input('buttonposition')
$bitlyenable = $request->input('bitlyenable')
$bit_token = $request->input('bit_token');
}
}
路由器文件代码:web.php
Route::post('/','InsertwpdataController@wp_share_cart');
<强>路线清单
Illuminate\Contracts\Container\BindingResolutionException
Target class [InsertwpdataController] does not exist.
at E:\xampp\htdocs\shopifyapps\whatsapp_share_cart\vendor\laravel\framework\src\Illuminate\Container\Container.php:875
871▕
872▕ try {
873▕ $reflector = new ReflectionClass($concrete);
874▕ } catch (ReflectionException $e) {
➜ 875▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
876▕ }
877▕
878▕ // If the type is not instantiable, the developer is attempting to resolve
879▕ // an abstract type such as an Interface or Abstract Class and there is
1 [internal]:0
Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
2 E:\xampp\htdocs\shopifyapps\whatsapp_share_cart\vendor\laravel\framework\src\Illuminate\Container\Container.php:873
ReflectionException::("Class InsertwpdataController does not exist")
Whoops\Exception\ErrorException
Module 'openssl' already loaded
1 E:\xampp\htdocs\shopifyapps\whatsapp_share_cart\vendor\filp\whoops\src\Whoops\Run.php:486
Whoops\Run::handleError("Module 'openssl' already loaded", "Unknown")
2 [internal]:0
Whoops\Run::handleShutdown()
I'm learning to create Shopify custom app using PHP+Laravel/React js,
i have created one form that has some fields, and that fields data I'm stored to the database but when I send data it gives the error.
in this when I have passed the axios.post('/wp_share_cart', data) that is not working, I don't know why it.
Component file code : WhatsappSharecart.jsx
import {gql, useQuery} from '@apollo/client';
import {Banner, AppProvider} from '@shopify/polaris';
import React from 'react';
import {Component} from 'react';
import ReactDOM from 'react-dom';
import {Loading} from '@shopify/app-bridge-react';
import app from "/css/app.css";
import { useReducer, useState } from 'react';
import axios from 'axios';
import { useNavigate } from 'react-router-dom'
import {Provider, useAppBridge, TitleBar} from '@shopify/app-bridge-react';
function WhatsappSharecart() {
const [wp_enable, setWpEnable] = useState("No");
const [buttonlabel, setButtonlabel] = useState("Share on WhatsApp");
const [cartmessage, setCartmessage] = useState("Hey! There Watch My Cart.");
const [buttonposition, setButtonposition] = useState("Default");
const [bitlyenable, setBitlyenable] = useState("No");
const [bit_token, setBitToken] = useState("Enter Bitly Access Token");
const handleChange = (event) => {
setWpEnable(event.target.value);
setButtonposition(event.target.value);
setBitlyenable(event.target.value);
}
/*const handleSubmit = event => {
event.preventDefault();
alert(`Whatsapp Share Cart Enable: ${wp_enable}`)
alert(`Button Label Is: ${buttonlabel}`)
alert(`Cart Message on Whatsapp Share Link Is: ${cartmessage}`)
alert(`Whatsapp Button Position on Cart Page Is: ${buttonposition}`)
console.log(buttonlabel);
}*/
const handleSubmit = event =>{
event.preventDefault();
const data = {
wp_enable: wp_enable,
buttonlabel: buttonlabel,
cartmessage: cartmessage,
buttonposition: buttonposition,
bitlyenable: bitlyenable,
bit_token: bit_token
}
/*fetch( '/api/wp_share_cart', {
method:'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify()
})
.then(response => {
return response.json();
})
.then(data => {
//update the state of links
});*/
axios.post('/wp_share_cart', data)
.then((response) => {
console.log(response .data)
}).catch((error) => {
console.log(error)
});
}
const handleAlternate = event => {
event.preventDefault();
alert(`Bitly Short URL Enable: ${bitlyenable}`)
alert(`Bitly Generic Access Token: ${bit_token}`)
}
return (
<div className="wp_share_cart">
<h1>General Configuration</h1>
<form onSubmit={handleSubmit}>
<fieldset>
<label>
<p>Whatsapp Share Cart Enable</p>
<select value={wp_enable} onChange={handleChange}>
{/*<option value="">--Please choose an option--</option>*/}
<option value="Yes">Yes</option>
<option value="No"> No </option>
</select>
</label>
<label>
<p>Button Label Text</p>
<input type="text"
value={buttonlabel}
onChange={(e) => setButtonlabel(e.target.value)}
name="wp_share_cart_label"/>
</label>
<label>
<p>Cart Message on Whatsapp Share Link</p>
<textarea value={cartmessage} onChange={(e) => setCartmessage(e.target.value)} />
</label>
<label>
<p>Whatsapp Button Position on Cart Page</p>
<select value={buttonposition} onChange={(e) => setButtonposition(e.target.value)}>
{/*<option value="">--Please choose an option--</option>*/}
<option value="Default"> Dafault </option>
<option value="Left"> Left </option>
<option value="Center"> Center </option>
<option value="Right"> Right </option>
</select>
</label>
</fieldset>
<button type="submit">Save Configuration</button>
<h1>Enable Bitly Short URL Settings</h1>
<fieldset>
<label>
<p>Bitly Short URL Enable</p>
<select value={bitlyenable} onChange={handleChange}>
{/*<option value="">--Please choose an option--</option>*/}
<option value="Yes">Yes</option>
<option value="No"> No </option>
</select>
</label>
<label>
<p>Bitly Generic Access Token</p>
<textarea value={bit_token} onChange={(e) => setToken(e.target.value)} />
</label>
</fieldset>
<button type="submit" onClick={handleAlternate}> Save Configuration</button>
</form>
</div>
)
}
export default WhatsappSharecart;
Controller File : InsertwpdataController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class InsertwpdataController extends Controller
{
public function index()
{
return view('products');
}
public function wp_share_cart(Request $request)
{
//dd('test132');
$wp_enable = $request->input('wp_enable')
$buttonlabel = $request->input('buttonlabel')
$cartmessage = $request->input('cartmessage')
$buttonposition = $request->input('buttonposition')
$bitlyenable = $request->input('bitlyenable')
$bit_token = $request->input('bit_token');
}
}
Router file code: web.php
Route::post('/','InsertwpdataController@wp_share_cart');
Route List
Illuminate\Contracts\Container\BindingResolutionException
Target class [InsertwpdataController] does not exist.
at E:\xampp\htdocs\shopifyapps\whatsapp_share_cart\vendor\laravel\framework\src\Illuminate\Container\Container.php:875
871▕
872▕ try {
873▕ $reflector = new ReflectionClass($concrete);
874▕ } catch (ReflectionException $e) {
➜ 875▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
876▕ }
877▕
878▕ // If the type is not instantiable, the developer is attempting to resolve
879▕ // an abstract type such as an Interface or Abstract Class and there is
1 [internal]:0
Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
2 E:\xampp\htdocs\shopifyapps\whatsapp_share_cart\vendor\laravel\framework\src\Illuminate\Container\Container.php:873
ReflectionException::("Class InsertwpdataController does not exist")
Whoops\Exception\ErrorException
Module 'openssl' already loaded
1 E:\xampp\htdocs\shopifyapps\whatsapp_share_cart\vendor\filp\whoops\src\Whoops\Run.php:486
Whoops\Run::handleError("Module 'openssl' already loaded", "Unknown")
2 [internal]:0
Whoops\Run::handleShutdown()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须从控制器(
dd('test132');
)中删除转储和模具功能。You have to remove the dump and die function from your controller (
dd('test132');
).