0

My Route

Route::get('news-logs', 'Backend\ChangeLog\ChangeLogController@changeLogNews')->name('change-log-news');

My Model

    <?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;
    }
}

My Controller

    <?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'));
    }
}

My View

    @foreach($history->revisionHistory as $log )
         <li>
{{ $log->userResponsible()->name }} changed {{ $log->fieldName() }} from {{ $log->oldValue() }} to {{ $log->newValue() }}</li>
    @endforeach

Now When ever I load the page, it says - "Property [revisionHistory] does not exist on this collection instance". I would like to get any help form your side. Thank You

aryan
  • 11
  • 1
  • 5

1 Answers1

0

The $history doesn't have a revisionHistory property. The $history is the result of $news->revisionHistory.

waldrumpus
  • 2,540
  • 18
  • 44