小编Kev*_*vvv的帖子

Laravel 上的“Action App\Http\Controllers\CommentRepliesController@createReply 未定义”错误

我正在尝试添加一个选项来回复对帖子的评论,但我一直收到:

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)

以下是我的 …

php sql lamp laravel

4
推荐指数
1
解决办法
1854
查看次数

在 React 中使用类的目的是什么?

我主要看到 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)

javascript constructor class reactjs

4
推荐指数
2
解决办法
5721
查看次数

你如何使用 react-apollo-hook 中的 useMutation 来执行删除突变?

我正在尝试使用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 …

reactjs graphql react-apollo react-hooks react-apollo-hooks

3
推荐指数
1
解决办法
3561
查看次数

如何在 GraphQL 中正确链接 useQuery 和 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显示未定义。如何确保及时定义返回值?

javascript reactjs graphql react-apollo react-hooks

3
推荐指数
1
解决办法
4282
查看次数

无法使用 useRef 钩子访问 React Native 中的 scrollToIndex() 方法

我正在尝试使用功能组件中的钩子从 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没有显示我正在寻找的上述方法。

reactjs react-native react-hooks

3
推荐指数
1
解决办法
1486
查看次数

如何将 ItemSeparatorComponent 添加到 FlatList 中的最后一项

我正在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)

reactjs react-native react-native-flatlist

3
推荐指数
1
解决办法
2331
查看次数

找不到类 'Illuminate\Notifications\NotificationServiceProvider'

我正在将我的 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

防止工匠在它被包含之前执行,但无济于事。

php sql lamp upgrade laravel

2
推荐指数
1
解决办法
2940
查看次数

如何在 React Native 中为 setNativeProps 使用 useRef 钩子?

我正在尝试将 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)

d3.js reactjs react-native react-hooks

2
推荐指数
1
解决办法
8800
查看次数

如何根据同一周期的状态有条件地运行 useEffect

我有一系列事件,其中一个事件必须依赖于前一个事件的执行而发生。

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

2
推荐指数
1
解决办法
8153
查看次数

尽管其有效性,但未提供所需类型的变量

我收到 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)

javascript reactjs graphql react-native react-apollo

2
推荐指数
1
解决办法
2万
查看次数