У меня есть модель Order
и модель Store
.
Всякий раз, когда я хочу позвонить модели заказа с магазином,
$order = Order::with('store')->first();
Я хочу сменить один из магазиноватрибуты следующим образом.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\OrderPoint;
class Order extends Model
{
public function store()
{
$order_id = $this->id;
$location = OrderPoint::where('order_id', $order_id)->first();
if ($location)
{
// DO something that location value is changed on the
// store
$this->store->location = $location;
}
return $this->belongsTo(Store::class);
}
}
Возможна ли эта модификация?