-1

i am a beginner in laravel and i need to do this : i have a "mgs" table and is this table i have "user_sender" & "user_reciver" so , how i get informations of this users from "users" table ?

and please correct me this code :

$read_msg_user = DB::table('mdg')
                            ->where('user_sender', '=', $id)
                            ->where('vue', '=', 0)
                            ->join('users', 'messages.user_sender', '=', 'users.id')->get();

thank's

  • 1
    Have you tried implementing this is Eloquent (Laravel's ORM), it would certainly make this easier for you. :) – Anthony Sterling Feb 24 '14 at 13:41
  • help me to do it please – Nassimweb15 Feb 24 '14 at 13:58
  • It's quite a large task, but I'd suggest reading this (http://stackoverflow.com/questions/19326950/define-laravel-eloquent-relations-between-3-models-in-a-messaging-system) SO post and the Eloquent docs at http://laravel.com/docs/eloquent. – Anthony Sterling Feb 24 '14 at 14:03
  • Learning PHP, Laravel, Eloquent, as easy as it seems to an expert; to a beginner, it is certainly not easy. Especially if it is a quite a large task. @Nassim: while it will not be of immediate help with your task, it will be good to go over a tutorial that uses Laravel with Eloquent, and maybe find some good webcasts aimed towards beginners. – Dennis Feb 24 '14 at 14:31

1 Answers1

0

I think you should use mdg instead of messages in your join. mdg.user_sender like this.

DB::table('mdg')
                        ->where('user_sender', '=', $id)
                        ->where('vue', '=', 0)
                        ->join('users', 'mdg.user_sender', '=', 'users.id')->get();
Jimmie Johansson
  • 1,875
  • 1
  • 19
  • 39