And your route?
Route::get('/blog/tag/{tag}', 'TagsController@index')->name('blogs.showbyTag');
Route wildcard should match with argument from your function
public function index(Tag $tag)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Source: https://laravel.com/docs/5.8/routing#route-model-binding
I was trying laravel from scratch ep 30 and 31 and found jeffery doing implicit binding of route but when i tried i get null result. why so ?
Tag model :
class Tag extends Model
{
public function articles()
{
return $this->belongsToMany(Article::class);
}
public function getRouteKeyName()
{
return 'name';
}
}
Tag Controller
use App\Tag;
use Illuminate\Http\Request;
class TagsController extends Controller
{
public function index(Tag $tag)
{
return $tag;
}
}
Route
Route::get('/blog/tag/{name}', 'TagsController@index')->name('blogs.showbyTag');
whats wrong in my code ?
it should be
$records = $tag->articles()->paginate();
Please or to participate in this conversation.