Postingan lainnya
Error laravel notfound
Kira-kira error kenapa ya padahal sudah benar semua tapi tetap saja error
Route : Web :
<?php
use App\Http\Controllers\SiswaController;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('home');
});
//Login
Route::get('/login','AuthController@login')->name('login');
Route::post('/post-login','AuthController@postlogin');
Route::get('/logout','AuthController@logout');
//Dashboard Admin
Route::group(['middleware' => ['auth','CheckRole:admin']],function (){
Route::get('/siswa','SiswaController@index');
Route::post('/siswa/create','SiswaController@create');
Route::get('/siswa/{siswa}','SiswaController@show');
Route::get('/siswa/{siswa}/edit','SiswaController@edit');
Route::post('/siswa/{id}/update','SiswaController@update');
Route::delete('/siswa/{siswa}','SiswaController@destroy');
Route::get('/siswa/addVal','SiswaController@addVal');
});
//Dashboard Siswa
Route::group(['middleware' => ['auth','CheckRole:admin,siswa']],function (){
Route::get('/dashboard','DashboardController@index');
});
SiswaController :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Siswa;
class SiswaController extends Controller
{
public function index(Request $request)
{
if($request->has('cari'))
{
$table = Siswa::where('kd_siswa','LIKE','%' . $request->cari . '%')->get();
}else{
$table = Siswa::all();
}
return view('siswa.index',compact('table'));
}
public function show(Siswa $siswa)
{
return view('siswa.show',compact('siswa'));
}
public function create(Request $request)
{
$request->validate([
'nama_depan' => 'required',
'kd_siswa' => 'required',
'nama_belakang' => 'required',
'jk' => 'required',
'agama' => 'required',
'alamat' => 'required'
]);
//insert into table user
$user = new \App\User;
$user->role = 'siswa';
$user->username = $request->nama_depan;
$user->email = $request->email;
$user->password = bcrypt('rahasia');
$user->remember_token = Str::random(60);
$user->save();
//insert into table siswa
$request->request->add(['user_id' => $user->id]);
$siswa = Siswa::create($request->all());
return redirect('/siswa')->with('sukses','Berhasil Input');
}
public function edit(Siswa $siswa)
{
// $siswa = Siswa::find($id);
return view('siswa.edit',compact('siswa'));
}
public function update(Request $request,$id)
{
$siswa = Siswa::find($id);
$siswa->update($request->all());
if($request->hasFile('avatar'))
{
$request->file('avatar')->move('img',$request->file('avatar')->getClientOriginalName());
$siswa->avatar = $request->file('avatar')->getClientOriginalName();
$siswa->save();
}
return redirect('/siswa')->with('sukses','Berhasil update');
}
public function destroy(Siswa $siswa)
{
Siswa::destroy($siswa->id);
return redirect('/siswa')->with('delete','Berhasil Hapus');
}
public function addVal()
{
return view('siswa.addVal');
}
}
AddVal.blade.php :
@extends('layout.main')
@section('content')
@section('title','Data Siswa')
HALAMAN ADD NILAI
@endsection
0
Tanggapan
Errornya seperti apa ?