F
Filament4w ago
MZX

Error when viewing a record.

The sites admin panel has been recently moved from Nova to Filament. For one of the Resources, when I click on a record. I get thrown with this error. foreach() argument must be of type array|object, string given
3 Replies
neverything
neverything4w ago
Can you provide more info, the code of the resource form for example and any customizations you might have done to the Edit<ResourceName> class.
MZX
MZX4w ago
No changes to the edit class
class Product extends Model implements Sortable, HasMedia, Buyable
{
use SoftDeletes, HasFactory, SortableTrait, HasTranslations, InteractsWithMedia, DefaultImage, BelongsToThrough, UnicodeJsonColumn;

protected $guarded = ['id'];

public $translatable = ['name', 'temp_name', 'desc', 'short_desc', 'search_keywords', 'meta_title', 'meta_keywords', 'meta_desc', 'canonical'];

/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['image_url', 'delivery', 'contacts'];

protected $casts = [
'shipping_prices' => 'array'
];
class Product extends Model implements Sortable, HasMedia, Buyable
{
use SoftDeletes, HasFactory, SortableTrait, HasTranslations, InteractsWithMedia, DefaultImage, BelongsToThrough, UnicodeJsonColumn;

protected $guarded = ['id'];

public $translatable = ['name', 'temp_name', 'desc', 'short_desc', 'search_keywords', 'meta_title', 'meta_keywords', 'meta_desc', 'canonical'];

/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['image_url', 'delivery', 'contacts'];

protected $casts = [
'shipping_prices' => 'array'
];
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('Info')
->schema([

Select::make('category')
->relationship('category', 'name'),

Select::make('vendor')
->relationship('vendor', 'name'),

TextInput::make('name'),

Select::make('tags')
->relationship('tags', 'name')
->multiple(),

Textarea::make('short_desc')
->rules(NULLABLE_TEXT_VALIDATION)
->translatable(),

Textarea::make('desc')
->rules(REQUIRED_TEXT_VALIDATION)
->translatable(),

Select::make('type')->options([
'product' => 'Product',
'service' => 'Service'
]),

Select::make('unit')
->relationship('unit', 'name'),

TextInput::make('youmats_moq')
->minValue(0)
->default(2)
->rules(REQUIRED_INTEGER_VALIDATION),

TextInput::make('min_quantity')
->minValue(2)
->rules(REQUIRED_INTEGER_VALIDATION),
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('Info')
->schema([

Select::make('category')
->relationship('category', 'name'),

Select::make('vendor')
->relationship('vendor', 'name'),

TextInput::make('name'),

Select::make('tags')
->relationship('tags', 'name')
->multiple(),

Textarea::make('short_desc')
->rules(NULLABLE_TEXT_VALIDATION)
->translatable(),

Textarea::make('desc')
->rules(REQUIRED_TEXT_VALIDATION)
->translatable(),

Select::make('type')->options([
'product' => 'Product',
'service' => 'Service'
]),

Select::make('unit')
->relationship('unit', 'name'),

TextInput::make('youmats_moq')
->minValue(0)
->default(2)
->rules(REQUIRED_INTEGER_VALIDATION),

TextInput::make('min_quantity')
->minValue(2)
->rules(REQUIRED_INTEGER_VALIDATION),
TextInput::make('sku')
->rules(NULLABLE_STRING_VALIDATION)
->default(\Illuminate\Support\Str::sku('yt', '-')),

RatingStar::make('rate'),

Toggle::make('active'),

Toggle::make('best_seller'),

Select::make('attributes')
->relationship('attributes', 'value'),

Fields::image(false, PRODUCT_PATH, 'images', false)

]),

Fields::Stores(),

Section::make('Search Keywords')
->description('Instructions: Set every keyword in one line')
->schema([
Textarea::make('Search Keywords')
->rules(NULLABLE_TEXT_VALIDATION)
->translatable()
]),


Fields::SEO(static::$model, 'products', false, true),

]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')->sortable(),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('category.name'),
Tables\Columns\TextColumn::make('vendor.name'),
Tables\Columns\ToggleColumn::make('active'),
Tables\Columns\TextColumn::make('slug')->label('Link')

])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
TextInput::make('sku')
->rules(NULLABLE_STRING_VALIDATION)
->default(\Illuminate\Support\Str::sku('yt', '-')),

RatingStar::make('rate'),

Toggle::make('active'),

Toggle::make('best_seller'),

Select::make('attributes')
->relationship('attributes', 'value'),

Fields::image(false, PRODUCT_PATH, 'images', false)

]),

Fields::Stores(),

Section::make('Search Keywords')
->description('Instructions: Set every keyword in one line')
->schema([
Textarea::make('Search Keywords')
->rules(NULLABLE_TEXT_VALIDATION)
->translatable()
]),


Fields::SEO(static::$model, 'products', false, true),

]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')->sortable(),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('category.name'),
Tables\Columns\TextColumn::make('vendor.name'),
Tables\Columns\ToggleColumn::make('active'),
Tables\Columns\TextColumn::make('slug')->label('Link')

])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
Dennis Koch
Dennis Koch4w ago
Please share the Flare error as mentioned in #✅┊rules