Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addresses()
- {
- return $this->belongsToMany('Address');
- }
- public function user(){
- return $this->hasOne('User');
- }
- public function profile($id){
- if($id != Auth::user()->id){
- return Redirect::to('logout');
- }
- $user=User::find(Auth::user()->id);
- $address = $user->addresse;
- dd($address);
- $comments = Comment::where('user_id','=',Auth::user()->id)
- ->take(10)->get();
- return View::make('users.profile')
- ->with(array('comments'=>$comments,'address'=>$address));
- }
- public function profil($id){
- ......
- $user=Auth::user();
- // this will bring users all related addresses as an array.
- //so you can loop through and use them.
- $adress = $user->adresses;
- ..........
- }
- public function address(){
- return $this->belongsTo("Address");
- }
- public function user(){
- return $this->hasOne("User");
- }
- public function profil($id){
- ......
- $user=Auth::user();
- $adress = $user->adress;
- // will give you a single address record belongs to user.
- ..........
- }
- public function addresses()
- {
- return $this>belongsToMany('address_id','Address');
- }
- $address = $user->Address->address(name of the row with the address);
Add Comment
Please, Sign In to add comment