mirror of
https://github.com/brunofontes/shareit.git
synced 2025-11-15 16:00:54 -03:00
Imrpoving Item, Product and Users
This commit is contained in:
@@ -9,15 +9,19 @@ class ItemController extends Controller
|
||||
{
|
||||
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'));
|
||||
$item = \DB::table('items')
|
||||
->join('products', 'items.product_id', '=', 'products.id')
|
||||
->where([['products.admin_id', \Auth::id()], ['items.id', $id]])
|
||||
->select('items.*', 'products.admin_id')
|
||||
->get();
|
||||
$otherItems = Item::where([['product_id', $item[0]->product_id], ['id', '!=', $id]])->get();
|
||||
return view('item', compact('item', 'otherItems'));
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
//TODO: Fazer innerjoint com tabela de users por item
|
||||
$items = Item::where('adminID', \Auth::id())->get();
|
||||
$items = Item::where('admin_id', \Auth::id())->get();
|
||||
return view('item.index', compact('items'));
|
||||
}
|
||||
|
||||
@@ -28,12 +32,18 @@ class ItemController extends Controller
|
||||
*
|
||||
* @return (view) The product view
|
||||
*/
|
||||
public function store()
|
||||
public function store(Request $request)
|
||||
{
|
||||
$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
|
||||
$request->validate(
|
||||
[
|
||||
'item' => 'required',
|
||||
'product_id' => 'required'
|
||||
]
|
||||
);
|
||||
$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]);
|
||||
|
||||
return redirect('product');
|
||||
return redirect('product/'.request('product_id'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user