从简单的.php添加一个jQuery表到.blade.php Laravel5

时间:2016-11-10 20:16:04

标签: php laravel laravel-5 blade laravel-blade

我有一个带导航栏的网站(位于main.blade.php中)。我创建了一个jQuery表,但不是在刀片视图中,而是作为一个简单的.php。如何设置内容部分并将其添加到刀片?谢谢!

路线:

web.php

old(来自刀片的简单页面):

Route::get('/manageclasses', ['as' => 'manageclasses', 'uses' => 'UserView\AdminController@manageclasses']);

新的(带表格的简单页面):

Route::get('/manageclasses',['as' => 'manageclasses',function(){
  $manageclasa = App\Elevi::all();
  return View::make('table')->with('manageclasa', $manageclasa);
}]);

我想要添加表格的刀片布局

@extends('layouts.master')
@extends('layouts.navbar')
@extends('layouts.sidebar')


@section('content')
<h3 class="white-text">Manage Page</h3>

@endsection

我的新布局

<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>Manage Clasa</title>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
      <script src="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
      <link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
   </head>


   <body>
      <h1>Elevi clasa</h1>
      <table>
      <thead>
         <tr>
            <th>Nume</th>
            <th>Prenume</th>
         </tr>
      </thead>
      <tbody>
         <?php foreach ($manageclasa as $elev): ?>
         <tr>
            <td><?php echo $elev['nume'] ?></td>
            <td><?php echo $elev['prenume'] ?></td>
         </tr>
         <?php endforeach; ?>
      </tbody>
      </table>

      <script>
         $(function(){
            $("table").dataTable();
         });
      </script>
   </body>
</html>

1 个答案:

答案 0 :(得分:0)

您正在返回一个Eloquent对象。试试这个:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Manage Clasa</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
</head>


<body>
<h1>Elevi clasa</h1>
<table id="elevi-clasa">
<thead>
<tr>
  <th>Nume</th>
  <th>Prenume</th>
</tr>
</thead>
<tbody>
@foreach($manageclasa as $elev)
<tr>
  <td>{{ $elev->nume }}</td>
  <td>{{ $elev->prenume }}</td>
</tr>
@endforeach
</tbody>
</table>

<script>
$(function(){
$("#elevi-clasa").dataTable();
});
</script>
</body>
</html>