Including Item and Product migration, controllers and models

This commit is contained in:
Bruno F. Fontes 2018-09-09 00:26:57 -03:00
parent 0eac52c440
commit fd3e4a67cf
10 changed files with 160 additions and 9 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \App\Item;
class ItemController extends Controller
{
//
public function index()
{
//$item = Item::all();
//return $item; //Show a JSON file instead of the view
return view('item');
}
public function show($id)
{
$item = Item::find($id);
return view('item', compact('item'));
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \App\Product;
class ProductController extends Controller
{
//
public function index()
{
//$product = Product::all();
return view('product');
}
public function show($id)
{
//$productID = Product::find($id);
$productID = $id;
return view('product', compact('productID'));
}
}

18
app/Item.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
{
//
public function free($productID)
{
return $query->where([
['productID', $productID],
['usedBy', ''],
]);
}
}

10
app/Product.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
//
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('adminID');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('items', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('productID');
$table->integer('usedBy');
$table->dateTime('usedSince');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('items');
}
}

View File

@ -6,7 +6,7 @@ Cada usuário, identificado por e-mail, pode ter outros amigos
usuário(nome, email)
product[site/software](nome, admin)
userPerProduct(productID, userID)
productUsers(productID, userID)
item[licença](nome, productID, usedBy, usedSince)
waiting(userID, itemID, waitingSince)

View File

@ -0,0 +1,7 @@
<html>
<h1>Item!</h1>
<div>
@if (isset($item))
Item: {{$item}}
@endif
</html>

View File

@ -0,0 +1,6 @@
<html>
<h1>Product!</h1>
@if (isset($productID))
{{$productID}}
@endif
</html>

View File

@ -16,11 +16,7 @@ Route::get('/', function () {
return view('welcome', compact('name'));
});
Route::get('/product/{id}', function () {
$productID = DB::table('product')->find($id);
return view('product', compact['productID']);
});
Route::get('/item/{id}', function () {
return view('item');
});
Route::get('/product', 'ProductController@index');
Route::get('/product/{product}', 'ProductController@show');
Route::get('/item', 'ItemController@index');
Route::get('/item/{item}', 'ItemController@show');