title: How I use relationship in blade template (hasOne) || Laravel
body: <p>Okay i'm trying get "likes" and "users" in Posts by relationship hasOne.</p>
  
  <p>here is my <code>Post.php</code> Model
      class Posts extends Model
  {
      protected $table = 'posts';</p>
  
  <pre><code>public function User()
  {
      return $this-&gt;hasOne(User::class, 'id', 'user_id');
  }
  
  public function Like()
  {
      return $this-&gt;hasOne(Like::class, 'post_id', 'id');
  }}
  </code></pre>
  
  <p>My Blade template</p>
  
  <pre><code>@foreach ($showdeals as $deal)
  
  
                                  &lt;div class="tab-pane active" id="home" role="tabpanel"&gt;
                                      &lt;div class="card-body"&gt;
                                          &lt;div class="profiletimeline"&gt;
  
                                              {{$deal-&gt;like-&gt;status}}
                                              &lt;br&gt;
                                              {{$deal-&gt;user-&gt;email}}
  
                          &lt;div class="sl-item"&gt;
                              &lt;div class="sl-left"&gt; &lt;img src=" {{asset( '/assets/images/users/2.jpg')}}" alt="user" class="img-circle"&gt; &lt;/div&gt;
                              &lt;div class="sl-right"&gt;
                                  &lt;div&gt; &lt;a href="#" class="link"&gt;{{$deal-&gt;user-&gt;username}}&lt;/a&gt; || {{$deal-&gt;subject}} &lt;Br&gt; &lt;span class="sl-date"&gt;{{$deal-&gt;created_at}}&lt;/span&gt;
                                      &lt;div class="m-t-20 row"&gt;
                                          &lt;div class="col-md-3 col-xs-12"&gt;&lt;img src="{{$deal-&gt;image}}" alt="user" class="img-responsive radius"&gt;&lt;/div&gt;
                                          &lt;div class="col-md-9 col-xs-12"&gt;
                                              &lt;p&gt; {{$deal-&gt;body}} &lt;/p&gt; &lt;a href="{{$deal-&gt;link}}" class="btn btn-success"&gt; עבור למוצר &lt;/a&gt;&lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="like-comm m-t-20"&gt; &lt;a href="javascript:void(0)" class="link m-r-10"&gt;2 תגובות&lt;/a&gt; &lt;a href="javascript:void(0)" class="link m-r-10"&gt;&lt;i class="fa fa-heart text-danger"&gt;&lt;/i&gt; 5 לייקים&lt;/a&gt; &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
  
  
  
                      &lt;/div&gt;
                      &lt;hr&gt;&lt;/div&gt;
              &lt;/div&gt;
  
                  @endforeach
  </code></pre>
  
  <p>And there is my Controller</p>
  
  <p>class PostsController extends Controller
  {</p>
  
  <pre><code>public function showdeals()
  {
  
      $showdeals = Posts::with( 'User', 'Like')-&gt;get();
          return view('posts.show', compact('showdeals'));
  }
  
  
  
  
  public function helpnewview(){
      return view('posts.anew');
  }
  
  
  public function helpnew(Request $request){
      //User pick link
      $userlink = $request['userlink'];
      return \Redirect::route('newdeal', compact('userlink'));
  }
  
  
  
  public function new(Request $request)
  {
      //Emdeb user link
      $link = Embed::create($request['userlink']);
      $linke = $request['userlink'];
      return view('posts.new', compact('link', 'userlink', 'linke'));
  }
  
  
  
  
  public function create(Request $request)
  {
  
      $posts = New Posts;
      $posts-&gt;user_id = Auth::User()-&gt;id;
      $posts-&gt;subject = $request['subject'];
      $posts-&gt;body = $request['body'];
      $posts-&gt;link = $request['link'];
      $posts-&gt;price = $request['price'];
      $posts-&gt;image = $request['image'];
      $posts-&gt;tag = $request['tag'];
      $posts-&gt;save();
  
      return back();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now if I do something like <code>{{$deal-&gt;user-&gt;email}}</code> its will work,
  if I go to something like this <code>{{$deal-&gt;like-&gt;status}}</code> its does not work,
  am I missing something ?</p>