There is a missing letter
ModelNotFoundExecption() //yours
ModelNotFoundExeception()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All,
I'm following along with the Laravel from scratch tutorials and finding it extremely useful. Challenging at times as I am new to a lot of the languages and tools used (php, laravel, composer, artisan etc). I have installed laravel 9 with php 8.2 on apache 2.4 on an AWS ubuntu AMI. Everything has been working fantastically so far but there has been the odd one or two things that I have had to work my way through doing some reading on. But I have come across an issue that I dont seem to be able to get past.
In Section 3 -> Blade -> "A few tweaks and considerations" jeffrey uses a class called 'ModelNotFoundException" When i try to call this class I get an error -> Class "App\Models\ModelNotFoundException" not found
I am calling the class from a script in app/models called Post.php.
I have added a use statement at the top of that script
use Illuminate\Database\Eloquent\ModelNotFoundException;
I am using two other classes within the same block of code (learned through the tutorial) which work fine.
The File:files class and method and the YamlFrontMatter::parsefiles class and method. Both have been referenced with a similar use statement at the beginning of the code.
use Illuminate\Support\Facades\File;
use Spatie\YamlFrontMatter\YamlFrontMatter;
I have also tried using this ModelNotFoundException class in my web.php routes file and it works fine when I put the use Illuminate\Database\Eloquent\ModelNotFoundException; statement at the top of that file.
<?php
namespace App\Models;
use Illuminate\Support\Facades\File;
use Spatie\YamlFrontMatter\YamlFrontMatter;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class Post {
public $title;
public $excerpt;
public $date;
public $body;
public $slug;
public function __construct($title, $excerpt, $date, $body, $slug)
{
$this->title = $title;
$this->excerpt = $excerpt;
$this->date = $date;
$this->body = $body;
$this->slug = $slug;
}
public static function all()
{
throw new ModelNotFoundExecption();
return cache()->rememberForever('posts.all', function (){
return collect(File::files(resource_path("posts")))
->map(fn($file) => YamlFrontMatter::parsefile($file))
->map(fn($document) => new Post(
$document->title,
$document->excerpt,
$document->date,
$document->body(),
$document->slug
))
->sortByDesc('date');
});
}
public static function find($slug)
{
$post = static::all()->firstWhere('slug', $slug);
return $post;
// if (! $post) {
// throw new ModelNotFoundExecption();
// }
}
}
Any help would be gratefully received I am assuming it has something to do with the namespace as the error is suggesting that App\Models\ModelNotFoundException cannot be found. But of course thats the class namespace I am already in.
There is a missing letter
ModelNotFoundExecption() //yours
ModelNotFoundExeception()
Please or to participate in this conversation.