andreasb's avatar

I think I have a route model binding issue, not sure

Good evening,

I think I have a problem with Facades or method injection and/or form or route model binding but I am not sure :-)

Now, I am at the stage in Jeff's Laravel 5.1 intro where we introduce many-to-many relationships. Then we added the multiple select and cleaned up the code (see https://laracasts.com/series/laravel-5-fundamentals/episodes/23 6:11)

Now ONE thing I notices was that his methods looked a bit different:

public function show(Article $article){
        
        return view('articles.show', compact('article'));
        
    }

Now, my code used to look like this

public function show($id){

        $article= Article::findOrFail($id);
        
        return view('articles.show', compact('article'));
        
    }

Now - everything worked until I changed my code from above to similar like Jeff has it in his videos.

Then I thought it must be the routes! Mine looks like this:

Route::resource('articles', 'ArticlesController');

which php artisan route:list acknowledges.

Now when I dd($article) in my blade-file, it actualy dumps an instance of the object but I am not sure whether it is empty or not?

The top of my ArticlesController looks like this:

<?php

namespace App\Http\Controllers;

use App\Article;
use App\Http\Requests;
use App\Http\Requests\ArticleRequest;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Laracasts\Flash\Flash;

So no request facades, right?

I think there must be something obvious what I don't see, but what is it?

Thank you Andreas

0 likes
1 reply

Please or to participate in this conversation.