F
Filament4w ago
L!am

Return Table will not show morphtoselect

In my OrderRelationManager i have a relation to my ProductRevision and ItemList but i can't get it done to show the information on the website. Could someone help me and tell me what i should change to show the information
14 Replies
L!am
L!am4w ago
i know i have to use GitHub Gist for longer scripts but i use gitlab so idk how to use that if more detail is needed just tell me ?? anyone
toeknee
toeknee4w ago
You haven't explained yourself. You say it's not showing right information, but nbot showing what it should show, nore are you showing the resource or the model with it's relationships. you need to provide more detaiuls.
L!am
L!am4w ago
This is the Resource, the thing that needs to show is my 'product_id' (from ProductRevision model) and my 'name' (from ItemList model)
L!am
L!am4w ago
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductRevision extends Model
{
use HasFactory, SoftDeletes;

protected $fillable = [
'revision_number',
'needs_documents',
'product_id',
];

protected $searchableFields = ['*'];

protected $table = 'product_revisions';

protected $casts = [
'needs_documents' => 'boolean',
];

/**
* Get the product of the product revision
*
* @return BelongsTo
*/
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}

/**
* Get the order lines of the product revision
*
* @return HasMany
*/
public function orderLines(): HasMany
{
return $this->hasMany(OrderLine::class);
}

/**
* Get the product prices of the product revision
*
* @return HasMany
*/
public function productPrices(): HasMany
{
return $this->hasMany(ProductPrice::class);
}

public function getLabelAttribute()
{
return "{$this->product->code} - {$this->product->name}";
}

public function getTypeLabelAttribute()
{
return "Product";
}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductRevision extends Model
{
use HasFactory, SoftDeletes;

protected $fillable = [
'revision_number',
'needs_documents',
'product_id',
];

protected $searchableFields = ['*'];

protected $table = 'product_revisions';

protected $casts = [
'needs_documents' => 'boolean',
];

/**
* Get the product of the product revision
*
* @return BelongsTo
*/
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}

/**
* Get the order lines of the product revision
*
* @return HasMany
*/
public function orderLines(): HasMany
{
return $this->hasMany(OrderLine::class);
}

/**
* Get the product prices of the product revision
*
* @return HasMany
*/
public function productPrices(): HasMany
{
return $this->hasMany(ProductPrice::class);
}

public function getLabelAttribute()
{
return "{$this->product->code} - {$this->product->name}";
}

public function getTypeLabelAttribute()
{
return "Product";
}
}
this is my ProductRevision model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ItemList extends Model
{
use HasFactory;

protected $fillable = [
'name',
'product_revision_id'
];

/**
* Get the product items for the product item list.
*
* @return HasMany
*/
public function items(): HasMany
{
return $this->hasMany(Item::class);
}

public function getProductIdAttribute()
{
return $this->productRevision->product_id ?? null;
}

/**
* Get the product revision for the product item list.
*
* @return BelongsTo
*/
public function productRevision(): BelongsTo
{
return $this->belongsTo(ProductRevision::class);
}

public function getLabelAttribute()
{
return $this->name;
}

public function getTypeLabelAttribute()
{
return "Item list";
}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ItemList extends Model
{
use HasFactory;

protected $fillable = [
'name',
'product_revision_id'
];

/**
* Get the product items for the product item list.
*
* @return HasMany
*/
public function items(): HasMany
{
return $this->hasMany(Item::class);
}

public function getProductIdAttribute()
{
return $this->productRevision->product_id ?? null;
}

/**
* Get the product revision for the product item list.
*
* @return BelongsTo
*/
public function productRevision(): BelongsTo
{
return $this->belongsTo(ProductRevision::class);
}

public function getLabelAttribute()
{
return $this->name;
}

public function getTypeLabelAttribute()
{
return "Item list";
}
}
and this is my ItemList model in my OrderRelationManager i am trying to show these 2 lines on the website
MorphToSelect::make('itemable')->label('Create item')
->types([
MorphToSelect\Type::make(ProductRevision::class)->titleAttribute('product_id'),
MorphToSelect\Type::make(ItemList::class)->titleAttribute('name'),
]),
MorphToSelect::make('itemable')->label('Create item')
->types([
MorphToSelect\Type::make(ProductRevision::class)->titleAttribute('product_id'),
MorphToSelect\Type::make(ItemList::class)->titleAttribute('name'),
]),
toeknee
toeknee4w ago
So when you view/edit the order you will see your relation manager at the bottom, do you see any rows of products? If not, then you relationship isn't working.
L!am
L!am4w ago
i do see the rows, this is what i see at the bottom
No description
toeknee
toeknee4w ago
so don't you want productRevision.id ?
L!am
L!am4w ago
yes i do want that i want to call up the 'product_id' from the productrevision model same with itemlist there it is the 'name' but everything i try it will just not show up under the header Product revision and Item list on the website
toeknee
toeknee4w ago
So where code is, I assume that is a product, that is then the product model, to get the productRevisrion you'd call the relationship on the model so that would be: productRevision.product_id ? Being: Product -> Product Revision -> product id
L!am
L!am4w ago
i don't know if the productRevision.product_id line is good i just found something on the internet and was trying it but before that it was just product_id but the same problem not showing up on the website that line is infact not good btw do you know how i could fix this?
toeknee
toeknee4w ago
if you do ->formatState(fn($state, $record) => dump($state) . dump($record)) what happens on the column?/
L!am
L!am4w ago
i get this error when i add that behind the column
TextColumn::make('product_id')->formatState(fn($state, $record) => dump($state) . dump($record)),
TextColumn::make('product_id')->formatState(fn($state, $record) => dump($state) . dump($record)),
No description
L!am
L!am3w ago
i have no clue why that error is there someone pls help 😄
toeknee
toeknee3w ago
try
TextColumn::make('product_id')->formatState(fn($state, $record) => dd($state, $record)),
TextColumn::make('product_id')->formatState(fn($state, $record) => dd($state, $record)),
Want results from more Discord servers?
Add your server
More Posts