The message is not displayed because you didn't include it to your blade template. The working solution should be like this:
<img src="\upload\{{$detail->image}}" height="100px" width="100px">
{{$detail->username}}
<br/>
{{$detail->email}}
<br>
@foreach($messages as $message)
{{$message->body}}
@endforeach
<form action="/store/{{$detail->id}}" method="post">
{!!csrf_field()!!}
<input type="text" name="title" class="form-control" placeholder="title" required>
<br/>
<textarea rows="4" cols="4" name="post" class="form-control" placeholder="post" required></textarea>
<br/>
<input type="submit" name="submit" class="btn btn-primary" value="submit">
</form>
Of course change "body" with whatever field you have in messsages table in DB.
EDIT:
You are forwarding same ID to fetch users and their messages.
public function getId($id)
{
$data['detail']=User::find($id) AND $data['messages']=Message::find($id);
return view('new_form',$data);
}
Once you define the right model relationship, you should do something like this:
public function getId($id)
{
$user = User::find($id)
$data['detail']=$user AND $data['messages']=$user->messages()
return view('new_form',$data);
}
Your User.php should have the relationship as Ketav Chotaliya suggested:
public function messages()
{
return $this->hasMany('App\Message');
}
This should work if your message model is called Message.php
, for everything else, rewrite accordingly