Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to resolve the sender to the User model? #3

Closed
MaxAIPlayground opened this issue Jun 14, 2014 · 2 comments
Closed

How to resolve the sender to the User model? #3

MaxAIPlayground opened this issue Jun 14, 2014 · 2 comments

Comments

@MaxAIPlayground
Copy link

So, I'm fetching a message via

$conversations = $this->messages->getUserConversations($user_id)->first();
$message = $conversations->getLastMessage();

Result:

object(Tzookb\TBMsg\Entities\Message)[323]
  protected 'id' => int 5
  protected 'sender' => int 50
  protected 'status' => int 1
  protected 'self' => int 0
  protected 'content' => string 'dfsdfsd' (length=7)
  protected 'created' => string '2014-06-14 22:52:25' (length=19)

Now, in my template I'd do something like

<div class="author">{{ $message->sender }}</div>

It's not possible, since all properties on the object are protected. I assume this is still a bug, right?

@tzookb
Copy link
Owner

tzookb commented Jun 14, 2014

the package doesnt return the users any more....

Ill show you how I use it in my controller:

the package now only returns the id of the users,
so it is your responsibilty to fetch them.

As you would see in my controller, I get the messages, than I fetch the
users.

In the view I would do something like this:

$users[ $msg->getSender() ]->username

public function conversation($conv_id) {
$currentUser = Auth::user();
/** @var \Tzookb\TBMsg\Entities\Conversation $conv */
$conv = TBMsg::getConversationMessages($conv_id, $currentUser->id);
TBMsg::markReadAllMessagesInConversation($conv_id,
$currentUser->id);

    $participants = $conv->getAllParticipants();

    //getting all data of participants
    if ( !empty($participants) ) {
        $users = User::whereIn('id',

$participants)->with('profileImage')->get();
foreach ( $users as $key=>$user ) {
$users[ $user->id ] = $user;
}
} else {
$users = [];
}

    return View::make('messages/conv')
        ->with('user', $currentUser)
        ->with('users', $users)
        ->with('conv_id', $conv_id)
        ->with('conv', $conv);
}

On Sun, Jun 15, 2014 at 12:26 AM, nockedout notifications@github.com
wrote:

So, I'm fetching a message via

$conversations = $this->messages->getUserConversations($user_id)->first();$message = $conversations->getLastMessage();

Result:

object(Tzookb\TBMsg\Entities\Message)[323]
protected 'id' => int 5
protected 'sender' => int 50
protected 'status' => int 1
protected 'self' => int 0
protected 'content' => string 'dfsdfsd' (length=7)
protected 'created' => string '2014-06-14 22:52:25' (length=19)

Now, in my template I'd do something like

{{ $message->sender }}

It's not possible, since all properties on the object are protected. I
assume this is still a bug, right?


Reply to this email directly or view it on GitHub
#3.

Tzook Bar Noy

"Life is what happens while you are busy making other plans"

Phone: +972.52.4625353

Email: tzookb@gmail.com

@MaxAIPlayground
Copy link
Author

Okay, I understand now. Thanks for your demonstration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants