Y
Y
yellow_pus2022-03-20 12:28:41
Laravel
yellow_pus, 2022-03-20 12:28:41

What eloquent request can be made for a default field?

Here I have a field, in laravel nova, inside an article: Text::make(__('Field'), 'thing')How can I set it to a default value from the same article, but from a different, previously entered field? I know it can be done like this:

Text::make(__('Field'), 'thing')->default(function ($request){
            return DB::table('thing')->orderBy('id', 'desc')->first()->count;
        }),

But in this case, retun returns the last entry, from the count column, but I need a query that would also return the count entry, but of the article that is currently open.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2022-03-21
@yellow_pus

As part of the description of the fields, you have access $thisthat refers to the model of the current object.
If countthis is just a field for the model, then it should work$this->count

Text::make(__('Field'), 'thing')->default(function ($request){
    return $this->count;
}),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question