1
votes

I am getting above error while requesting to next page but I want posts title is as page title as well

@extends('layouts.app')

@section('pageTitle', $post->title)

@section('content')
    <a href="{{ url('posts') }}" class="btn btn-outline-secondary">Go Back</a>
    <br> <br>
    <h1>{{ $post->title }}</h1>
    <div class="">
      <p>{!! $post->body !!}</p>
    </div>
    <hr>
    <small>Written on: {{ $post->created_at }}</small>
    <hr>
    <a href="/posts/edit" class="btn btn-outline-primary">Edit</a>
@endsection
  public function show($id)
    {
        $post = Post::find($id);
        return view('posts.show')->with('post', $post);
    }
1
Welcome to SO ... can you provide the controller that returns this view so we can see how you are acquiring the data you are passing to it?lagbox
use like {{$post['title']}}A.A Noman
are you sent the $post variable in your controller to your view?Amir Mohsen
@lagbox yes I have edited and added the controllerJay Jadhav
@AmirMohsen Yes now I have ProvidedJay Jadhav

1 Answers

1
votes

Post::find(...) can return null. You will have to make sure that you are actually receiving a model instance, the record exists, before trying to use it. You can use something like Post::findOrFail(...) to allow this to fail when it doesn't find a record. This would allow you to continue in the code knowing $post will be a valid instance.