mercredi 15 août 2018

Laravel after joining the table is not showing

the index method use 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]);
   }}

my course.aindex is

<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></td>
    <td></td>
    <td></td>
    <td></td>

    <td class="pl-5">
    <a href ="" 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 = "" 
      method ="post" class = "d-inline-block">
       
       
       <button type = "submit" class="btn btn-danger">Delete</button>
       </form></td>
  </tr>

The above joining has some error maybe thats why the table is not showing at all means no data is showing but if i do this in index method

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

then the index page shows the table but when i join the tables it does not work i have added the teacher_id in fillable. if i add dd($all) in index method it returns me this

Collection {#250 ▼
#items: []
}

so i am guessing there is something wrong in my joining command please help



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire