【问题标题】:Laravel Orchid: How can the post entry in the database be retrieved from in the PostEditScreen.php?Laravel Orchid:如何从 PostEditScreen.php 中检索数据库中的帖子条目?
【发布时间】:2020-09-22 22:21:23
【问题描述】:

Laravel Orchid:如何从 PostEditScreen.php 中检索数据库中的帖子条目?

在 PostEditScreen.php 中的函数中,如何访问 PostEditScreen 所引用的数据库中的条目?

Post::find($post.id) 不工作。

任何帮助将不胜感激。

【问题讨论】:

    标签: database laravel


    【解决方案1】:
    /**
     * Query data.
     *
     * @param Post $post
     *
     * @return array
     */
    public function query(Post $post): array
    {
        // This will already be a record of your model.
    }
    

    或者你可以明确地做到这一点

    /**
     * Query data.
     *
     * @param int $id
     *
     * @return array
     */
    public function query(int $id): array
    {
       Post::find($id)
    }
    

    这在 laravel 文档中有说明:https://laravel.com/docs/7.x/routing#route-model-binding

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 2011-06-28
      相关资源
      最近更新 更多