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.
		
		
		
		
		
			
		
			
				
					
					
						
							92 lines
						
					
					
						
							3.0 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							92 lines
						
					
					
						
							3.0 KiB
						
					
					
				| <?php | |
| 
 | |
| namespace App\Http\Controllers; | |
| 
 | |
| use Illuminate\Http\Request; | |
| use App\Models\Hopaddition; | |
| use App\Models\Hop; | |
| use App\Models\Summarie; | |
| class HopAdditionController extends Controller | |
| { | |
|     public function __construct() | |
|     { | |
|         $this->middleware('auth'); | |
|     } | |
| 
 | |
| 
 | |
|     public function index() | |
|     { | |
|         $hopadditions = Hopaddition::orderBy('id')->get(); | |
|         foreach ($hopadditions as $hopaddition) | |
|         { | |
|             $beername = Summarie::where('beer_id', $hopaddition->beer_id)->value('name'); | |
|             $hopname = Hop::where('id', $hopaddition->hop_id)->value('name'); | |
|             $hopaddition['beer'] = $beername; | |
|             $hopaddition['hop'] = $hopname; | |
|         } | |
|         return view('hopadditions.index')->with('hopadditions', $hopadditions); | |
|     } | |
| 
 | |
|    public function store(Request $request){ | |
|         // validation | |
|         $this->validate($request,[ | |
|             'beer_id' => 'required', | |
|             'hop_id' => 'required', | |
|             'amount' => 'required', | |
|             'timing' => 'required', | |
|         ]); | |
|         // create project | |
|         $hop = new Hopaddition; | |
|         $lastID = Hopaddition::orderBy('id','desc')->take(1)->value('id'); | |
|         $hop->id = number_format($lastID) + 1; | |
|         $hop->beer_id = $request->input('beer_id'); | |
|         $hop->hop_id = $request->input('hop_id'); | |
|         $hop->amount = $request->input('amount'); | |
|         $hop->timing = $request->input('timing'); | |
|         $hop->save(); | |
| 
 | |
|         return redirect('/hopadditions')->with('success', 'Hop Addition Added'); | |
|     } | |
|     public function edit($id){ | |
|         $hopaddition = Hopaddition::where('id', (int)$id)->first(); | |
|         $beers = Summarie::orderBy('name')->get(); | |
|         $selected_beer = $hopaddition->beer_id; | |
|         $hops = Hop::orderBy('name')->get(); | |
|         $selected_hop = $hopaddition->hop_id; | |
|         $data = array('hopaddition'=>$hopaddition, 'beers'=>$beers, 'hops'=>$hops, 'selected_beer'=>$selected_beer, 'selected_hop'=>$selected_hop); | |
|         return view('hopadditions.edit')->with($data); | |
|     } | |
| 
 | |
|     public function update(Request $request, $id){ | |
|         // validation | |
|         $this->validate($request,[ | |
|           'beer_id' => 'required', | |
|           'hop_id' => 'required', | |
|           'amount' => 'required', | |
|           'timing' => 'required', | |
|         ]); | |
| 
 | |
|         $hop = Hopaddition::where('id', (int)$id)->first(); | |
|         $hop->beer_id = $request->input('beer_id'); | |
|         $hop->hop_id = $request->input('hop_id'); | |
|         $hop->amount = $request->input('amount'); | |
|         $hop->timing = $request->input('timing'); | |
|         $hop->save(); | |
| 
 | |
|         return redirect('/hopadditions')->with('success', 'Hop Addition Updated!'); | |
|     } | |
|     public function create() | |
|     { | |
|         $beers = Summarie::orderBy('name')->get(); | |
|         $hops = Hop::orderBy('name')->get(); | |
|         $data = array('beers'=>$beers, 'hops'=>$hops); | |
|         return view('hopadditions.create')->with($data); | |
|     } | |
|     public function destroy($id) | |
|     { | |
|         $hopaddition = Hopaddition::find($id); | |
|         $hopaddition->delete(); | |
| 
 | |
|         return redirect('/hopadditions')->with('success', 'Hop Addition deleted!'); | |
|     } | |
| }
 |