mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-24 04:14:57 +00:00
Including Items and Products views and controllers
This commit is contained in:
parent
112d3dc44e
commit
25cff75c48
@ -23,6 +23,7 @@ class HomeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return view('home');
|
$items = \App\Item::where('userID');
|
||||||
|
return view('home', compact('items'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class ItemController extends Controller
|
|||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$item = Item::find($id);
|
$item = Item::where([['id', $id], ['userID', \Auth::id()]]);
|
||||||
return view('item', compact('item'));
|
return view('item', compact('item'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,57 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use \App\Product;
|
use \App\Product;
|
||||||
|
use \App\User;
|
||||||
|
|
||||||
class ProductController extends Controller
|
class ProductController extends Controller
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
//$product = Product::all();
|
$products = Product::where('adminID', \Auth::id())->get();
|
||||||
return view('product');
|
return view('product.index', compact('products'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
//$productID = Product::find($id);
|
$product = Product::find($id);
|
||||||
$productID = $id;
|
$items = \DB::table('items')
|
||||||
return view('product', compact('productID'));
|
->join('products', 'items.productID', '=', 'products.id')
|
||||||
|
->where('products.adminID', \Auth::id())
|
||||||
|
->select('items.*', 'products.*')
|
||||||
|
->get();
|
||||||
|
return view('product.show', compact('items', 'product'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class Item extends Model
|
class Item extends Model
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
public function free($productID)
|
public function free($productID, $userID)
|
||||||
{
|
{
|
||||||
return $query->where([
|
return $query->where([
|
||||||
|
['userID', $userID],
|
||||||
['productID', $productID],
|
['productID', $productID],
|
||||||
['usedBy', ''],
|
['usedBy', ''],
|
||||||
]);
|
]);
|
||||||
|
@ -6,5 +6,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
|
|
||||||
class Product extends Model
|
class Product extends Model
|
||||||
{
|
{
|
||||||
|
protected $fillable = ['adminID', 'name'];
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,12 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
You are logged in!
|
<h4>Your itens</h4>
|
||||||
|
@forelse ($items as $item)
|
||||||
|
<li>{{$item.name}}</li>
|
||||||
|
@empty
|
||||||
|
<p>There are no items for you yet. Include one <a href="/product">here.</a></p>
|
||||||
|
@endforelse
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
41
resources/views/product/index.blade.php
Normal file
41
resources/views/product/index.blade.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<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"></div>
|
||||||
|
<div class="col"><button type="submit" class="btn btn-primary">Insert</button></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<p><br></p>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">Products</div>
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
{{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
@forelse ($products as $product)
|
||||||
|
<li><a href="/product/{{$product['id']}}">{{$product['name']}}</a></li>
|
||||||
|
@empty
|
||||||
|
<p>There are no products yet. Include one with the form above.</p>
|
||||||
|
@endforelse
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
43
resources/views/product/show.blade.php
Normal file
43
resources/views/product/show.blade.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<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"></div>
|
||||||
|
<div class="col"><button type="submit" class="btn btn-primary">Insert</button></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<p><br></p>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
Product: <strong>{{$product['name']}}</strong>
|
||||||
|
<span class="d-inline-block text-truncat float-right">Edit - Delete</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="alert alert-success" role="alert"> {{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
@forelse ($items as $item)
|
||||||
|
<li><a href="/product/{{$item['id']}}">{{$item['name']}}</a></li>
|
||||||
|
@empty
|
||||||
|
<p>There are no items yet. Include one with the form above.</p>
|
||||||
|
@endforelse
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
@ -15,10 +15,11 @@ Route::get('/', function () {
|
|||||||
return view('welcome');
|
return view('welcome');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/product', 'ProductController@index');
|
Route::get('/product', 'ProductController@index')->middleware('auth');
|
||||||
Route::get('/product/{product}', 'ProductController@show');
|
Route::get('/product/{product}', 'ProductController@show')->middleware('auth');
|
||||||
Route::get('/item', 'ItemController@index');
|
Route::post('/product', 'ProductController@store')->middleware('auth');
|
||||||
Route::get('/item/{item}', 'ItemController@show');
|
Route::get('/item', 'ItemController@index')->middleware('auth');
|
||||||
|
Route::get('/item/{item}', 'ItemController@show')->middleware('auth');
|
||||||
Auth::routes();
|
Auth::routes();
|
||||||
|
|
||||||
Route::get('/home', 'HomeController@index')->name('home');
|
Route::get('/home', 'HomeController@index')->name('home')->middleware('auth');
|
||||||
|
Loading…
Reference in New Issue
Block a user