Call to undefined method firstOrFail
- 0
Hi,
I’m getting this error with Laravel when I try to access a page on my blog.
Call to undefined method IlluminateDatabaseQueryBuilder::firstOrFail()
This is the query I changed:
$category = DB::table('blog_post_categories')->where('slug', $slug)->firstOrFail();
What am I doing wrong?
Answers
- 0
You cannot use the firstOrFail method with the query builder. You need to use it with Eloquent model.
Try this
$category = BlogCategory::where('slug', $slug)->firstOrFail();
Change the model name if I didn’t get it right.