我的路线
Route::get('news-logs', 'Backend\ChangeLog\ChangeLogController@changeLogNews')->name('change-log-news');
我的模特
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class News extends Model
{
protected $table = 'news';
use \Venturecraft\Revisionable\RevisionableTrait;
protected $revisionCreationsEnabled = true;
protected $revisionEnabled = true;
public static function boot()
{
parent::boot();
}
public function revisionHistory(){
$news = News::all();
$history = $news->revisionHistory;
}
public function getRouteKeyName()
{
return 'slug';
}
public function months($year) {
$queryResult = DB::table('news')->select(DB::raw('MONTH(order_date) as month'), DB::raw('YEAR(order_date) as year'))->where(DB::raw('YEAR(order_date)'), $year)->orderBy(DB::raw('MONTH(order_date)'))->get();
$months = collect($queryResult)->unique('month');
return $months;
}
}
我的控制器
<?php
namespace App\Http\Controllers\Backend\ChangeLog;
use App\Models\News;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ChangeLogController extends Controller
{
public function changeLogNews(){
$news = News::all();
$history = $news->revisionHistory;
dd($history);
return view('backend.change-log.history',compact('history'));
}
}
我的观点
@foreach($history->revisionHistory as $log )
<li>
{{ $log->userResponsible()->name }} changed {{ $log->fieldName() }} from {{ $log->oldValue() }} to {{ $log->newValue() }}</li>
@endforeach
现在,当我加载页面时,它会显示 - “此集合实例上不存在属性 [revisionHistory]”。我想从你这边得到任何帮助。谢谢你