mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-23 20:10:52 +00:00
Including Edit Product
This commit is contained in:
parent
614dbeda35
commit
707dd1654a
@ -35,7 +35,7 @@ class ProductController extends Controller
|
|||||||
{
|
{
|
||||||
//TODO: Delete all items with all users for the product
|
//TODO: Delete all items with all users for the product
|
||||||
$request->validate(['product' => 'required']);
|
$request->validate(['product' => 'required']);
|
||||||
$item = User::find(\Auth::id())
|
$item = User::findOrFail(\Auth::id())
|
||||||
->items()->with('users')->find(request('item'));
|
->items()->with('users')->find(request('item'));
|
||||||
$product = $item->product_id;
|
$product = $item->product_id;
|
||||||
|
|
||||||
@ -51,11 +51,12 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
public function patch(Request $request)
|
public function patch(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate(['item' => 'required', 'name' => 'required']);
|
$request->validate(['product' => 'required', 'name' => 'required']);
|
||||||
$item = User::find(\Auth::id())->items()->find(request('item'));
|
$product = User::find(\Auth::id())->products()->find(request('product'));
|
||||||
$item->name = request('name');
|
$product->name = request('name');
|
||||||
$item->save();
|
$product->url = request('url');
|
||||||
return redirect('item/'.request('item'));
|
$product->save();
|
||||||
|
return redirect('product/'.request('product'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
14
resources/views/product/addItemForm.blade.php
Normal file
14
resources/views/product/addItemForm.blade.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<form method="POST" action="/item">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="form-group row mt-2">
|
||||||
|
<div class="col-sm-2 col-lg-1"><label for="product">Item:</label></div>
|
||||||
|
<div class="col-xs-12 col-sm mb-3"><input type="text" class="form-control" name="item" id="item" placeholder="One Hundred Years of Solitude" required></div>
|
||||||
|
<input type="hidden" name="product_id" id="product_id" value="{{ $product['id'] }}" required>
|
||||||
|
<div class="col-sm-2 col-lg-1 mr-4"><button type="submit" class="btn btn-primary">Insert</button></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@include ('layouts.errors')
|
||||||
|
</form>
|
19
resources/views/product/addProductForm.blade.php
Normal file
19
resources/views/product/addProductForm.blade.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<form method="POST" action="/product">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="form-group row mt-2">
|
||||||
|
<div class="col-sm-2 col-lg-1"><label for="product">Name:</label></div>
|
||||||
|
<div class="col-xs-12 col-sm"><input type="text" class="form-control" name="product" id="product" placeholder="Book" required></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mt-2">
|
||||||
|
<div class="col-sm-2 col-lg-1"><label for="product">URL:</label></div>
|
||||||
|
<div class="col-xs-12 col-sm"><input type="text" class="form-control" name="url" id="url" placeholder="http://bookwebsite.com"></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row mt-2">
|
||||||
|
<div class="col-xs-0 col-sm-1 col-md-1 col-lg-1 col-xg-1"></div>
|
||||||
|
<div class="col col-xs-12"><button type="submit" class="btn btn-primary">Insert</button></div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@include ('layouts.errors')
|
||||||
|
</form>
|
@ -1,46 +0,0 @@
|
|||||||
<span class="d-inline-block text-truncat float-right">
|
|
||||||
<div class="btn-group btn-group-sm" role="group">
|
|
||||||
|
|
||||||
|
|
||||||
<!-- EDIT BUTTON -->
|
|
||||||
<form action="/product" method="POST">
|
|
||||||
@method('PATCH')
|
|
||||||
<button type="submit" class="btn btn-sm btn-secondary mr-1">Edit</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- DELETE BUTTON -->
|
|
||||||
<form class="delete" action="/product" method="POST">
|
|
||||||
{{ csrf_field() }}
|
|
||||||
@method('DELETE')
|
|
||||||
<button type="button" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#deleteModal">Delete</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- MODAL - DELETE CONFIRMATION -->
|
|
||||||
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
|
|
||||||
<div class="modal-dialog" role="document">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title" id="deleteModalLabel">Confirmation...</h5>
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
Would you like to delete the product <strong>{{$product->name}}</strong> and it's items?
|
|
||||||
You will not be able to restore it after deletion.
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
||||||
<form class="delete" action="/product" method="POST">
|
|
||||||
{{ csrf_field() }}
|
|
||||||
@method('DELETE')
|
|
||||||
<button type="submit" class="btn btn-danger">Delete</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</span>
|
|
28
resources/views/product/deleteButton.blade.php
Normal file
28
resources/views/product/deleteButton.blade.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<button type="button" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#deleteModal">Delete</button>
|
||||||
|
|
||||||
|
<!-- MODAL - DELETE CONFIRMATION -->
|
||||||
|
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="deleteModalLabel">Confirmation...</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
Would you like to delete the product <strong>{{$product->name}}</strong> and it's items?
|
||||||
|
<p>You will not be able to restore it after deletion.</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||||
|
<form action="/delete" method="POST">
|
||||||
|
@method('DELETE')
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="product" value="{{$product->id}}">
|
||||||
|
<button type="submit" class="btn btn-danger">Delete</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
36
resources/views/product/editButton.blade.php
Normal file
36
resources/views/product/editButton.blade.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<button type="button" class="btn btn-sm btn-secondary mr-1" data-toggle="modal" data-target="#editModal">Edit</button>
|
||||||
|
|
||||||
|
<!-- MODAL - CHANGE WINDOW -->
|
||||||
|
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="editModalLabel">Edit product</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form action="/product" method="POST">
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name" class="col-form-label">New name: </label>
|
||||||
|
<input type="text" name="name" id="name" class="form-control" value="{{$product->name}}">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="url" class="col-form-label">New url: </label>
|
||||||
|
<input type="text" name="url" id="url" class="form-control" value="{{$product->url}}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
@method('PATCH')
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="product" value="{{$product->id}}">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||||
|
<button type="submit" class="btn btn-danger">Edit</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -4,19 +4,8 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
|
|
||||||
<form method="POST" action="/product" class="form-inline">
|
|
||||||
<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" required></div>
|
|
||||||
<div class="col"><button type="submit" class="btn btn-primary">Insert</button></div>
|
|
||||||
</div>
|
|
||||||
@include ('layouts.errors')
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div class="card mt-4">
|
<div class="card mt-4">
|
||||||
<div class="card-header">Products</div>
|
<div class="card-header"><strong>Products</strong></div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@if (session('status'))
|
@if (session('status'))
|
||||||
@ -35,6 +24,11 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card mt-4">
|
||||||
|
<div class="card-header">Add product</div>
|
||||||
|
<div class="card-body">@include('product.addProductForm')</div>
|
||||||
|
</div>
|
||||||
|
<div class="float-right mt-2"><a class="btn btn-secondary" href="/home">Your items</a></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,21 +5,18 @@
|
|||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
|
|
||||||
<form method="POST" action="/item" class="form-inline">
|
|
||||||
<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" required></div>
|
|
||||||
<input type="hidden" name="product_id" id="product_id" value="{{ $product['id'] }}" required>
|
|
||||||
<div class="col"><button type="submit" class="btn btn-primary">Insert</button></div>
|
|
||||||
</div>
|
|
||||||
@include ('layouts.errors')
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div class="card mt-4">
|
<div class="card mt-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
Product: <strong>{{$product['name']}}</strong>
|
<strong>{{$product['name']}}</strong>
|
||||||
@include ('product.buttons')
|
@if ($product['url'])
|
||||||
|
(<em><a href="{{$product['url']}}" target="_blank" rel="noopener noreferrer">{{$product['url']}}</a></em>)
|
||||||
|
@endif
|
||||||
|
<span class="d-inline-block text-truncat float-right">
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
@include ('product.editButton')
|
||||||
|
@include ('product.deleteButton')
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@ -38,6 +35,13 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card mt-4">
|
||||||
|
<div class="card-header">Add item</div>
|
||||||
|
<div class="card-body">@include('product.addItemForm')</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="float-right mt-2"><a class="btn btn-secondary" href="/product">BACK</a></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,6 +18,8 @@ Route::get('/', function () {
|
|||||||
Route::get('/product', 'ProductController@index')->middleware('auth');
|
Route::get('/product', 'ProductController@index')->middleware('auth');
|
||||||
Route::get('/product/{product}', 'ProductController@show')->middleware('auth');
|
Route::get('/product/{product}', 'ProductController@show')->middleware('auth');
|
||||||
Route::post('/product', 'ProductController@store')->middleware('auth');
|
Route::post('/product', 'ProductController@store')->middleware('auth');
|
||||||
|
Route::patch('/product', 'ProductController@patch')->middleware('auth');
|
||||||
|
Route::delete('/product', 'ProductController@delete')->middleware('auth');
|
||||||
|
|
||||||
Route::get('/item', 'ItemController@index')->middleware('auth');
|
Route::get('/item', 'ItemController@index')->middleware('auth');
|
||||||
Route::get('/item/{item}', 'ItemController@show')->middleware('auth');
|
Route::get('/item/{item}', 'ItemController@show')->middleware('auth');
|
||||||
|
Loading…
Reference in New Issue
Block a user