Laravel加入桌子后没有显示

时间:2018-08-15 21:55:49

标签: laravel laravel-5

索引方法      使用Illuminate \ Support \ Facades \ DB;

 class CourseController extends Controller
  {public function indexeli(){
 $all = DB::table('courses')
        ->join('teachers', 'courses.teacher_id', '=', 'teachers.id')
        ->select('courses.*', 'teachers.tchr_name')
        ->get();

    return view('course.aindex',['data'=>$all]);
   }}

我的course.aindex是

<table class="table table-bordered mt-5">
<thead class="">
  <tr>
    <th>Course ID</th>
    <th>Course Name</th>
    <th>Course Type</th>
      <th>Teacher Name</th>
    <th>Edit</th>
    <th>Delete</th>
  </tr>
</thead>
<tbody>

@foreach($data as $x)
<tr>
    <td>{{$x->course_id}}</td>
    <td>{{$x->course_name}}</td>
    <td>{{$x->course_type}}</td>
    <td>{{$x->tchr_name}}</td>

    <td class="pl-5">
    <a href ="{{route('editeli',$x->id)}}" class="btn btn-info ml- 
    2">Edit</a></td>
    <td class="pl-5"><form onsubmit = "return confirm('are you sure you want 
    to delete this info?')" action = "{{route('destroyeli', $x->id)}}" 
      method ="post" class = "d-inline-block">
       {{csrf_field()}}
       {{method_field('delete')}}
       <button type = "submit" class="btn btn-danger">Delete</button>
       </form></td>
  </tr>

上面的连接有一些错误,也许就是为什么表根本不显示意味着没有数据显示但是 如果我在索引方法中这样做

  $all = Course::all();
   return view('course.aindex',['data'=>$all]);

然后索引页显示表,但是当我加入表时它不起作用 我在fillable中添加了teacher_id。如果我在索引方法中添加dd($ all),它将向我返回

Collection {#250 ▼
#items: []
}

所以我猜我的加入命令有问题,请帮助

0 个答案:

没有答案