I have a set of code, it is similar to the other codes that I'm using and they are working fine. Just in this case there is some mysterious issue which I'm not able to find the cause of. Please see the code below
BlogPostController.php
public function category(Category $category){
return view('blog/cat')->with('categories',$category);
}
categories.blade.php
@extends('layouts.blog')
{{$categories->name}}
The category.blade
does not output {{$categories->name}}
. No errors are shown. If I change the {{$categories->name}}
and type normal text e.g data
, then data
is printed on the webpage . I even tried restarting my system. There is no way out.
The I removed the Model Route Binding, and tried the usual way ,
public function category($id){
$category = Category::where('id',$id)->first();
return view('blog/cat')->with('categories',$category);
}
EDIT ROUTE - web.php
Route::get('blog/category/{cat}','BlogPostController@category')->name('blog.category');
In this case the category.blade.php
prints the data properly.
What could be the issue with the Model Route Binding in this case. All my controllers use Model Route Binding rather than the usual way, but this is the first time I'm stumbling upon this issue.