-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a01c30
commit 497cd50
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
use App\Http\Requests; | ||
|
||
use App\Fornecedor; | ||
|
||
class FornecedorController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
} | ||
|
||
public function index() | ||
{ | ||
$fornecedores = Fornecedor::orderBy('Nome', 'asc')->get(); | ||
//$fornecedores = Fornecedor::all(); | ||
return view('fornecedores.index',['fornecedores' => $fornecedores]); | ||
} | ||
|
||
public function create() | ||
{ | ||
return view('fornecedores.create'); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$this->validate($request, [ | ||
'Nome' => 'required', | ||
'CNPJ' => 'required', | ||
'Endereco' => 'required', | ||
]); | ||
|
||
$fornecedores = new Fornecedor; | ||
$fornecedores->Nome = $request->Nome; | ||
$fornecedores->CNPJ = $request->CNPJ; | ||
$fornecedores->Endereco = $request->Endereco; | ||
$fornecedores->save(); | ||
return redirect('fornecedores')->with('message', 'Fornecedor atualizado com sucesso!'); | ||
|
||
} | ||
|
||
public function show($id) | ||
{ | ||
$fornecedores = Fornecedor::find($id); | ||
|
||
return view('fornecedores.details')->with('detailpage', $fornecedores); | ||
} | ||
|
||
public function edit($id) | ||
{ | ||
$fornecedores = Fornecedor::find($id); | ||
|
||
return view('fornecedores.edit')->with('detailpage', $fornecedores); | ||
} | ||
|
||
public function update(Request $request, $id) | ||
{ | ||
$this->validate($request, [ | ||
'Nome' => 'required', | ||
'CNPJ' => 'required', | ||
'Endereco' => 'required', | ||
]); | ||
|
||
$fornecedores = Fornecedor::find($id); | ||
$fornecedores->Nome = $request->Nome; | ||
$fornecedores->CNPJ = $request->CNPJ; | ||
$fornecedores->Endereco = $request->Endereco; | ||
$fornecedores->save(); | ||
return redirect('fornecedores')->with('message', 'Fornecedor atualizado com sucesso!'); | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
$fornecedores = Fornecedor::find($id); | ||
$fornecedores->delete(); | ||
return redirect('fornecedores'); | ||
} | ||
} |