面临的问题:方法Illuminate \ Database \ Query \ Builder :: links不存在

Hey everyone I was creating a laravel project and I wanted to add the pagination but I faced this error :

Method Illuminate\Database\Query\Builder::links does not exist. (View: C:\xampp\htdocs\TestingTaskesources\views\income\index.blade.php)

Here is the controller code:

public function index()
    {

        $income =Income::orderBy('created_at','desc')->paginate(1);
        return view('income.index', compact('income'));

    }

The view code:

@extends('layouts.app')
@section('content')
<h3>Profit</h3>
<br>
@if(count($income)>0)
@foreach($income as $income)
    <div class="card bg-muted">
    <h3><a href="/income/{{$income->id}}">{{$income->title}}</a></h3>
    </div>
@endforeach
    {{$income->links()}}
@else
<p>No result</p>

@endif
@stop

You have a typo in your code. change $income to $inc.

@extends('layouts.app')
@section('content')
<h3>Profit</h3>
<br>
@if(count($income)>0)
@foreach($income as $inc)
    <div class="card bg-muted">
    <h3><a href="/income/{{$inc->id}}">{{$inc->title}}</a></h3>
    </div>
@endforeach
    {{$income->links()}}
@else
<p>No result</p>

@endif
@stop

This is because of your foreach loop variable kindly change as following

@if(count($income)>0)
@foreach($income as $income_single)
...
@endforeach
    {{$income->links()}}
@else