【问题标题】:Call to undefined method error when I try to use links()当我尝试使用 links() 时调用未定义的方法错误
【发布时间】:2020-03-26 01:33:24
【问题描述】:

当我尝试使用 $student->links() 时,我看到了这个错误:

Facade\Ignition\Exceptions\ViewException 调用未定义的方法 App\Student::links()

我检查了控制器、型号等,但它们似乎都正常...我该如何解决这个问题?

(我在我的 Macbook 和 VPS -CentOS7- 上都尝试过此代码,但出现同样的问题)

我的那部分观点是这样的:

      </tr>
            @endforeach
           </tbody>
         </table>
            {{ $student->links() }}
         </div>
       @endsection

【问题讨论】:

  • 如果你想使用 'links()' 你应该 'paginate()' 你的 '$student' 变量...请发布控制器

标签: php laravel hyperlink centos


【解决方案1】:

改变

{{ $student->links() }}

{{ $students->links() }}

(使用复数形式)。

【讨论】:

    【解决方案2】:
      public function index(){
            $students = Student::paginate(2);
            return view('welcome', compact('students'));
        }
    

    我有它(分页)但同样的问题:)

    【讨论】:

    • 你能上传最小的源代码来重现这个问题吗?
    【解决方案3】:

    您需要在后端代码中进行分页。 $students = App\Student::paginate(15);

    然后你就可以访问links()

    <div class="container">
        @foreach ($students as $student)
            {{ $student->name }}
        @endforeach
    </div>
    
    {{ $students->links() }}
    

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      • 2014-11-08
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      相关资源
      最近更新 更多