mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-24 04:14:57 +00:00
Including Item Delete
This commit is contained in:
parent
c1b4ac419d
commit
1408e558d7
@ -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
|
$user = \App\User::find(\Auth::id());
|
||||||
\DB::table('item_user')->insert([ 'user_id' => \Auth::id(), 'item_id' => $id]);
|
$user->items()->create(['name' => request('item'), 'product_id' => request('product_id')]);
|
||||||
|
|
||||||
return redirect('product/'.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 -->
|
<!-- DELETE BUTTON -->
|
||||||
<form action="/item/{{$item->id}}" method="POST">
|
<form action="/item/" method="POST">
|
||||||
@method('DELETE')
|
@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>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user