Laravel Orchid:如何在PostEditScreen.php中检索数据库中的post条目?
在 PostEditScreen .php 中的函数中,如何访问 PostEditScreen 引用的数据库中的条目?
Post::find($post.id)
不起作用。
任何帮助将不胜感激。
/**
* 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