Guest User

Untitled

a guest
Dec 16th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public function addresses()
  2. {
  3. return $this->belongsToMany('Address');
  4. }
  5.  
  6. public function user(){
  7. return $this->hasOne('User');
  8. }
  9.  
  10. public function profile($id){
  11. if($id != Auth::user()->id){
  12. return Redirect::to('logout');
  13. }
  14. $user=User::find(Auth::user()->id);
  15. $address = $user->addresse;
  16. dd($address);
  17. $comments = Comment::where('user_id','=',Auth::user()->id)
  18. ->take(10)->get();
  19.  
  20. return View::make('users.profile')
  21. ->with(array('comments'=>$comments,'address'=>$address));
  22. }
  23.  
  24. public function profil($id){
  25. ......
  26. $user=Auth::user();
  27. // this will bring users all related addresses as an array.
  28. //so you can loop through and use them.
  29.  
  30. $adress = $user->adresses;
  31.  
  32. ..........
  33. }
  34.  
  35. public function address(){
  36. return $this->belongsTo("Address");
  37. }
  38.  
  39. public function user(){
  40. return $this->hasOne("User");
  41. }
  42.  
  43. public function profil($id){
  44. ......
  45. $user=Auth::user();
  46. $adress = $user->adress;
  47. // will give you a single address record belongs to user.
  48.  
  49. ..........
  50. }
  51.  
  52. public function addresses()
  53. {
  54. return $this>belongsToMany('address_id','Address');
  55. }
  56.  
  57. $address = $user->Address->address(name of the row with the address);
Add Comment
Please, Sign In to add comment