我正在尝试做一个基本的CRUD应用,但这就是我得到的。
是因为变量$sekolah
无法读取吗?
这是源代码
web.php
<?php
Route::get('/', function () {
return view('index');
});
// Route::get('/event', function () {
// $namaevent = 'contoh event';
// return view('event',['namaevent' => $namaevent]);
//route CRUD
Route::get('/tampilsekolah','AdminTampilSekolahController@index');
Route::get('/event','EventController@index');
Route::get('/loker','LokerController@index');
Route::get('/pencarian', function () {
return view('pencarian');
});
Route::get('/listsekolah', function () {
return view('listsekolah');
});
Route::get('/sekolaah', function () {
return view('test');
});
AdminTampilSekolahController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Controllers;
class InputSekolahController extends Controller
{
public function index()
{
// mengambil data dari table tb_sekolah
$sekolah = DB::table('tb_sekolah')->get();
// mengirim data sekolah ke view inputsekolah
return view('admintampilsekolah',['sekolah' => $sekolah]);
}
}
和视图 admintampilsekolah.blade.php
<!doctype html>
<html >
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="/css/style.css">
<title>List Sekolah (ADMIN)</title>
</head>
<body>
<!-- isi web -->
<div class="countainer">
<div class="card mx-auto" style="width: 85%; margin-top: 5%;">
<div class="card-header">
...........
</div>
<div class="card-body">
<h5 class="card-title text-center">.........</h5>
<div class="table-responsive-xl">
<table class="table table-bordered tabel table-striped">
<thead class="thead-dark text-center">
<tr>
<th scope="col">Kode Sekolah</th>
<th scope="col">Nama</th>
<th scope="col">Jenjang</th>
<th scope="col">Alamat</th>
<th scope="col">Kecamatan</th>
<th scope="col">Email</th>
<th scope="col">Notelp</th>
<th scope="col">Jumlah Guru</th>
<th scope="col">Jumlah Murid</th>
<th scope="col">Prestasi</th>
<th scope="col">Sarana</th>
<th scope="col">Akreditasi</th>
<th scope="col">Kurikulum</th>
<th width="10%" scope="col" colspan="2" >Option</th>
</tr>
</thead>
<tbody class="text-center">
@foreach($sekolah as $s)
<tr>
<td>{{$s->Kode}}></td>
<td>{{$s->Nama}}></td>
<td>{{$s->Jenjang}}></td>
<td>{{$s->Alamat}}></td>
<td>{{$s->Kecamatan}}></td>
<td>{{$s->Email}}></td>
<td>{{$s->Notelp}}></td>
<td>{{$s->Jumlahguru}}></td>
<td>{{$s->Jumlahmurid}}></td>
<td>{{$s->Prestasi}}></td>
<td>{{$s->Sarana}}></td>
<td>{{$s->Akreditasi}}></td>
<td>{{$s->Kurikulum}}></td>
<td>
<a href="/tb_sekolah/edit/{{$s->Kode}}" class="btn btn-primary ">EDIT</a>
</td>
<td>
<a href="/tb_sekolah/hapus/{{$s->Kode}}" class="btn btn-danger ">DELETE</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
答案 0 :(得分:2)
控制器中类的名称应紧随文件名之后
更改
class InputSekolahController extends Controller
收件人
class AdminTampilSekolahController extends Controller
因为Laravel使用作曲家和反思来构建类映射
您可能需要运行
composer dumpautoload
在此之后,该类将被加载