title: Laravel 5: Redirect "blog/{id}" to "blog/{slug}" - Trying to get property of non-object error
body: <p>I'm trying to redirect users that go to blog/{id} to blog/{slug} with the slug being the slug of the id they entered.</p>
  
  <p>What I am doing is not working. I dd{$article->slug} and get the correct string, yet when I try to redirect I get "Trying to get property of non-object" error.</p>
  
  <p>I'm using route/model binding. This is my RouteServiceProvider:</p>
  
  <pre><code>    $router-&gt;bind('blog', function($slug)
      {
          if ($slug) {
              if(is_numeric($slug)) {
                  $article = Article::findOrFail($slug);
  
                  return redirect('blog/' . $article-&gt;slug);
              }
  
              return Article::with('images')-&gt;where('slug', $slug)-&gt;first();
          }
      });
  </code></pre>
  
  <p>This is my show method in controller:</p>
  
  <pre><code>public function show(Article $article)
  {
      return view('blog.show', compact('article'));
  }
  </code></pre>
  
  <p>Any ideas would be greatly appreciated!</p>
  
  <p>articles migration file:</p>
  
  <p>
  
  <pre><code>class CreateArticlesTable extends Migration
  {
      public function up()
      {
          Schema::create('articles', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;integer('user_id')-&gt;unsigned();
              $table-&gt;string('title');
              $table-&gt;string('slug');
              $table-&gt;text('body');
              $table-&gt;timestamps();
  
              $table-&gt;foreign('user_id')
                    -&gt;references('id')
                    -&gt;on('users')
                    -&gt;onDelete('cascade');
          });
      }
  
      public function down()
      {
          Schema::drop('articles');
      }
  }
  </code></pre>