Reputation: 23
I am a complete newb trying to teach myself the laravel framework. I have a little PHP experience from a past life and am just trying to learn a new skill set. I am def not a developer by trade.
I am trying to complete a tutorial on routes.
In my web.php file I have this
Route::get('/test/{post}', function($post) {
$posts = [
'my-first-post' => 'Hello, this is my first blog post!',
'my-second-post' => 'Now I am getting the hang of this blogging thing',
'test' => 'test'
];
if (! array_key_exists($post, $posts)) {
abort(404, 'Sorry, that post was not found');
}
return view('post', [
'post' => $posts[$post]
]);
});
In my blade file I have this
<!DOCTYPE HTML>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
This is a test
</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
</head>
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md">
this is a test
{{$post}}
</div>
</div>
</div>
</body>
</html>
When I refresh the page with the following URL http://127.0.0.1:8000/test/test
I get the following error
InvalidArgumentException View [post] not found.
Am i doing something silly?
Upvotes: 0
Views: 116
Reputation: 675
Through the exception it seems that the view 'post' does not exist.
Please make sure that post.blade.php exists in project_root/resources/views/post.blade.php
For further details please refer to this link: https://laravel.com/docs/7.x/views#creating-views
Upvotes: 1