spatie/laravel-model-status

Nova Field

Paulsky opened this issue · 8 comments

Hello,

Thank you for this great package! I would like to use the statuses in a Nova field for my model. I'm not sure how to implement this. I have tried the 'morph fields' but I can't seem to render the field.

Thank you in advance!

Hey Guys,
I created a little Workaround for this with a nova Action (https://nova.laravel.com/docs/1.0/actions/defining-actions.html):

  • Create Action with Nova php artisan nova:action YOUR_ACTION_NAME
  • Use Select Field to determine which Status to set (Can be done in the fields section)
  • Update Status for all Models selected with the action

Here is my Code for the Action:

<?php
namespace App\Nova\Actions;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Select;

class setStatus extends Action
{
    use InteractsWithQueue, Queueable;

    public function handle(ActionFields $fields, Collection $models)
    {
        foreach ($models as $model) {

            // The normal function to set the Status
            $model->setStatus($fields->status);
        }
    }

    public function fields()
    {
        return [
            Select::make('Status')->options([
                'created' => 'DRAFT',
                'published' => 'READY FOR SUBMISSION',
            ])->displayUsingLabels()
        ];
    }
}

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

Please reopen this issue

I'm also interested

Here is what I did.

In Nova Resource,
`

        Text::make(__('Status'), function ($model) {
            return Str::ucfirst($this->status);
        }),

         Select::make(__('Status'), 'sel_status')
            ->options([
                'new' => 'New',
                'approved' => 'Approved'
            ])
            ->withMeta(['value' => Str::lower($this->status)])
            ->onlyOnForms()
            ->displayUsingLabels(),

`

In the Model

`

   static::saving(function ($model) {

        $model->setStatus($model->sel_status);

        unset($model->sel_status);

    });

`