1 回答
TA贡献2003条经验 获得超2个赞
好吧没关系,我修好了。我只是想在这里发布答案,以防有人也被它困住。问题是我的路线,而不是使用resource我手动添加的路线:
Route::get('ledger', 'LedgerController@index')->name('ledger.index')->middleware('auth');
Route::post('/ledger', 'LedgerController@store')->name('ledger.store')->middleware('auth');
Route::delete('/ledger/{id}', 'LedgerController@destroy')->name('ledger.destroy')->middleware('auth');
Route::get('/ledger/fetch', 'LedgerController@index')->name('ledger.fetch')->middleware('auth');
我还编辑了我的代码index(),因此将它与fetch()方法结合起来,因此它现在看起来像这样:
public function index(Request $request)
{
$disableLedger = true;
$ledgers = Ledger::orderBy('id', 'DESC')
->where('user_id', auth()->user()->id)
->paginate(10);
$ledgerCatType = DB::table('ledgers')
->orderBy('ledgers.id', 'DESC')
->join('categories', 'ledgers.cat_id', '=', 'categories.id')
->where('ledgers.user_id', auth()->user()->id)
->select('categories.type')
->paginate(10);
$categories = Category::where('user_id', auth()->user()->id)->get();
if ($request->ajax())
{
return view('ledgers.entries', compact('ledgers', 'categories', 'ledgerCatType', 'disableLedger'))->render();
}
return view('ledgers.index', compact('ledgers', 'categories', 'ledgerCatType', 'disableLedger'));
}
- 1 回答
- 0 关注
- 124 浏览
添加回答
举报