首页 > 解决方案 > App 的返回值必须是实例 Laravel 错误

问题描述

我有文件上传器,当其到期日期大于或等于今天的日期时,我想显示已过期而不是下载链接

它是我的模型:

class Panelfile extends Model
{

protected $guarded = [];

public function
getLinkAttribute()
{
    return
    $this->isExpired() ? null :
    $this->file;
}

public function
isExpired() : boolean
{
   return Carbon::now()->gte($this->expiration);
}

protected $appends = ["link"];

protected $casts = [
    'expiration' =>
    'datatime:Y-m-d H:i:s',
];
}

及其我的观点:

@foreach($filepanels as $filepanel)
            
            <div class="widget-download-file d-flex align-items-center justify-content-between mb-4">
                <div class="d-flex align-items-center mr-3">
                    <div class="download-file-icon mr-3" style="background-color: {{$filepanel->color}};">

                        <img src="{{$filepanel->png}}" alt="">

                    </div>
                    <div class="user-text-table">
                        <h6 class="d-inline-block font-15 mb-0">{{$filepanel->title}}</h6>
                        <p class="mb-0">{{$filepanel->description}}</p>
                    </div>
                </div>

               @if ($filepanel->link === null)
                <p>Expired</p>
@else
    <a href="{{$filepanel->file}}" class="download-link badge badge-primary badge-pill">دانلود</a>
                @endif

            </div>
                @endforeach

这是我的错误:

Return value of App\Panelfile::isExpired() must be an instance of phpDocumentor\Reflection\Types\Boolean, bool returned (View: C:\wamp64\www\site\resources\views\back\filesview\view.blade.php)

我该如何解决?

标签: laraveleloquentlaravel-8laravel-6php-carbon

解决方案


推荐阅读