2018-09-09 03:26:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use \App\Product;
|
2018-09-10 04:23:32 +00:00
|
|
|
use \App\User;
|
2018-09-09 03:26:57 +00:00
|
|
|
|
|
|
|
class ProductController extends Controller
|
|
|
|
{
|
|
|
|
//
|
|
|
|
public function index()
|
|
|
|
{
|
2018-09-10 04:23:32 +00:00
|
|
|
$products = Product::where('adminID', \Auth::id())->get();
|
|
|
|
return view('product.index', compact('products'));
|
2018-09-09 03:26:57 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 04:23:32 +00:00
|
|
|
/**
|
|
|
|
* Stores the included product into database
|
|
|
|
*
|
|
|
|
* @return (view) The product view
|
|
|
|
*/
|
|
|
|
public function store()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
$product = new Product;
|
|
|
|
$product->name = request('product');
|
|
|
|
$product->adminID = $userID;
|
|
|
|
$product->save();
|
|
|
|
*/
|
|
|
|
Product::create(['name' => request('product'), 'adminID' => \Auth::id()]); //Just remember to add the fillable on Model to make this work
|
|
|
|
|
|
|
|
return redirect('product');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a specified Product
|
|
|
|
*
|
|
|
|
* @param (int) $id The product id
|
|
|
|
*/
|
|
|
|
public function delete($id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a specified Product
|
|
|
|
*
|
|
|
|
* @param (int) $id The product id
|
|
|
|
*/
|
2018-09-09 03:26:57 +00:00
|
|
|
public function show($id)
|
|
|
|
{
|
2018-09-10 04:23:32 +00:00
|
|
|
$product = Product::find($id);
|
|
|
|
$items = \DB::table('items')
|
|
|
|
->join('products', 'items.productID', '=', 'products.id')
|
|
|
|
->where('products.adminID', \Auth::id())
|
|
|
|
->select('items.*', 'products.*')
|
|
|
|
->get();
|
|
|
|
return view('product.show', compact('items', 'product'));
|
2018-09-09 03:26:57 +00:00
|
|
|
}
|
|
|
|
}
|