Closed Brand3000 closed 11 months ago
I have some question. Hope it get fixed as soon as possible.
@Johan-An @Brand3000 can u show your composer.json and model config (sortable level)? i make blank project with nova-sortable and nova-switcher and i dont have a problem.
composer.json:
{
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/nova": "^4.24",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"outl1ne/nova-sortable": "^3.4",
"spatie/eloquent-sortable": "^4.0",
"trin4ik/nova-switcher": "^0.3.0"
}
}
Models/User.php:
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\EloquentSortable\SortableTrait;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
use SortableTrait;
public $sortable = [
'order_column_name' => 'order_column',
'sort_when_creating' => true,
];
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
Nova/User.php
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Illuminate\Validation\Rules;
use Laravel\Nova\Fields\Gravatar;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Password;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Outl1ne\NovaSortable\Traits\HasSortableRows;
use Trin4ik\NovaSwitcher\NovaSwitcher;
class User extends Resource
{
use HasSortableRows;
/**
* The model the resource corresponds to.
*
* @var class-string<\App\Models\User>
*/
public static $model = \App\Models\User::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'name';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id', 'name', 'email',
];
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields (NovaRequest $request)
{
return [
ID::make()->sortable(),
Gravatar::make()->maxWidth(50),
Text::make('Name')
->sortable()
->rules('required', 'max:255'),
Text::make('Email')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),
Password::make('Password')
->onlyOnForms()
->creationRules('required', Rules\Password::defaults())
->updateRules('nullable', Rules\Password::defaults()),
NovaSwitcher::make('Active', 'disabled')
->reverse()
];
}
/**
* Get the cards available for the request.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function cards (NovaRequest $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function filters (NovaRequest $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function lenses (NovaRequest $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function actions (NovaRequest $request)
{
return [];
}
}
You change checkboxes for both records in your movie, and it doesn't help to see the problem. On the index page change a checkbox only for one record to see different statuses and it will do the trick
composer.json { "require": { "php": "^8.1", "laravel/framework": "^10.10", "laravel/nova": "^4.0", "mobilenowgroup/laravel-dingding-notification": "^1.0", "mobilenowgroup/laravel-nova-preview-component-package": "^1.0", "outl1ne/nova-sortable": "^3.4", "stepanenko3/nova-command-runner": "^4.2", "trin4ik/nova-switcher": "^0.3.0", } }
@Johan-An I don't understand what this has to do with switcher. What version is your nova?
@Johan-An I don't understand what this has to do with switcher. What version is your nova?
FYI: app/Models/FaqSubject.php
<?php
namespace App\Models;
use App\Models\Traits\PublishAble;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
class FaqSubject extends Model implements Sortable
{
use HasFactory, PublishAble, SortableTrait;
const HORSE_RIDING_CATE_SLUG = 'horse_riding';
const FOOTBALL_CATE_SLUG = 'football';
const MULTI_SPORTS_CATE_SLUG = 'multi_sports';
/**
* @var array
*/
public $sortable = [
'order_column_name' => 'sort',
'sort_when_creating' => false,
'nova_order_by' => 'ASC',
];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function faqs()
{
return $this->hasMany(Faq::class);
}
/**
* @return array
*/
public static function getCateSlug()
{
return [
self::HORSE_RIDING_CATE_SLUG => __('Horse Riding'),
self::FOOTBALL_CATE_SLUG => __('Football'),
self::MULTI_SPORTS_CATE_SLUG => __('Multi Sports'),
];
}
public function scopeFilterForApi(Builder $query)
{
$query->has('faqs')->with('faqs');
if ($cate = request()->input('cate_slug')) {
return $query->where('cate_slug', $cate);
}
return $query;
}
}
app/Nova/FaqSubject.php
<?php
namespace App\Nova;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Outl1ne\NovaSortable\Traits\HasSortableManyToManyRows;
use Outl1ne\NovaSortable\Traits\HasSortableRows;
use Trin4ik\NovaSwitcher\NovaSwitcher;
class FaqSubject extends Resource
{
use HasSortableManyToManyRows, HasSortableRows;
/**
* The model the resource corresponds to.
*
* @var class-string<\App\Models\FaqSubject>
*/
public static $model = \App\Models\FaqSubject::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'title';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id',
'title',
];
/**
* Get the fields displayed by the resource.
*
* @return array
*/
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),
Text::make(__('Theme'), 'title')
->rules('required'),
Select::make(__('Category'), 'cate_slug')
->rules('required')
->displayUsingLabels()
->filterable()
->options(\App\Models\FaqSubject::getCateSlug()),
NovaSwitcher::make(__('Published'), 'status'),
HasMany::make(__('Faq'), 'faqs', Faq::class),
];
}
/**
* Get the cards available for the request.
*
* @return array
*/
public function cards(NovaRequest $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @return array
*/
public function filters(NovaRequest $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @return array
*/
public function lenses(NovaRequest $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @return array
*/
public function actions(NovaRequest $request)
{
return [];
}
/**
* Get the displayable label of the resource.
*
* @return string
*/
public static function label()
{
return __('Themes');
}
/**
* Get the displayable singular label of the resource.
*
* @return string
*/
public static function singularLabel()
{
return __('theme');
}
}
@Johan-An i still ok (( Can you publish small laravel project with minimal functionality, where hava this bug? I want to help, but I can't see the problem.
Sure. Please refer to this: https://github.com/Johan-An/laravel10
@Johan-An i think, problem with nova version. I don't have any other ideas. try to find 4.28 trial
I'm starting a new project and I've already installed and everything seems to be working fine without amendments.
@Brand3000 TY @Johan-An I have installed 4.28 and everything is fine. I think the problem is with your version of nova. I see that you have a different refresh animation.
I'm closing this task, but i`m ready to help if we clarify the data
@Brand3000 TY @Johan-An I have installed 4.28 and everything is fine. I think the problem is with your version of nova. I see that you have a different refresh animation.
I'm closing this task, but i`m ready to help if we clarify the data
I'll try to upgrade the nova version next. Thanks for your time sincerely.
Hi! I use your package in conjunction with https://github.com/outl1ne/nova-sortable and it doesn't work properly. If you try this package, you will see the problem. I have fixed it by adding this.value = this.field.value; in the label method. If you have time and agree with my correction. it'd be great to fix that in your package. Thanks.