Laravel + Vue return data with more than one relation

Laravel + Vue return data with more than one relation

I have a model called Exercise, that belongs to Topic, and a Topic belongs to a Subject.

I have a model called Exercise, that belongs to Topic, and a Topic belongs to a Subject.

With

Exercise::with('topic')->get()

I can access properties from the current topic of the exercise inside Vue. What can I do to return also the data from the subject that the topic that my exercise belongs to?

If I was able to use just blade template, I would just call:

{{$exercise->topic->subject->name}}

But the thing is that I'm passing everything as a json to work with the data in a datatable with vue.

One solution is to also pass Subject::all to my view, and use the subject_id inside the exercise>topic with vue:

@{{subjects[exercise.topic.subject_id].name}}

I'm looking for a better and cleaner solution than that. Is there a Laravel method, like multiple with's with multiple relations? Something like:

Exercise::with('topic')->and('topic')->with('subject')->get()

Thank you!

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top Vue.js Developers in USA

Vue.js is an extensively popular JavaScript framework with which you can create powerful as well as interactive interfaces. Vue.js is the best framework when it comes to building a single web and mobile apps.

Inertia.js for Laravel & Vue - Server Driven Single Page Apps

We take a look at the basics of Inertia.js and build out a simple CRUD application in Laravel and Vue. What is Inertia.js? Inertia is a library that combines the best of both server-side rendering (SSR) and client-side rendering (CSR) by allowing developers to build SPAs using server-side routing and controllers.

10 Best Vue Icon Component For Your Vue.js App

In this article, I will collect 10 Vue icon component to bring more interactivity, better UI design to your Vue application.