2 years ago

Using ->with()

Posted 2 years ago by freshface


I have the following code Project::with(['content'])->paginate(25)

With the following result:

    "meta": [],
    "data": [
            "id": 4,
            "cover_image": {
                "filename": null
            "launched_at": "2017-07-18 09:36:42",
            "created_at": "2017-07-18 09:36:42",
            "updated_at": null,
            "content": {
                "project_id": 4,
                "name": "Qui adipisci esse.",
                "description_website": "<p>Voluptatem ut illum dolore.</p>",
                "location": "Pennsylvania",
                "language": "en"

But I want content on the same level as id, launched_at... I can do this with a manual left join but I want to use it the hasOne... Now I am using this in my model to perform this:

#In ProductModel.php

public function content()
        return $this->hasOne('App\Api\V1\Models\ProjectContent');

Any suggestions?

Please sign in or create an account to participate in this conversation.