mardi 31 juillet 2018

Laravel | Get value of a column with

i am having a problem with laravel, all the details are given below.

I Have 2 tables in mysql database : books & pens.

books & pens have columns : bookid,bookname & penid,penname, respectively.

Users have a transactions table with : bookid or penid.

I am retrieving all the transactions of a specific user with this:

$usertransactions = $user->usertransactions;

Not to worry about the relationships between user and usertransaction model, its all setup.

the response of the function above is:

"data": {

    "Id": "1",
    "Bookid": "27",

}

or

"data": {

    "Id": "2",
    "Penid": "42",

}

I want the result to be like below:

"data": {

    "Id": "1",
    "Bookid": "27",
    "Bookname" : "bookname from books table using the Bookid from response"

}

I Would appreciate the help.

Regards



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire