i would like to display latest order status name from database but i have a problem with displaying data. Here is my code:
OrderController
class OrderController extends Controller
{
public function index()
{
$orders = Order::with('shippingAddress', 'billingAddress', 'carrier', 'payment', 'status')->limit(300)->orderBy('id', 'DESC')->get();
}
}
OrderModel (cutted)
public function status()
{
return $this->hasMany('App\Ss\Models\OrderHistory','id_order', 'id')
->orderBy('date_add', 'DESC')
->limit(1)
->with('statusLanguage');
}
OrderHistory model
class OrderHistory extends Model
{
protected $table="order_history";
public $timestamps = false;
public function statusLanguage(){
return $this->hasOne('App\Ss\Models\StatusLanguage', 'id_status', 'id_status');
}
}
How i tried to display:
{{ $order->status()->statusLanguage()->name ?? 'No status' }}
{{ $order->status()->statusLanguage->name ?? 'No status' }}
{{ $order->status->statusLanguage->name ?? 'No status' }}
Each time result was error like "Property [statusLanguage] does not exist on this collection instance." or similar.
When i try to dd($order->status) it show returned relation with data what i needed:
So where is mistake?