【问题标题】:Method Illuminate\Database\Eloquent\Collection::appends does not exist方法 Illuminate\Database\Eloquent\Collection::appends 不存在
【发布时间】:2019-11-12 11:38:50
【问题描述】:

这是我用的

 {{ $joburi->appends(\Request::except('page'))->render() }}

这是我的控制器

<?php

namespace App\Http\Controllers\Auth;

use Auth;
use App\Models\Joburi;
use App\Models\SkillsEmployee;
use App\Models\ProfileEmployee;
use App\Models\ProfileEmployer;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class JoburiController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function index()
    {
        {
            $joburi = Joburi::where('activ', 1)->limit(15)->get();
            $skill = SkillsEmployee::all();
            $employerimage = ProfileEmployer::where('uid', Auth::user()->id)->first();
            $profileimage = ProfileEmployee::where('uid', Auth::user()->id)->first();
            return view('joburiactive', compact('joburi', 'skill', 'employerimage', 'profileimage'));
        }
    }

在其他控制器上工作没有问题

有人知道我为什么会收到这个错误吗?

【问题讨论】:

  • 你能显示你在另一个控制器中定义$joburi 的位置吗? appends 是分页类的一部分,而您只是在这里获得 15 个对象的常规集合。
  • 我发现了问题,我必须使用$joburi = Joburi::where('activ', 1)-&gt;sortable()-&gt;paginate(5);
  • 因为在你的$joburi变量赋值中使用的get方法返回一个Collection

标签: php laravel laravel-5 eloquent


【解决方案1】:

您在 $joburi 查询上调用的 get() 方法返回一个集合,而不是一条记录。也许您应该尝试first() 或其他一些不返回集合的方法。或者您应该找到一种不同的方式来处理集合,以使其符合您的要求。

【讨论】:

    猜你喜欢
    • 2015-12-20
    • 2020-11-21
    • 2021-09-08
    • 2020-11-13
    • 2019-12-11
    • 2020-02-04
    • 2019-05-24
    • 2019-09-04
    • 1970-01-01
    相关资源
    最近更新 更多