My beer compendium
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.
 
 
 
 
 
 

102 lines
3.8 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Adjunctaddition;
use App\Models\Adjunct;
use App\Models\Summarie;
class AdjunctAdditionController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$adjunctadditions = Adjunctaddition::get();
foreach ($adjunctadditions as $adjunctaddition)
{
$beername = Summarie::where('beer_id', $adjunctaddition->beer_id)->value('name');
$adjunctname = Adjunct::where('id', $adjunctaddition->adjunct_id)->value('name');
$altname = Adjunct::where('id', $adjunctaddition->alternative)->value('name');
$adjunctaddition['beer'] = $beername;
$adjunctaddition['name'] = $adjunctname;
$adjunctaddition['alternativename'] = $altname;
}
return view('adjunctadditions.index')->with('adjunctadditions', $adjunctadditions);
}
public function store(Request $request){
// validation
$this->validate($request,[
'beer_id' => 'required',
'adjunct_id' => 'required',
'amount' => 'required',
'timing' => 'required',
]);
// create project
$adjunct = new Adjunctaddition;
$lastID = Adjunctaddition::orderBy('id','desc')->take(1)->value('id');
$adjunct->id = number_format($lastID) + 1;
$adjunct->beer_id = $request->input('beer_id');
$adjunct->adjunct_id = $request->input('adjunct_id');
$adjunct->amount = $request->input('amount');
$adjunct->timing = $request->input('timing');
$adjunct->alternative = $request->input('alternative');
$adjunct->notes = $request->input('notes');
$adjunct->save();
return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Added');
}
public function edit($id){
$adjunctaddition = Adjunctaddition::where('id', (int)$id)->first();
$beers = Summarie::orderBy('name')->get();
$selected_beer = $adjunctaddition->beer_id;
$adjuncts = Adjunct::orderBy('name')->get();
$selected_adjunct = $adjunctaddition->adjunct_id;
$selected_alt = $adjunctaddition->alternative;
$data = array('adjunctaddition'=>$adjunctaddition, 'beers'=>$beers, 'adjuncts'=>$adjuncts, 'selected_beer'=>$selected_beer, 'selected_adjunct'=>$selected_adjunct, 'selected_alt'=>$selected_alt);
return view('adjunctadditions.edit')->with($data);
}
public function update(Request $request, $id){
// validation
$this->validate($request,[
'beer_id' => 'required',
'adjunct_id' => 'required',
'amount' => 'required',
'timing' => 'required',
]);
$adjunct = Adjunctaddition::where('id', (int)$id)->first();
$adjunct->beer_id = $request->input('beer_id');
$adjunct->adjunct_id = $request->input('adjunct_id');
$adjunct->amount = $request->input('amount');
$adjunct->timing = $request->input('timing');
$adjunct->alternative = $request->input('alternative');
$adjunct->notes = $request->input('notes');
$adjunct->save();
return redirect('/adjunctadditions')->with('success', 'Adjunct Addition Updated!');
}
public function create()
{
$beers = Summarie::orderBy('name')->get();
$adjuncts = Adjunct::orderBy('name')->get();
$data = array('beers'=>$beers, 'adjuncts'=>$adjuncts);
return view('adjunctadditions.create')->with($data);
}
public function destroy($id)
{
$adjunctaddition = Adjunctaddition::find($id);
$adjunctaddition->delete();
return redirect('/adjunctadditions')->with('success', 'Adjunct Addition deleted!');
}
}