title: Get brand name, instead of ID - Laravel 5.8
body: <p>Good someone can help me, I am not doing it well. I have a table called products, in it a field called <code>brand_id</code>, then I have a table called brands, in which I list it by its <code>ID</code> field, this table also contains a column called nombre.</p>
  
  <p><strong>Model producto</strong></p>
  
  <pre><code>class Producto extends Model
  {
      protected $table = 'productos';
  
      public function marcas()
      {
          return $this-&gt;belongsTo(Marca::class , 'id');
      }
  }
  </code></pre>
  
  <p><strong>Model Marca</strong></p>
  
  <p>class Marca extends Model</p>
  
  <pre><code>{
      protected $table = 'marcas';
  
      public function producto()
      {
          return $this-&gt;hasMany(Producto::class , 'id_brand');
      }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <p>public $categorias, $productos, $ofertados;</p>
  
  <pre><code>public function __construct()
  {
      $this-&gt;productos = Producto::with('marcas')
                  -&gt;latest('id')
                  -&gt;limit(6)
                  -&gt;whereEstado(1)
                  -&gt;get();            
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>@foreach ($productos as $pro)    
     &lt;div class="col-4 catProduct"&gt;
        &lt;div class="col-12 bordeCajon"&gt;
            @if ($pro-&gt;novedad == 1)
               &lt;div class="nEntrada"&gt;NOVEDAD&lt;/div&gt; 
            @endif
  
            @if ($pro-&gt;pvpAntes == null)     
            @else
              &lt;div class="oferta"&gt;OFERTA!&lt;/div&gt;
            @endif   
            &lt;div class="minHei"&gt;
               &lt;img src="{{ asset("{$pro-&gt;imagen}") }}" alt=""&gt;
            &lt;/div&gt;
            &lt;div class="paddingProducto"&gt;
               @php
                  /** echo "&lt;pre&gt;"; print_r($pro-&gt;marcas);*/
               @endphp
  
               &lt;h2&gt; {{ $pro-&gt;marcas-&gt;mombre }} &lt;/h2&gt;
               &lt;h3&gt;{{ $pro-&gt;producto }}&lt;/h3&gt;
               &lt;div class="dividerProd"&gt;&lt;/div&gt;
               &lt;h4&gt;{{ $pro-&gt;pvpAhora }} &lt;span&gt;€&lt;/span&gt;&lt;/h4&gt;
  
               @if ($pro-&gt;pvpAntes == null)     
               @else
               &lt;div class="pvpAntes"&gt;{{ $pro-&gt;pvpAntes }} &lt;span&gt;€&lt;/span&gt;&lt;/div&gt;
                @endif 
               &lt;a href="{{ route('web.detalle', ['cat' =&gt; $pro-&gt;categoria, 'sub' =&gt; $pro-&gt;subcategoria, 'url' =&gt; $pro-&gt;url]) }}" class="btn btn-primary btnForm pull-right"&gt;VER PRODUCTO&lt;/a&gt;
             &lt;/div&gt;
         &lt;/div&gt;
     &lt;/div&gt;
  @endforeach
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>Trying to get property 'nombre' of non-object (View: /Applications/MAMP/htdocs/camasLiteras/resources/views/index.blade.php
  </code></pre>
  
  <p>For example, in the marks table I have 4 marks. In the beginning I have 6 products each with a brand. Well it does what we have done is take the product and put the name of the brand in the same order of the brand table, that is, it does not put the name that it touches. And since there are 6 products but only 4 brands, that's why it says the 'name' of no-object '. If I deactivate two products it doesn't give me an error but it shows in each product a different brand, putting the 4 there are.</p>