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.
		
		
		
		
		
			
		
			
				
					
					
						
							79 lines
						
					
					
						
							2.0 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							79 lines
						
					
					
						
							2.0 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Http\Controllers;
							 | 
						|
								
							 | 
						|
								use Illuminate\Http\Request;
							 | 
						|
								use App\Models\Brewerie;
							 | 
						|
								class BrewerieController extends Controller
							 | 
						|
								{
							 | 
						|
								    public function __construct()
							 | 
						|
								    {
							 | 
						|
								        $this->middleware('auth');
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								    public function index()
							 | 
						|
								    {
							 | 
						|
								        $project = Brewerie::orderBy('name')->get();
							 | 
						|
								        return view('breweries.index')->with('breweries', $project);
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								   public function store(Request $request){
							 | 
						|
								        // validation
							 | 
						|
								        $this->validate($request,[
							 | 
						|
								            'name' => 'required',
							 | 
						|
								        ]);
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        // create project
							 | 
						|
								        $brewerie = new Brewerie;
							 | 
						|
								        $lastID = Brewerie::orderBy('id','desc')->take(1)->value('id');
							 | 
						|
								        $brewerie->id = number_format($lastID) + 1;
							 | 
						|
								        $brewerie->name = $request->input('name');
							 | 
						|
								        if ($request->input('place'))
							 | 
						|
								        {
							 | 
						|
								                $brewerie->place = $request->input('place');
							 | 
						|
								        }
							 | 
						|
								        if ($request->input('country'))
							 | 
						|
								        {
							 | 
						|
								                $brewerie->country = $request->input('country');
							 | 
						|
								        }
							 | 
						|
								        $brewerie->save();
							 | 
						|
								
							 | 
						|
								        return redirect('/breweries')->with('success', 'Brewery Added');
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    public function edit($id){
							 | 
						|
									      $brewery = Brewerie::where('id', (int)$id)->first();
							 | 
						|
								        return view('breweries.edit')->with('brewery', $brewery);
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    public function update(Request $request, $id)
							 | 
						|
								    {
							 | 
						|
								        $request->validate([
							 | 
						|
								            'name'=>'required',
							 | 
						|
								            'place'=>'required',
							 | 
						|
								            'country'=>'required'
							 | 
						|
								        ]);
							 | 
						|
								
							 | 
						|
								        $brewery = Brewerie::where('id', $id)->first();
							 | 
						|
								        $brewery->name =  $request->get('name');
							 | 
						|
								        $brewery->place = $request->get('place');
							 | 
						|
								        $brewery->country = $request->get('country');
							 | 
						|
								        $brewery->save();
							 | 
						|
								
							 | 
						|
								        return redirect('/breweries')->with('success', 'Brewery updated!');
							 | 
						|
								    }
							 | 
						|
								    public function create()
							 | 
						|
								    {
							 | 
						|
								        return view('breweries.create');
							 | 
						|
								    }
							 | 
						|
								    public function destroy($id)
							 | 
						|
								    {
							 | 
						|
								        $brewery = Brewerie::find($id);
							 | 
						|
								        $brewery->delete();
							 | 
						|
								
							 | 
						|
								        return redirect('/breweries')->with('success', 'Brewery deleted!');
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								}
							 |