I develop a forum module for a web site IN LARAVEL 8, I face the problem of Undefined property: AppModelsThread::$title, since 3 days I look for the solution but in vain.
Here is the code of my model
<?php
namespace AppModels;
use AppTraitsHasAuthor;
use AppTraitsHasTags;
use IlluminateDatabaseEloquentBuilder;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentRelationsBelongsTo;
use IlluminateSupportStr;
class Thread extends Model
{
use HasTags;
use HasAuthor;
use HasFactory;
const TABLE = 'threads';
protected $table = self::TABLE;
protected $fillable = [
'title',
'body',
'slug',
'writer_id',
'category_id',
];
protected $with = [
'category',
'writer',
'tags',];
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function excerpt(int $limit = 250): string
{
return Str::limit(strip_tags($this->body()), $limit);
}
public function id(): int
{
return $this->id;
}
public function title(): string
{
return $this->title;
}
public function body(): string
{
return $this->body;
}
public function slug(): string
{
return $this->slug;
}
public function delete()
{
$this->removeTags();
parent::delete();
}
public function scopeForTag(Builder $query, string $tag): Builder
{
return $query->whereHas('tagsRelation', function ($query) use ($tag) {
$query->where('tags.slug', $tag);
});
}
code of my Controller that displays the details of the post (show)
public function show(Category $category, Thread $thread)
{
return view('pages.threads.show', compact('thread', 'category'));
}
the different fragments of the views
-
Index
@foreach($threads as $thread) <article class="post post-medium"> <div class="row mb-3"> <div class="col-lg-5"> <div class="post-image thumb-info-wrapper border-radius-0"> <a href="blog-post.html"> <img src="{{asset('assets/frontend//img/blog/medium/blog-11.jpg')}}" class="img-fluid img-thumbnail img-thumbnail-no-borders rounded-0" style="width: 100px;height:100px" alt="" /> </a> </div> </div> <div class="col-lg-7"> <div class="post-content"> <h2 class="font-weight-semibold pt-4 pt-lg-0 text-5 line-height-4 mb-2"><a href="{{ route('forums.show', [$thread->category->slug(), $thread->slug()]) }}"> {{ $thread->title() }}</a></h2> <p class="mb-0"> {{ $thread->excerpt() }}[...]</p> </div> </div> </div> <div class="row"> <div class="col"> <div class="post-meta"> <span class="appear-animation" data-appear-animation="flash" data-appear-animation-delay="0" data-appear-animation-duration="1s"><i class="far fa-calendar-alt"></i> {{ $thread->created_at->diffForHumans() }}</span> <span><i class="far fa-user"></i> By <a href="#">{{$thread->author()->name}}</a> </span> <span><i class="far fa-folder"></i> <a href="#">Lifestyle</a>, <a href="#">Design</a> </span> <span><i class="far fa-comments"></i> <a href="#">12 Comments</a></span> <a href="javascript:void(0)" class="text-muted d-inline-flex align-items-center align-middle" data-abc="true"> <i class="fa fa-heart fa-spin text-danger"></i> <span class="align-middle">445</span> </a> <span class="text-muted d-inline-flex align-items-center align-middle ml-4"> <i class="fa fa-eye text-muted fsize-3"></i> <span class="align-middle">14532</span> </span> <span class="text-muted d-inline-flex align-items-center align-middle ml-4"> <i class="fa fa-comments text-muted fsize-3"></i> <span class="align-middle">14532</span> </span> <span class="d-block d-sm-inline-block float-sm-right mt-3 mt-sm-0"><a href="{{ route('forums.show', [$thread->category->slug(), $thread->slug()]) }}" class="btn btn-xs btn-light text-1 text-uppercase">Read More</a></span> </div> </div> </div> </article> @endforeach
*show
@extends('layouts.guest')
@section('title', 'forum')
@push('css')
@endpush
@section('content')
<section class="page-header page-header-modern bg-color-light-scale-1 page-header-md">
<div class="container">
<div class="row">
<div class="col-md-12 align-self-center p-static order-2 text-center">
<h1 class="text-dark font-weight-bold text-8">Medium Image Right Sidebar</h1>
<span class="sub-title text-dark">Check out our Latest News!</span>
</div>
<div class="col-md-12 align-self-center order-1">
<ul class="breadcrumb d-block text-center">
<li><a href="{{route('home')}}">Home</a></li>
<li><a href="{{route('forums.index')}}">Forum</a></li>
<li><a href="#">{{ $category->name() }}</a></li>
<li class="active">{{ $thread->title() }}</li>
</ul>
</div>
</div>
</div>
</section>
<div class="container-fluid mt-100">
<div class="row">
<div class="col-md-12">
<div class="card mb-4">
<div class="card-header">
<div class="media flex-wrap w-100 align-items-center"> <img src="https://i.imgur.com/iNmBizf.jpg" class="d-block ui-w-40 rounded-circle" alt="">
<div class="media-body ml-5"> <a href="javascript:void(0)" data-abc="true">Tom Harry</a>
<div class="text-muted small">13 days ago</div>
</div>
<div class="text-muted small ml-3">
<div>Member since <strong>01/1/2019</strong></div>
<div><strong>134</strong> posts</div>
</div>
</div>
</div>
<div class="card-body">
<p>{!! $thread->body() !!}</p>
</div>
<div class="card-footer d-flex flex-wrap justify-content-between align-items-center px-0 pt-0 pb-3">
<div class="px-4 pt-3">
<a href="javascript:void(0)" class="text-muted d-inline-flex align-items-center align-middle" data-abc="true">
<i class="fa fa-heart fa-spin text-danger"></i> <span class="align-middle">445</span> </a>
<span class="text-muted d-inline-flex align-items-center align-middle ml-4">
<i class="fa fa-eye text-muted fsize-3"></i> <span class="align-middle">14532</span> </span>
<span class="text-muted d-inline-flex align-items-center align-middle ml-4">
<i class="fa fa-comments text-muted fsize-3"></i> <span class="align-middle">14532</span>
</span>
</div>
<div class="px-4 pt-3"> <button type="button" class="btn btn-primary"><i class="ion ion-md-create"></i> Reply</button> </div>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('js')
@endpush
thank you for your help