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.
 
 
 
 
 
 

93 lines
3.1 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', $project);
}
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();
return view('adjunctadditions.edit')->with('adjunctaddition', $adjunctaddition);
}
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()
{
return view('adjunctadditions.create');
}
public function destroy($id)
{
$adjunctaddition = Adjunctaddition::find($id);
$adjunctaddition->delete();
return redirect('/adjunctadditions')->with('success', 'Adjunct Addition deleted!');
}
}