mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-24 04:14:57 +00:00
Including item and product form validation
This commit is contained in:
parent
25cff75c48
commit
2845e7501d
@ -7,17 +7,33 @@ use \App\Item;
|
||||
|
||||
class ItemController extends Controller
|
||||
{
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
//$item = Item::all();
|
||||
//return $item; //Show a JSON file instead of the view
|
||||
return view('item');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
//TODO: Fazer innerjoint com tabela de users por item
|
||||
$item = Item::where([['id', $id], ['userID', \Auth::id()]]);
|
||||
return view('item', compact('item'));
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
//TODO: Fazer innerjoint com tabela de users por item
|
||||
$items = Item::where('adminID', \Auth::id())->get();
|
||||
return view('item.index', compact('items'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the included item into database
|
||||
* As the items are included on the Product view,
|
||||
* it must return to there after inclusion
|
||||
*
|
||||
* @return (view) The product view
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$this->validate(request(), ['name' => 'required']);
|
||||
Item::create(['name' => request('item'), 'productID' => request('productID')]); //Just remember to add the fillable on Model to make this work
|
||||
|
||||
return redirect('product');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use \App\User;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
$products = Product::where('adminID', \Auth::id())->get();
|
||||
|
11
resources/views/layouts/errors.blade.php
Normal file
11
resources/views/layouts/errors.blade.php
Normal file
@ -0,0 +1,11 @@
|
||||
@if (count($errors))
|
||||
<div class="form-group">
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
@ -9,13 +9,13 @@
|
||||
<div class="form-group">
|
||||
{{ csrf_field() }}
|
||||
<div class="col"><label for="product">Add Product: </label></div>
|
||||
<div class="col-6"><input type="text" class="form-control" name="product" id="product" placeholder="Book"></div>
|
||||
<div class="col-6"><input type="text" class="form-control" name="product" id="product" placeholder="Book" required></div>
|
||||
<div class="col"><button type="submit" class="btn btn-primary">Insert</button></div>
|
||||
</div>
|
||||
@include ('layouts.errors')
|
||||
</form>
|
||||
<p><br></p>
|
||||
|
||||
<div class="card">
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">Products</div>
|
||||
|
||||
<div class="card-body">
|
||||
|
@ -9,13 +9,13 @@
|
||||
<div class="form-group">
|
||||
{{ csrf_field() }}
|
||||
<div class="col"><label for="product">Add Item: </label></div>
|
||||
<div class="col-6"><input type="text" class="form-control" name="item" id="item" placeholder="One Hundred Years of Solitude"></div>
|
||||
<div class="col-6"><input type="text" class="form-control" name="item" id="item" placeholder="One Hundred Years of Solitude" required></div>
|
||||
<div class="col"><button type="submit" class="btn btn-primary">Insert</button></div>
|
||||
</div>
|
||||
@include ('layouts.errors')
|
||||
</form>
|
||||
<p><br></p>
|
||||
|
||||
<div class="card">
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">
|
||||
Product: <strong>{{$product['name']}}</strong>
|
||||
<span class="d-inline-block text-truncat float-right">Edit - Delete</span>
|
||||
@ -34,7 +34,6 @@
|
||||
<p>There are no items yet. Include one with the form above.</p>
|
||||
@endforelse
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user