Welcome Guest, Not a member yet? Register   Sign In
Model with Entity (return type)
#1

(This post was last modified: 07-05-2022, 01:19 AM by ozornick.)

Hello. The model returns a stdClass for the returnType. I would like to have a hint as User class. Is it really possible to do this?


PHP Code:
    protected $returnType = \App\Models\Entity\User::class;

    public function findLast(): stdClass // I have User this
    {
        return $this->builder()
            ->orderBy('id DESC')
            ->get(1)->getRow();
    
Reply
#2

->getFirstRow($this->returnType); instead of ->getRow();
Reply
#3

(07-05-2022, 07:58 AM)iRedds Wrote: ->getFirstRow($this->returnType); instead of ->getRow();
Yes, I know that there is such a possibility. Thought I should automatically determine the entity. For find() findAll() only works. Thus, only the model knows about the class

PHP Code:
    protected $returnType = \App\Models\Entity\Settings::class;

    public function findLast(): ?Settings
    
{
        return $this->builder()
            ->orderBy('id DESC')
            ->get(1)->getCustomRowObject(0$this->returnType);
    
Reply




Theme © iAndrew 2016 - Forum software by © MyBB