I am trying to creating a blog post with Laravel using views (blog.blade.php) inside HTML.
The code in my laravel web.php fetches the blog posts from my local mssql server looks as follow (and works):
Route::get('/blog/{id}', function($id){
$posts = DB::table('blog_posts')->get();
return view('blog', ['id'=>$id], ['posts'=>$posts]); });
In the laravel views dir home.blade.php my code works with hardcoded route: url('/blog/1') The href link takes you to the full blog post
<h2>Blog posts:</h2>
@foreach ($posts as $post)
<p>{{ $post->title }} </p> <a href="{{ url('/blog/1') }}" >▲ Click here to view full post</a>
@endforeach
What I am trying to do is:
<p>{{ $post->title }} </p> <a href="{{ url('/blog/{{ $post->id }}') }}" >▲ Click here to view full post</a>
How do I get the $post->id that is the route (1, 2, 3 or 4) and comes from the sql data base saved to the blog row to work. I get the following error returned from my xampp php server when using {{ $post->id }} instead of hardcoding "1" .
D:\XAMPP Server\htdocs\cool-blog
ParseError Unclosed '(' does not match '}' (View: D:\XAMPP Server\htdocs\cool-blog\resources\views\home.blade.php) http://localhost:8000/