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.
166 lines
4.7 KiB
166 lines
4.7 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Summarie;
|
|
use App\Models\Brewerie;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SummarieController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
|
|
public function index()
|
|
{
|
|
$beers = Summarie::orderBy('name')->get();
|
|
foreach ($beers as $beer)
|
|
{
|
|
$brewery = DB::table('breweries')->where('id', $beer->brewery_id)->value('name');
|
|
$beer['brewery'] = $brewery;
|
|
}
|
|
return view('beers.index')->with('beers', $beers);
|
|
}
|
|
|
|
public function store(Request $request){
|
|
// validation
|
|
$this->validate($request,[
|
|
'name' => 'required',
|
|
'type' => 'required',
|
|
'abv' => 'required',
|
|
'fg' => 'required',
|
|
'keywords' => 'required',
|
|
'og' => 'required',
|
|
'source' => 'required',
|
|
'batch' => 'required',
|
|
'beer_id' => 'required',
|
|
'brewery_id' => 'required'
|
|
]);
|
|
|
|
|
|
// create project
|
|
$beer = new Summarie;
|
|
$beer->beer_id = $request->input('beer_id');
|
|
$beer->name = $request->input('name');
|
|
$beer->type = $request->input('type');
|
|
$beer->abv = $request->input('abv');
|
|
$beer->fg = $request->input('fg');
|
|
$beer->keywords = '{'.$request->input('keywords').'}';
|
|
if ($request->mine)
|
|
{
|
|
$beer->mine = true;
|
|
} else {
|
|
$beer->mine = false;
|
|
}
|
|
$beer->og = $request->input('og');
|
|
$beer->source = $request->input('source');
|
|
$beer->batch = $request->input('batch');
|
|
$beer->brewery_id = $request->input('brewery_id');
|
|
if ($request->input('notes'))
|
|
{
|
|
$beer->notes = $request->input('notes');
|
|
}
|
|
if ($request->input('boil_volume'))
|
|
{
|
|
$beer->boil_volume = $request->input('boil_volume');
|
|
}
|
|
if ($request->input('ebc'))
|
|
{
|
|
$beer->ebc = $request->input('ebc');
|
|
}
|
|
if ($request->input('srm'))
|
|
{
|
|
$beer->srm = $request->input('srm');
|
|
}
|
|
if ($request->input('ph'))
|
|
{
|
|
$beer->ph = $request->input('ph');
|
|
}
|
|
$beer->save();
|
|
|
|
return redirect('/beers')->with('success', 'Beer Added');
|
|
}
|
|
|
|
public function edit($id){
|
|
$beer = Summarie::where('beer_id', (int)$id)->first();
|
|
return view('beers.edit')->with('beer', $beer);
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$request->validate([
|
|
'name' => 'required',
|
|
'type' => 'required',
|
|
'abv' => 'required',
|
|
'fg' => 'required',
|
|
'keywords' => 'required',
|
|
'og' => 'required',
|
|
'source' => 'required',
|
|
'batch' => 'required',
|
|
'brewery_id' => 'required'
|
|
]);
|
|
|
|
$beer = Summarie::where('beer_id', (int)$id)->first();
|
|
$beer->name = $request->input('name');
|
|
$beer->type = $request->input('type');
|
|
$beer->abv = $request->input('abv');
|
|
$beer->fg = $request->input('fg');
|
|
$beer->keywords = '{'.$request->input('keywords').'}';
|
|
if ($request->mine)
|
|
{
|
|
$beer->mine = true;
|
|
} else {
|
|
$beer->mine = false;
|
|
}
|
|
$beer->og = $request->input('og');
|
|
$beer->source = $request->input('source');
|
|
$beer->batch = $request->input('batch');
|
|
$beer->brewery_id = $request->input('brewery_id');
|
|
if ($request->input('notes'))
|
|
{
|
|
$beer->notes = $request->input('notes');
|
|
}
|
|
if ($request->input('boil_volume'))
|
|
{
|
|
$beer->boil_volume = $request->input('boil_volume');
|
|
}
|
|
if ($request->input('ebc'))
|
|
{
|
|
$beer->ebc = $request->input('ebc');
|
|
}
|
|
if ($request->input('srm'))
|
|
{
|
|
$beer->srm = $request->input('srm');
|
|
}
|
|
if ($request->input('ph'))
|
|
{
|
|
$beer->ph = $request->input('ph');
|
|
}
|
|
$beer->save();
|
|
|
|
return redirect('/beers')->with('success', 'Beer updated!');
|
|
}
|
|
public function create()
|
|
{
|
|
$lastID = Summarie::orderBy('beer_id','desc')->take(1)->value('beer_id');
|
|
$beer_id = number_format($lastID) + 1;
|
|
$brewery_list = Brewerie::orderBy('name')->pluck('name', 'id');
|
|
$data = array('beer_id'=>$beer_id, 'brewery_list'=>$brewery_list);
|
|
return view('beers.create')->with($data);
|
|
|
|
}
|
|
public function destroy($id)
|
|
{
|
|
$beer = Summarie::find($id);
|
|
$beer->delete();
|
|
|
|
return redirect('/beers')->with('success', 'Beer deleted!');
|
|
}
|
|
|
|
|
|
|
|
}
|