0

I got three tables called threads,posts,users

threads got

id
title
etc.

posts got

id
thread_id
user_id
post
post_date
etc.

users got

id
username 
password
email
etc.

when users wants to view a thread i simply call a jquery ajax request using post data to send thread id and return this code :

Response::eloquent(Thread::find(Input::get('threadid'))->posts()->get());

this code does his job perfectly and return posts by same thread_id. (post model also eager loads the user by looking user_id).

however this code grabs every attribute of posts and users i mean everything to json, post_date, post_updatereason, user_password, user_email all columns in tables.

I just want to grab post, username and post_date with json

0

2 Answers 2

4

You can add public static $hidden = array('list', 'of', 'fields'); to your model which extends Eloquent. Then none of the fields which you enumarate in the array will be returned. For more information refer to the documentation.

For example

class User extends Eloquent {
  public static $hidden = array('password', 'email');
}

will return the user model without the password and email.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are using laravel 3, and this is probably the same for version 4, you should be able to specific the columns you want using the get method.

Response::eloquent(Thread::find(Input::get('threadid'))->posts()->get(['username','post_date']));

1 Comment

I did that actualy but if I not grab user_id model can't find the author(which eager loads in Post::with('author')). If i put user_id in get() json will show the user_id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.