F
Filament2mo ago
L!am

Call to undefined method App\Models\OrderLine::orderLines()

when i want to edit a order on my website i get this error i don't get directed to the edit page and same as for making one i get the error but it does make a order i don't know how to fix it so i can edit it
15 Replies
L!am
L!am2mo ago
this is my OrderLineResource
L!am
L!am2mo ago
and this is my OrderLine Model
Dennis Koch
Dennis Koch2mo ago
I can’t read your code because I’m on mobile and you decided to upload some txt files, but you probably didn’t specify the relation correctly
L!am
L!am2mo ago
yeah the text was to long and i don't have nitro so i needed to sent it in txt i just can't find where the relation is not good because in a other script that is working i almost have the same as that script
Sujal Tamrakar
Sujal Tamrakar2mo ago
Can you post your OrderLinesRelationManager::class ?
Dennis Koch
Dennis Koch2mo ago
Or you could have shared a Gist as mentioned in #✅┊rules
L!am
L!am2mo ago
Sujal Tamrakar
Sujal Tamrakar2mo ago
You don't have a relationship named 'orderLines' in your model. Change the relationship in your OrderLinesRelationManager protected static string $relationship = 'orderLines';
L!am
L!am2mo ago
to what should i change it?
Dennis Koch
Dennis Koch2mo ago
To the actual name of that relationship you want to use. What’s the relationship called on the Order model?
L!am
L!am2mo ago
i have multiple relations to scripts this is my order model
Dennis Koch
Dennis Koch2mo ago
Sorry it’s not really readable because you don’t use code formatting 🤷🏼‍♂️ See #✅┊rules
L!am
L!am2mo ago
<?php

namespace App\Models;

use App\Traits\HasNumber;
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 Order extends Model
{
use HasFactory, HasNumber;

protected $fillable = [
'order_category_id',
'customer_id',
'order_type_id',
'internal_order',
'flow_id',
'name',
'description',
'status',
'status_flow',
'external_reference_number',
'template',
'number',
'code',
'sales_price',
'budget_cost_price',
'expected_cost_price',
'cost_price',
'delivery_date',
'expected_delivery_date',
'planned_delivery_date',
'parent_order_id',
'follow_up_order_id',
];

protected $casts = [
'flow_data' => 'array',
];

protected $searchableFields = ['*'];

protected static function boot()
{
parent::boot();

// static::saving(function (Order $model) {
// if($model->isDirty('flow_id')){
// $flow = Flow::where('id', $model->flow_id)->with('steps')->first();
// $model->flow_data = $flow ? $flow->toArray() : null;
// }
// });
}

/**
* Get the third party of the order
*
* @return BelongsTo
*/
public function thirdParty(): BelongsTo
{
return $this->belongsTo(ThirdParty::class);
}
<?php

namespace App\Models;

use App\Traits\HasNumber;
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 Order extends Model
{
use HasFactory, HasNumber;

protected $fillable = [
'order_category_id',
'customer_id',
'order_type_id',
'internal_order',
'flow_id',
'name',
'description',
'status',
'status_flow',
'external_reference_number',
'template',
'number',
'code',
'sales_price',
'budget_cost_price',
'expected_cost_price',
'cost_price',
'delivery_date',
'expected_delivery_date',
'planned_delivery_date',
'parent_order_id',
'follow_up_order_id',
];

protected $casts = [
'flow_data' => 'array',
];

protected $searchableFields = ['*'];

protected static function boot()
{
parent::boot();

// static::saving(function (Order $model) {
// if($model->isDirty('flow_id')){
// $flow = Flow::where('id', $model->flow_id)->with('steps')->first();
// $model->flow_data = $flow ? $flow->toArray() : null;
// }
// });
}

/**
* Get the third party of the order
*
* @return BelongsTo
*/
public function thirdParty(): BelongsTo
{
return $this->belongsTo(ThirdParty::class);
}

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

/**
* Get the customer of the order
*
* @return BelongsTo
*/
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}

public function customerWithTrashed(): BelongsTo
{
return $this->customer()->withTrashed();
}

/**
* Get the order category of the order
*
* @return BelongsTo
*/
public function orderCategory(): BelongsTo
{
return $this->belongsTo(OrderCategory::class);
}

public function flow()
{
return $this->belongsTo(Flow::class);
}

// public function flowSteps()
// {
// return $this->hasMany(FlowStep::class);
// }

public function getCurrentFlowEventStep()
{
return $this->flowEvents()->orderByDesc('flow_step_id')->first();
}


public function orderTypes(): HasOne
{
return $this->hasOne(OrderType::class);
}

}

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

/**
* Get the customer of the order
*
* @return BelongsTo
*/
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}

public function customerWithTrashed(): BelongsTo
{
return $this->customer()->withTrashed();
}

/**
* Get the order category of the order
*
* @return BelongsTo
*/
public function orderCategory(): BelongsTo
{
return $this->belongsTo(OrderCategory::class);
}

public function flow()
{
return $this->belongsTo(Flow::class);
}

// public function flowSteps()
// {
// return $this->hasMany(FlowStep::class);
// }

public function getCurrentFlowEventStep()
{
return $this->flowEvents()->orderByDesc('flow_step_id')->first();
}


public function orderTypes(): HasOne
{
return $this->hasOne(OrderType::class);
}

}
i don't know how to make a github git because school already made a branch in gitlab
Dennis Koch
Dennis Koch2mo ago
So it’s not the wrong relation but the relation manager is using the OrderLine model instead of Order model. You can just swap the model on the RM
L!am
L!am2mo ago
theres no way i was looking for that for so long 😭 pff crazy how 1 word can take so much time to find 🤣 but atleast thanks for the help! 😄
Want results from more Discord servers?
Add your server
More Posts