GithubHelp home page GithubHelp logo

Nova Field about laravel-model-status HOT 8 CLOSED

spatie avatar spatie commented on May 14, 2024 6
Nova Field

from laravel-model-status.

Comments (8)

d0utone avatar d0utone commented on May 14, 2024 1

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()
        ];
    }
}

from laravel-model-status.

SuhaibKotb avatar SuhaibKotb commented on May 14, 2024

+1

from laravel-model-status.

dennissvu avatar dennissvu commented on May 14, 2024

+2

from laravel-model-status.

 avatar commented on May 14, 2024

+3

from laravel-model-status.

spatie-bot avatar spatie-bot commented on May 14, 2024

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.

from laravel-model-status.

Paulsky avatar Paulsky commented on May 14, 2024

Please reopen this issue

from laravel-model-status.

ImJustToNy avatar ImJustToNy commented on May 14, 2024

I'm also interested

from laravel-model-status.

iamoat avatar iamoat commented on May 14, 2024

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);

    });

`

from laravel-model-status.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.