我在员工管理系统中使用laravel 5查询生成器时遇到问题.这是我的员工管理员
<?php
namespace App\Http\Controllers;
use App\Employee;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class EmployeesController extends Controller
{
public function index()
{
// $employees = Employee::all();
// return view('employees.index', compact('employees'));
$employees = DB::table('employees')->get();
return view('employees.index', compact('employees'));
}
}
当我使用注释掉的代码时,视图工作,我可以看到我的员工列表
$employees = Employee::all();
return view('employees.index', compact('employees'));
我在这里看到了answer,我按照建议做了,但没有运气.我添加了use DB;在名称空间声明之后,还try 了
$employees = \DB::table('employees')->get();
but it throws another error which says Call to a member function count() on a non-object on line 6. I even copied the DB.php file from C:\xampp\htdocs\laravel5project\vendor\laravel\framework\src\Illuminate\Support\Facades to the App folder (C:\xampp\htdocs\laravel5project\app) but still no luck. I've also tried to explicitly give it the namespace
use Illuminate\Support\Facades\DB
这里是风景
@extends('layouts.default')
@section('PageTitle', 'Employee List')
@section('content')
@if ( !$employees->count() )
There are no Employees!
@else
<table id="tblEmployee" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach( $employees as $employee )
<tr>
<td>{{$employee->Name}}</td>
</tr>
@endforeach
</tbody>
</table>
@endif
@endsection
有什么问题吗?