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.
		
		
		
		
		
			
		
			
				
					
					
						
							105 lines
						
					
					
						
							2.9 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							105 lines
						
					
					
						
							2.9 KiB
						
					
					
				| <?php | |
| 
 | |
| namespace App\Http\Controllers; | |
| 
 | |
| use Illuminate\Http\Request; | |
| use App\Models\Yeast; | |
| class YeastController extends Controller | |
| { | |
|     public function __construct() | |
|     { | |
|         $this->middleware('auth'); | |
|     } | |
| 
 | |
| 
 | |
|     public function index() | |
|     { | |
|         $yeasts = Yeast::orderBy('name')->get(); | |
|         return view('yeasts.index')->with('yeasts', $yeasts); | |
|     } | |
| 
 | |
|    public function store(Request $request){ | |
|         // validation | |
|         $this->validate($request,[ | |
|             'name' => 'required', | |
|         ]); | |
| 
 | |
| 
 | |
|         // create project | |
|         $yeast = new Yeast; | |
|         $lastID = Yeast::orderBy('id','desc')->take(1)->value('id'); | |
|         $yeast->id = number_format($lastID) + 1; | |
|         $yeast->name = $request->input('name'); | |
|         if ($request->input('attenuation')) | |
|         { | |
|                 $yeast->attenuation = $request->input('attenuation'); | |
|         } | |
|         if ($request->input('flocculation')) | |
|         { | |
|                 $yeast->flocculation = $request->input('flocculation'); | |
|         } | |
|         if ($request->input('profile')) | |
| 	      { | |
| 		            $yeast->profile = '{'.$request->input('profile').'}'; | |
| 	      } | |
| 	      if ($request->input('tolerance')) | |
|         { | |
|                 $yeast->tolerance = $request->input('tolerance'); | |
|         } | |
|         if ($request->input('temp_range')) | |
|         { | |
|                 $yeast->temp_range = $request->input('temp_range'); | |
|         } | |
|         $yeast->save(); | |
| 
 | |
|         return redirect('/yeasts')->with('success', 'Yeast Added!'); | |
|     } | |
|     public function edit($id){ | |
|         $yeast = Yeast::where('id', (int)$id)->first(); | |
|         return view('yeasts.edit')->with('yeast', $yeast); | |
|     } | |
| 
 | |
|     public function update(Request $request, $id){ | |
|         // validation | |
|         $this->validate($request,[ | |
|             'name' => 'required', | |
|         ]); | |
| 
 | |
|         $yeast = Yeast::where('id', (int)$id)->first(); | |
|         $yeast->name = $request->input('name'); | |
|         if ($request->input('attenuation')) | |
|         { | |
|                 $yeast->attenuation = $request->input('attenuation'); | |
|         } | |
|         if ($request->input('flocculation')) | |
|         { | |
|                 $yeast->flocculation = $request->input('flocculation'); | |
|         } | |
|         if ($request->input('profile')) | |
| 	      { | |
| 		            $yeast->profile = '{'.$request->input('profile').'}'; | |
| 	      } | |
| 	      if ($request->input('tolerance')) | |
|         { | |
|                 $yeast->tolerance = $request->input('tolerance'); | |
|         } | |
|         if ($request->input('temp_range')) | |
|         { | |
|                 $yeast->temp_range = $request->input('temp_range'); | |
|         } | |
|         $yeast->save(); | |
| 
 | |
|         return redirect('/yeasts')->with('success', 'Yeast Updated!'); | |
|     } | |
|     public function create() | |
|     { | |
|         return view('yeasts.create'); | |
|     } | |
|     public function destroy($id) | |
|     { | |
|         $yeast = Yeast::find($id); | |
|         $yeast->delete(); | |
| 
 | |
|         return redirect('/yeasts')->with('success', 'Yeast deleted!'); | |
|     } | |
| }
 |