I'm not sure if I understand your question, but what do you mean by "write the code of model" ?
Can you show us some code?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to write the code of model in a blade file . But how can possible to write? I have post.blade.php file where i showing all post . But i need to show the post contents (.pdf,.doc,.ppt etc) where these files are staying other table . I want to show these contents which are corresponding of individual post . For this , i'm checking these content by a model in the post.blade.php file . But its seem to wrong . How can solve the problem ?
@najmulcse First of all you can't do queries in your view.
If I understand correctly your Content can have a foreign key to a Post right?
If so, in your Post.php you should have a relation like this:
public function content() {
return $this->hasOne(Post::class);
}
and in your view
<p>{{ $post->body }}</p>
@if($post->content)
{{$post->content->content}}
@endif
Please or to participate in this conversation.