我正在尝试添加一个选项来回复对帖子的评论,但我一直收到:
CommentRepliesController@createReply 未定义。
通过添加对帖子的回复PostCommentsController@store效果很好。但是,当我尝试通过返回帖子或直接comment/reply在 URL 中添加对评论的回复时,它给了我上面的错误。
以下是我的路线:
Route::group(['middleware'=>'auth'], function(){
Route::resource('comment/reply', 'CommentRepliesController@createReply');
});
Run Code Online (Sandbox Code Playgroud)
以下是我的CommentRepliesController@createReply:
public function createReply(Request $request){
$user = Auth::user();
if($user->photo){
$data = [
'comment_id' => $request->comment_id,
'author' => $user->name,
'email' => $user->email,
'photo' => $user->photo->file,
'body' => $request->body
];
} else{
$data = [
'comment_id' => $request->comment_id,
'author' => $user->name,
'email' => $user->email,
'body' => $request->body
];
}
CommentReply::create($data);
$request->session()->flash('reply_message', 'Your reply has been submitted
and is awaiting moderation.');
return redirect()->back();
}
Run Code Online (Sandbox Code Playgroud)
以下是我的 …
我主要看到 JavaScript 使用类作为构造函数,如下所示:
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
// Getter
get area() {
return this.calcArea();
}
// Method
calcArea() {
return this.height * this.width;
}
}
Run Code Online (Sandbox Code Playgroud)
React 使用类而不使用contructor()函数的原因是什么,例如以下?我没有看到类用于创建实例。
class App extends Component {
render() {
return (
<div className="app-content">
</div>
)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用s 中的useMutation钩子react-apollo-hook来执行删除突变,但是在以下代码中我很难将帖子的 ID 值传递给突变钩子:
const Posts = () => {
const { data, error, loading } = useQuery(GET_POST)
const onDeleteHandler = useMutation(DELETE_POST, {
variables: { id }
})
if (loading) return <div>...loading</div>
if (error) return <div>Error</div>
return data.posts.map(({id, title, body, location, published, author}) => {
return (
<div className="card" key={id}>
<p>id: {id}</p>
<p>title: {title}</p>
<p>body: {body}</p>
<p>location: {location}</p>
<p>published: {published}</p>
<p>author: {author.name}</p>
<Link to={`/post/${id}/edit`}>
Edit
</Link>
<button
onClick={onDeleteHandler}>
Delete
</button>
</div>
)
})
}
Run Code Online (Sandbox Code Playgroud)
由于钩子不能用作回调函数,因此我不能useMutation …
我有 useQuery 和 useMutation 从 react-apollo-hooks 背靠背。我希望能够使用 useQuery 的返回值作为 useMutation 的变量。目前, useQuery 的值没有及时返回变量,导致变量未定义。
const { data, error, loading } = useQuery(GET_POSTS, {
variables: {
id: props.match.params.id
}
})
const item = props.match.params.id
const owner = data.posts[0].author.id
const variables = { item , owner, startDate, endDate }
const bookItem = useMutation(CREATE_BOOKING_MUTATION, variables)
Run Code Online (Sandbox Code Playgroud)
变量data.posts[0].author.id显示未定义。如何确保及时定义返回值?
我正在尝试使用功能组件中的钩子从 FlatList访问scrollToIndex()方法或scrollToItem()方法useRef。我希望能够flatListRef.current.ScrollToIndex()在我的组件中使用,类似于基于类的组件使用的方式this.flatListRef.ScrollToIndex():
const flatListRef = useRef(React.createRef)
<FlatList
data={items}
renderItem={({ item }) => <Item item={item} />}
keyExtractor={item => item.id.toString()}
contentContainerStyle={styles.card}
horizontal={true}
showsHorizontalScrollIndicator={false}
ref={flatListRef}
/>
Run Code Online (Sandbox Code Playgroud)
console.loggingflatListRef.current没有显示我正在寻找的上述方法。
我正在Item SeparatorComponent为我的FlatList. 有没有办法将该行添加到列表的最末尾,例如最后一项的底部边框?
export default Item = ({ title, data }) => {
const renderSeparator = () => (
<View
style={{
backgroundColor: 'lightgrey',
height: 0.5,
}}
/>
)
return (
<View style={styles.container}>
<View style={styles.title}>
<Text style={styles.titleText}>{title}</Text>
</View>
<View style={styles.subItem}>
<FlatList
ItemSeparatorComponent={renderSeparator}
data={data}
renderItem={({ item }) => (
<SubItem
title={item.title}
subText={item.subText}
/>
)}
keyExtractor={item => item.id.toString()}
/>
</View>
</View>
)
}
Run Code Online (Sandbox Code Playgroud) 我正在将我的 Laravel 从 5.2 升级到 5.3 并且已经阅读了https://laravel.com/docs/5.3/upgrade上的文档,但是当我运行我的应用程序时我仍然收到这条消息:
ProviderRepository.php 第 146 行中的 FatalErrorException:找不到类 'Illuminate\Notifications\NotificationServiceProvider'
我已经将 Illuminate\Notifications\NotificationServiceProvider 添加到提供者,并将 Illuminate\Support\Facades\Notification 添加到 config/app.php 中的别名。我也试过:
作曲家转储自动加载
作曲家更新 --no-scripts
防止工匠在它被包含之前执行,但无济于事。
我正在尝试将 React Native 的类组件转换为涉及useRef. 以下是类组件:
import React, { Component } from "react";
import { AppRegistry, StyleSheet, Text, View, Animated, TouchableWithoutFeedback } from "react-native";
import { interpolateNumber, interpolateRgb } from "d3-interpolate";
export default class animations extends Component {
state = {
animation: new Animated.Value(0)
};
componentWillMount() {
const positionInterpolate = interpolateNumber(0, 200);
const colorInterpolate = interpolateRgb("rgb(255,99,71)", "rgb(99,71,255)");;
this.state.animation.addListener(({value}) => {
const position = positionInterpolate(value);
const color = colorInterpolate(value);
const style = [
styles.box,
{
backgroundColor: color,
transform: [
{translateY: …Run Code Online (Sandbox Code Playgroud) 我有一系列事件,其中一个事件必须依赖于前一个事件的执行而发生。
const [token, setToken] = useState('')
const getToken = async () => {
try {
const newToken = await AsyncStorage.getItem(LOGIN_TOKEN)
setToken(newToken)
} catch (err) {
throw new Error(err)
}
}
useEffect(() => {
getToken()
if(token) {
console.log("the final event")
}
}, [postAction])
Run Code Online (Sandbox Code Playgroud)
我有useEffect每次postAction更改时都会运行的钩子。我希望“最终事件”仅在getToken运行并检索token. 我相信 setter 的异步性质setToken没有及时发生来token设置 以满足 的条件if statement。因此,最终事件永远不会在第一次运行时执行。
asynchronous race-condition reactjs react-native react-hooks
我收到 GraphQL 错误,但我似乎无法查明其来源。
所需类型“String!”的变量“$title” 没有提供。
所需类型“String!”的变量“$body” 没有提供。
所需类型“Int!”的变量“$price” 没有提供。
错误消息很简单。此突变需要三个必需变量,并且错误显示没有提供任何类型,即使明确提供了它们。令人困惑的部分是使用 GraphQL Playground 的相同突变工作得很好。在前端使用其他突变也能正常工作。这告诉我这不是解析器或服务器的问题。
我的突变 GraphQL 如下所示:
export const CREATE_POST_MUTATION = gql`
mutation CreatePost($title: String!, $body: String!, $price: Int!) {
createPost(data: {
title: $title, body: $body, price: $price
}
){
id
title
}
}
`
Run Code Online (Sandbox Code Playgroud)
我正在使用 Apollo 的 React Hook:
export const CREATE_POST_MUTATION = gql`
mutation CreatePost($title: String!, $body: String!, $price: Int!) {
createPost(data: {
title: $title, body: $body, price: $price
}
){
id
title
}
}
`
Run Code Online (Sandbox Code Playgroud)
表单的提交处理程序:
const [createPost, …Run Code Online (Sandbox Code Playgroud) reactjs ×8
react-hooks ×5
react-native ×5
graphql ×3
javascript ×3
react-apollo ×3
lamp ×2
laravel ×2
php ×2
sql ×2
asynchronous ×1
class ×1
constructor ×1
d3.js ×1
upgrade ×1