mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-23 20:10:52 +00:00
Including Item and Product migration, controllers and models
This commit is contained in:
parent
0eac52c440
commit
fd3e4a67cf
23
app/Http/Controllers/ItemController.php
Normal file
23
app/Http/Controllers/ItemController.php
Normal 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'));
|
||||
}
|
||||
}
|
23
app/Http/Controllers/ProductController.php
Normal file
23
app/Http/Controllers/ProductController.php
Normal 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
18
app/Item.php
Normal 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
10
app/Product.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
//
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
35
database/migrations/2018_09_08_192152_create_items_table.php
Normal file
35
database/migrations/2018_09_08_192152_create_items_table.php
Normal 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');
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
||||
|
7
resources/views/item.blade.php
Normal file
7
resources/views/item.blade.php
Normal file
@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<h1>Item!</h1>
|
||||
<div>
|
||||
@if (isset($item))
|
||||
Item: {{$item}}
|
||||
@endif
|
||||
</html>
|
6
resources/views/product.blade.php
Normal file
6
resources/views/product.blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<h1>Product!</h1>
|
||||
@if (isset($productID))
|
||||
{{$productID}}
|
||||
@endif
|
||||
</html>
|
@ -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');
|
Loading…
Reference in New Issue
Block a user