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.
141 lines
4.0 KiB
141 lines
4.0 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Hop;
|
|
|
|
class HopController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
|
|
public function index()
|
|
{
|
|
$project = Hop::orderBy('name')->get();
|
|
return view('hops.index')->with('hops', $project);
|
|
}
|
|
|
|
public function store(Request $request){
|
|
// validation
|
|
$this->validate($request,[
|
|
'name' => 'required',
|
|
]);
|
|
|
|
|
|
// create project
|
|
$hop = new hop;
|
|
$lastID = Hop::orderBy('id','desc')->take(1)->value('id');
|
|
$hop->id = number_format($lastID) + 1;
|
|
$hop->name = $request->input('name');
|
|
if ($request->input('alpha_acid'))
|
|
{
|
|
$hop->alpha_acid = $request->input('alpha_acid');
|
|
}
|
|
$hop->bitter = $request->input('bitter');
|
|
$hop->aroma = $request->input('aroma');
|
|
if ($request->input('beta_acid'))
|
|
{
|
|
$hop->beta_acid = $request->input('beta_acid');
|
|
}
|
|
if ($request->input('myrcene'))
|
|
{
|
|
$hop->myrcene = $request->input('myrcene');
|
|
}
|
|
if ($request->input('profile'))
|
|
{
|
|
$hop->profile = '{'.$request->input('profile').'}';
|
|
}
|
|
if ($request->input('humulene'))
|
|
{
|
|
$hop->humulene = $request->input('humulene');
|
|
}
|
|
if ($request->input('total_oil'))
|
|
{
|
|
$hop->total_oil = $request->input('total_oil');
|
|
}
|
|
if ($request->input('cohumulone'))
|
|
{
|
|
$hop->cohumulone = $request->input('cohumulone');
|
|
}
|
|
if ($request->input('farnesene'))
|
|
{
|
|
$hop->farnesene = $request->input('farnesene');
|
|
}
|
|
if ($request->input('caryophyllene'))
|
|
{
|
|
$hop->caryophyllene = $request->input('caryophyllene');
|
|
}
|
|
$hop->save();
|
|
|
|
return redirect('/hops')->with('success', 'Hop Added!');
|
|
}
|
|
|
|
public function edit($id){
|
|
$hop = Hop::where('id', (int)$id)->first();
|
|
return view('hops.edit')->with('hop', $hop);
|
|
}
|
|
|
|
public function update(Request $request, $id){
|
|
// validation
|
|
$this->validate($request,[
|
|
'name' => 'required',
|
|
]);
|
|
$hop = Hop::where('id', (int)$id)->first();
|
|
$hop->name = $request->input('name');
|
|
if ($request->input('alpha_acid'))
|
|
{
|
|
$hop->alpha_acid = $request->input('alpha_acid');
|
|
}
|
|
$hop->bitter = $request->input('bitter');
|
|
$hop->aroma = $request->input('aroma');
|
|
if ($request->input('beta_acid'))
|
|
{
|
|
$hop->beta_acid = $request->input('beta_acid');
|
|
}
|
|
if ($request->input('myrcene'))
|
|
{
|
|
$hop->myrcene = $request->input('myrcene');
|
|
}
|
|
if ($request->input('profile'))
|
|
{
|
|
$hop->profile = '{'.$request->input('profile').'}';
|
|
}
|
|
if ($request->input('humulene'))
|
|
{
|
|
$hop->humulene = $request->input('humulene');
|
|
}
|
|
if ($request->input('total_oil'))
|
|
{
|
|
$hop->total_oil = $request->input('total_oil');
|
|
}
|
|
if ($request->input('cohumulone'))
|
|
{
|
|
$hop->cohumulone = $request->input('cohumulone');
|
|
}
|
|
if ($request->input('farnesene'))
|
|
{
|
|
$hop->farnesene = $request->input('farnesene');
|
|
}
|
|
if ($request->input('caryophyllene'))
|
|
{
|
|
$hop->caryophyllene = $request->input('caryophyllene');
|
|
}
|
|
$hop->save();
|
|
return redirect('/hops')->with('success', 'Hop Updated!');
|
|
}
|
|
public function create()
|
|
{
|
|
return view('hops.create');
|
|
}
|
|
public function destroy($id)
|
|
{
|
|
$hop = Hop::find($id);
|
|
$hop->delete();
|
|
|
|
return redirect('/hops')->with('success', 'Hop deleted!');
|
|
}
|
|
}
|