mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-23 20:10:52 +00:00
Including Item Delete
This commit is contained in:
parent
a3fe6f719d
commit
52eda15057
@ -39,10 +39,19 @@ class ItemController extends Controller
|
||||
]
|
||||
);
|
||||
|
||||
$id = Item::insertGetId(['name' => request('item'), 'product_id' => request('product_id')]); //Just remember to add the fillable on Model to make this work
|
||||
\DB::table('item_user')->insert([ 'user_id' => \Auth::id(), 'item_id' => $id]);
|
||||
$user = \App\User::find(\Auth::id());
|
||||
$user->items()->create(['name' => request('item'), 'product_id' => request('product_id')]);
|
||||
|
||||
return redirect('product/'.request('product_id'));
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$request->validate(['item' => 'required']);
|
||||
$item = \App\User::find(\Auth::id())->items()->find(request('item'));
|
||||
$product = $item->product_id;
|
||||
$item->delete();
|
||||
return redirect('product/' . $product);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,9 +12,11 @@
|
||||
|
||||
|
||||
<!-- DELETE BUTTON -->
|
||||
<form action="/item/{{$item->id}}" method="POST">
|
||||
<form action="/item/" method="POST">
|
||||
@method('DELETE')
|
||||
<button type="button" class="btn-sm btn-danger">Delete</button>
|
||||
{{ csrf_field() }}
|
||||
<input type="hidden" name="item" value="{{$item->id}}">
|
||||
<button type="submit" class="btn-sm btn-danger">Delete</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user