TIF_E41201014/app/Http/Controllers/Server/JurusanController.php

95 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\Server;
use App\Http\Controllers\Controller;
use App\Http\Requests\JurusanRequest;
use App\Models\Jurusan;
use Illuminate\Http\Request;
class JurusanController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$numb = 1;
$data = Jurusan::all();
return view('server-side.jurusan.index', compact('data', 'numb'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('server-side.jurusan.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(JurusanRequest $request)
{
$data = $request->all();
Jurusan::create($data);
return redirect()->route('jurusan.index')->with('message', 'Data berhasil ditambahkan');
}
/**
* Display the specified resource.
*
* @param \App\Models\Jurusan $jurusan
* @return \Illuminate\Http\Response
*/
public function show(Jurusan $jurusan)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Jurusan $jurusan
* @return \Illuminate\Http\Response
*/
public function edit(Jurusan $jurusan)
{
return view('server-side.jurusan.edit', compact('jurusan'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Jurusan $jurusan
* @return \Illuminate\Http\Response
*/
public function update(JurusanRequest $request, Jurusan $jurusan)
{
$jurusan->update($request->validated());
return redirect()->route('jurusan.index')->with('message', 'Data berhasil diubah');
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Jurusan $jurusan
* @return \Illuminate\Http\Response
*/
public function destroy($id_jurusan)
{
$jurusan = Jurusan::find($id_jurusan);
$jurusan->delete();
return redirect()->route('jurusan.index')->with('message', 'Data berhasil dihapus');
}
}