title: Laravel show blade - Trying to get property '"' of non-object
body: <p>Afternoon,</p>
  <p>I am trying to show a team from my league using teams.show.blade but I keep receiving an error &quot;trying to get property 'displayName' of non-object&quot;. I have tried every permutation of code to try and show the data to no gain. Any assistance would be appreciated.</p>
  <p>I would like the URL to be domain.com/league/{ID}/team/{abbrName}</p>
  <p>Route is as domain.com/league/1/team/MIA for Miami and so on</p>
  <p>I have got the code sorted until I would like to show the individual team shown from my teams.index.blade.</p>
  <p><strong>Section of teams.show.blade</strong></p>
  <pre><code>@extends('layouts.home')
  @section('content')
  
  &lt;div class=&quot;page-heading&quot; style=&quot;background-image:url('/images/teams/banners/{{$team-&gt;displayName}}.jpg');&quot;&gt;
  &lt;div class=&quot;container&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
  &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;
  &lt;h1 class=&quot;page-heading__title&quot;&gt;{{$team-&gt;cityName}} {{$team-&gt;displayName}}&lt;span class=&quot;highlight&quot;&gt; Overview&lt;/span&gt;&lt;/h1&gt;
  &lt;ol class=&quot;page-heading__breadcrumb breadcrumb&quot;&gt;
  &lt;li class=&quot;breadcrumb-item&quot;&gt;&lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;li class=&quot;breadcrumb-item&quot;&gt;&lt;a href=&quot;/leagues&quot;&gt;League&lt;/a&gt;&lt;/li&gt;
  &lt;li class=&quot;breadcrumb-item&quot;&gt;&lt;a href=&quot;/leagues/{{$team-&gt;leagueId}}/teams&quot;&gt;Teams&lt;/a&gt;&lt;/li&gt;
  &lt;li class=&quot;breadcrumb-item active&quot; aria-current=&quot;page&quot; style=&quot;color:#ffffff;&quot;&gt;{{$team-&gt;displayName}} 
  &lt;/li&gt;
  &lt;/ol&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>The setup is as follows including code</p>
  <p><strong>web.php</strong></p>
  <pre><code>Route::get('/leagues',['uses'=&gt;'LeaguesController@index', 'as'=&gt;'leagues']);
  Route::get('/league/{league}',['uses'=&gt;'LeaguesController@show', 'as'=&gt;'leagues.show']);
  
  Route::get('/league/{league}/teams',['uses'=&gt;'TeamsController@index', 'as'=&gt;'teams']);
  Route::get('/league/{league}/team/{team}',['uses'=&gt;'TeamsController@show', 'as'=&gt;'teams.show']);
  </code></pre>
  <p><strong>TeamsController</strong></p>
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Models\Team;
  use App\Models\League;
  
  class TeamsController extends Controller
  {
  
  function index(League $league){
      $teams = $league-&gt;team;
      return view('teams.index', compact('league','teams'));
  }
  
  public function show($abbrName){
      $team = Team::find($abbrName);
      return view('teams.show')-&gt;with('team', $team);
  }}
  </code></pre>
  <p><strong>Team Model</strong></p>
  <pre><code>namespace app\Models;
  use Illuminate\Database\Eloquent\Model;
  
  
  class Team extends Model
  {
  
  /**
   * The database table used by the model.
   *
   * @var string
   */
  protected $table = 'teaminfo';
  public $primaryKey = 'teamId';
  
  /**
   * Indicates if the model should be timestamped.
   *
   * @var bool
   */
  public $timestamps = false;
  
  /**
   * The attributes that are not mass assignable.
   *
   * @var array
   */
  protected $guarded = [];
  
  /**
   * The attributes that are hidden.
   *
   * @var array
   */
  protected $hidden = [];
  
  
  /**
   * Fillable fields for a Profile.
   *
   * @var array
   */
  protected $fillable = [
      'teamId',
      'abbrName',
      'cityName',
      'displayName',
      'divName',
      'offScheme',
      'defScheme',
      'ovrRating',
      'injuryCount',
      'primaryColor',
      'secondaryColor',
      'userName',
  ];
  
  /**
   * The attributes that should be cast to native types.
   *
   * @var array
   */
  protected $casts = [
      'teamId'            =&gt; 'integer',
      'abbrName'          =&gt; 'string',
      'cityName'          =&gt; 'string',
      'displayName'       =&gt; 'string',
      'divName'           =&gt; 'string',
      'offScheme'         =&gt; 'string',
      'defScheme'         =&gt; 'string',
      'ovrRating'         =&gt; 'string',
      'injuryCount'       =&gt; 'string',
      'primaryColor'      =&gt; 'string',
      'secondaryColor'    =&gt; 'string',
      'userName'          =&gt; 'string',
  ];
  
      /**
   * Get the profiles for the league.
   */
  public function profile()
  {
      return $this-&gt;hasMany('App\Models\Profile');
  }
  public function league()
  {
      return $this-&gt;belongsTo('App\Models\League');
  }}
  </code></pre>