嗨,我正在尝试从数据库中分页数据,我得到了下面的错误。
“调用未定义方法App\Material::link() (View: C:\xampp\htdocs\project104\resources\views\swapview.blade.php)”)
我不知道我在哪里搞错了,我试着改变变量,但仍然有一个错误。
下面是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Material;
class SwapViewController extends Controller
{
public function index()
{
return view('swapview');
}
public function show()
{
$inf = Material::paginate(4);
$info = Material::orderBy('created_at', 'DESC')->get();
return view('swapview',['info'=>$info]);
}
}以下是我的看法
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
@foreach($info as $inf)
<div style="background-color:#162238; color:white;" class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4">
<img
src="{{asset('images/' . $inf->imogi)}}"
alt="Trendy Pants and Shoes"
/>
</div>
<div class="col-md-8">
<div class="card-body">
<div style="text-align: right;">
<i style="color:#3490dc" class="fa fa-building-o" style="font-size:24px"></i> <small>{{$inf->organazation}}</small> <small><i class="fa fa-calendar" style="color:#3490dc" aria-hidden="true"></i> {{ $inf->created_at->format('d/m/Y') }}</small>
</div>
<br/>
<!--LIVEWIRE online status-->
@if($inf->isOnline())
<small><div class="circle"></div></small> <small style="color:#22bb33;">operative</small>
@else
<small><div class="ocircle"></div></small> <small>inoperative</small>
@endif
<h5 class="card-title"><i class="fa fa-user-circle-o" style="color:#3490dc" aria-hidden="true"></i> {{$inf->name}}</h5>
<small style="color:#3490dc;"><i class="fa fa-clock-o" style="color:#3490dc;"></i></small> <small style="color:#3490dc;"> posted {{ \Carbon\Carbon::parse($inf->created_at)->diffForHumans() }}</small><br/>
<small><i class="fa fa-map-marker" style="color:#3490dc" aria-hidden="true"></i> {{$inf->location}}</small> | <small><i class="fa fa-phone" style="color:#3490dc" aria-hidden="true"></i>{{$inf->contact}}</small>
<hr color=3490dc>
<p class="card-text">
<small><small style="color:#3490dc;"><i class="fa fa-exchange" aria-hidden="true"></i></small> {{$inf->swap}}</small>
</p>
<hr color=3490dc>
<p class="card-text">
<small><small style="color:#3490dc;"><i class="fa fa-exchange" style="font-size:10px"></i></small> {{$inf->exchange}}</small>
</p>
</div>
</div>
</div>
<a style="color:red;" href="{{ route('report') }}"><i class="fa fa-flag" style="color:red;" aria-hidden="true"></i> <small style="color:#3490dc;">Report</small></a>
</div>
<br/>
@endforeach
{{ $inf->links() }}
</div>
</div>
</div>
@include('footer')
@endsection我会感谢您的帮助,谢谢
发布于 2022-09-22 18:18:08
在您的控制器中,这是您的显示方法:
public function show()
{
$inf = Material::paginate(4);
$info = Material::orderBy('created_at', 'DESC')->get();
return view('swapview',['info'=>$info]);
}因此,在返回时,将$info变量发送到视图,但不发送$inf。
然后,在您的视图中,您使用的是$info as $inf,因此您的$inf变量是一个材料项,而不是您在控制器中获得的分页材料项。所以,当你使用$inf->links()时,Laravel不能给你一些分页链接.因为您不在分页元素上。
似乎在变量命名方面存在一些混淆。
https://stackoverflow.com/questions/73761221
复制相似问题