You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Models\Adjunct;
class AdjunctController extends Controller { public function __construct() { $this->middleware('auth'); }
public function index() { $adjuncts = Adjunct::orderBy('name')->get(); return view('adjuncts.index')->with('adjuncts', $adjuncts); }
public function store(Request $request){ // validation
$this->validate($request,[ 'name' => 'required', ]);
// create project
$adjunct = new Adjunct; $lastID = Adjunct::orderBy('id','desc')->take(1)->value('id'); $adjunct->id = number_format($lastID) + 1; $adjunct->name = $request->input('name'); $adjunct->save();
return redirect('/adjuncts')->with('success', 'Adjunct Added!'); } public function edit($id){ $adjunct = Adjunct::where('id', (int)$id)->first(); return view('adjuncts.edit')->with('adjunct', $adjunct); }
public function update(Request $request, $id){ // validation
$this->validate($request,[ 'name' => 'required', ]);
$adjunct = Adjunct::where('id', (int)$id)->first(); $adjunct->name = $request->input('name'); $adjunct->save();
return redirect('/adjuncts')->with('success', 'Adjunct Updated!'); } public function create() { return view('adjuncts.create'); } public function destroy($id) { $adjunct = Adjunct::find($id); $adjunct->delete();
return redirect('/adjuncts')->with('success', 'Adjunct deleted!'); }
}
|