调用未定义函数App \ Http \ Controllers \ appends()

时间:2018-07-05 01:54:50

标签: laravel

我想在分页中使用追加,但是这样的错误

Call to undefined function App\Http\Controllers\appends()

。 这是我的控制器...

  public function index(InstrumentType $instrumentType)
{ 
    $query = "";

    if(request('serial_number')){
        $query = request('serial_number');
    }

    $instruments =  Instrument::where('instrument_type_id', $instrumentType->id)->where('serial_number', 'like', '%'.$query.'%')->paginate(5);
    $instruments = appends($request->query());
    return view('settinginstrument.index', compact('instrumentType', 'instruments'));
}

1 个答案:

答案 0 :(得分:2)

使用

$instruments->appends($request->query());

代替

appends($request->query());

尝试:

public function index(Request $request, InstrumentType $instrumentType)
{ 
    $query = "";

    if(request('serial_number')){
        $query = request('serial_number');
    }

    $instruments =  Instrument::where('instrument_type_id', $instrumentType->id)->where('serial_number', 'like', '%'.$query.'%')->paginate(5);
    $instruments = $instruments->appends($request->query());
    return view('settinginstrument.index', compact('instrumentType', 'instruments'));
}

有关更多信息,请检查:https://laravel.com/docs/5.6/pagination#displaying-pagination-results