Answers for "model access in view laravel"

PHP
4

laravel load view in variable

$html = view('users.edit', compact('user'))->render();
Posted by: Guest on October-07-2020
0

laravel view-model

class PostViewModel extends ViewModel
{
    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();
    }
}
Posted by: Guest on March-07-2021
4

laravel load view in variable

$html = view('users.edit', compact('user'))->render();
Posted by: Guest on October-07-2020
0

laravel view-model

class PostViewModel extends ViewModel
{
    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();
    }
}
Posted by: Guest on March-07-2021

Code answers related to "model access in view laravel"

Browse Popular Code Answers by Language