在 Laravel 中查看模型
我们投入了大量资源来创建 一流的 开源 包。您可以通过购买我们的付费产品来支持我们[https://spatie.be/open-source/support-us]。
class PostViewModel extends ViewModel
{
public $user;
public $post;
public $indexUrl = null;
public function __construct(User $user, Post $post = null)
{
$this->user = $user;
$this->post = $post;
$this->indexUrl = action([PostsController::class, 'index']);
}
public function post(): Post
{
return $this->post ?? new Post();
}
public function categories(): Collection
{
return Category::canBeUsedBy($this->user)->get();
}
}然后,您可以使用视图 m
暂无开放 Issues,或尚未同步最近议题。