在这里需要帮助,我正在使用Laravel应用,我的问题是我的数据不会显示在桌子上。我尝试了一些方法来显示我的数据,但是它不起作用。 这是我的代码。
<tbody>
@if (count($expenses) > 0)
@foreach ($expenses as $expense)
<tr data-entry-id="{{ $expense->id }}">
<td field-key='expense_category'>{{ $expense->expense_category->name or '' }}</td>
<td field-key='entry_date'>{{ $expense->entry_date }}</td>
<td field-key='amount'>{{ $expense->amount }}</td>
<td field-key='created_by'>{{ $expense->created_by->name or '' }}</td>
<td>
@can('view')
<a href="{{ route('expenses.show',[$expense->id]) }}" class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>
@endcan
@can('edit')
<a href="{{ route('expenses.edit',[$expense->id]) }}" class="btn btn-xs btn-info">@lang('quickadmin.qa_edit')</a>
@endcan
@can('delete')
{!! Form::open(array(
'style' => 'display: inline-block;',
'method' => 'DELETE',
'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
'route' => ['expenses.destroy', $expense->id])) !!}
{!! Form::submit(trans('quickadmin.qa_delete'), array('class' => 'btn btn-xs btn-danger')) !!}
{!! Form::close() !!}
@endcan
</td>
</tr>
@endforeach
@else
<tr>
<td colspan="9">@lang('quickadmin.qa_no_entries_in_table')</td>
</tr>
@endif
</tbody>
这是我的ExpenseController。 但是我从来没有碰过这段代码,我总是在表格上工作。
class ExpensesController extends Controller
{
/**
* Display a listing of Expense.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
if (! Gate::allows('expense_access')) {
return abort(401);
}
if ($filterBy = Input::get('filter')) {
if ($filterBy == 'all') {
Session::put('Expense.filter', 'all');
} elseif ($filterBy == 'my') {
Session::put('Expense.filter', 'my');
}
}
$expenses = Expense::all();
return view('admin.expenses.index', compact('expenses'));
}
}
答案 0 :(得分:0)
尝试查找您是否正在从数据库获取数据....
$expenses = Expense::all();
dd($expenses);
它将显示您的数据收集。 我认为您没有从这里获取任何数据。