所以我昨天才开始使用 Laravel 和 Orchid... 现在我遇到了这个问题
我想为所有帖子创建一个数据页面
所以我创建布局:PostListLayout
类 PostListLayout 扩展了 Table {
public $target = 'posts';
/**
* @return TD[]
*/
public function columns(): array
{
return [
TD::make('title', 'Title')
->render(function (Post $post) {
return Link::make($post->title)
->route('platform.post.edit', $post);
}),
TD::make('created_at', 'Created'),
TD::make('updated_at', 'Last edit'),
];
}
}
定义表格层后,我们返回到视图屏幕
class PostListScreen extends Screen
{
/**
* Display header name.
*
* @var string
*/
public $name = 'Blog post';
/**
* Display header description.
*
* @var string
*/
public $description = 'All blog posts';
/**
* Query data.
*
* @return array
*/
public function query(): array
{
return [
'posts' => Post::paginate()
];
}
/**
* Button commands.
*
* @return Link[]
*/
public function commandBar(): array
{
return [
Link::make('Create new')
->icon('pencil')
->route('platform.post.edit')
];
}
/**
* Views.
*
* @return Layout[]
*/
public function layout(): array
{
return [
PostListLayout::class
];
}
}
但最终我得到了这个错误页面:
Call to undefined method App\Models\Post::getContent() (View: C:\Users\KHARYA\Desktop\ORCHID\orchid-project\vendor\orchid\platform\resources\views\layouts\table.blade.php)
在应用\Models\Posts.php
class Posts extends Model {use AsMultiSource ...}
你应该使用 Orchid\Screen\AsSource Trait
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Orchid\Screen\AsSource;
class Posts extends Model
{
use HasFactory;
use AsSource;