Andrew Sanjaya
Andrew Sanjaya

Reputation: 11

Target class [App\Http\Controllers\AdminTampilSekolahController] does not exist

I am trying to do a basic CRUD app, but this is what I got.

Can it be because the variable $sekolah can't read?

this is the source code

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]);

    } 
}

and the view 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>

Upvotes: 0

Views: 4687

Answers (1)

Salim Djerbouh
Salim Djerbouh

Reputation: 11034

The name of the class in the controller should follow the name of the file

Change

class InputSekolahController extends Controller

To

class AdminTampilSekolahController extends Controller

Because Laravel uses composer and reflection to build a class-map

You may need to run

composer dumpautoload 

After this so that the class loads

Upvotes: 2

Related Questions