diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a4407f2..0c77010 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use \App\User; use Illuminate\Http\Request; class HomeController extends Controller @@ -23,7 +24,17 @@ class HomeController extends Controller */ public function index() { - $items = \App\User::find(\Auth::id())->items()->get(); - return view('home', compact('items')); + $items = User::find(\Auth::id())->items()->get(); + foreach ($items as $item) { + + if ($item->used_by) { + $users[$item->used_by] = User::find($item->used_by)->name; + + if ($item->waiting_user_id) { + $users[$item->waiting_user_id] = User::find($item->waiting_user_id)->name; + } + } + } + return view('home', compact('items', 'users')); } } diff --git a/app/Http/Controllers/ReturnController.php b/app/Http/Controllers/ReturnController.php index 4643f24..d0acd62 100644 --- a/app/Http/Controllers/ReturnController.php +++ b/app/Http/Controllers/ReturnController.php @@ -10,7 +10,7 @@ class ReturnController extends Controller public function store(Request $request) { $item = User::find(\Auth::id())->items()->find(request('item')); - $item->usedBy = null; + $item->used_by = null; $item->save(); return redirect('home'); diff --git a/app/Http/Controllers/TakeController.php b/app/Http/Controllers/TakeController.php index bf84b53..ab30be1 100644 --- a/app/Http/Controllers/TakeController.php +++ b/app/Http/Controllers/TakeController.php @@ -11,7 +11,7 @@ class TakeController extends Controller public function store(Request $request) { $item = User::find(\Auth::id())->items()->find(request('item')); - $item->usedBy = \Auth::id(); + $item->used_by = \Auth::id(); $item->save(); return redirect('home'); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 070a4e0..8d81573 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -68,7 +68,7 @@ class UserController extends Controller if ($item->product->user_id == \Auth::id()) { $returnItem = User::findOrFail(request('user_id'))->items()->findOrFail(request('item_id')); - $returnItem->usedBy = null; + $returnItem->used_by = null; $returnItem->save(); User::findOrFail(request('user_id'))->items()->detach([request('item_id')]); } else { diff --git a/app/Item.php b/app/Item.php index ba75eeb..23dfbb4 100644 --- a/app/Item.php +++ b/app/Item.php @@ -23,7 +23,7 @@ class Item extends Model return $query->where([ ['user_id', $user_id], ['product_id', $product_id], - ['usedBy', ''], + ['used_by', ''], ]); } diff --git a/database/migrations/2018_09_08_192152_create_items_table.php b/database/migrations/2018_09_08_192152_create_items_table.php index 4cb3e6c..294d932 100644 --- a/database/migrations/2018_09_08_192152_create_items_table.php +++ b/database/migrations/2018_09_08_192152_create_items_table.php @@ -17,8 +17,8 @@ class CreateItemsTable extends Migration $table->increments('id'); $table->string('name'); $table->integer('product_id'); - $table->integer('usedBy')->nullable(); - $table->dateTime('usedSince')->nullable(); + $table->integer('used_by')->nullable(); + $table->integer('waiting_user_id')->nullable(); $table->timestamps(); }); } diff --git a/readme.md b/readme.md index 48b57b5..6f0d6ed 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ Cada usuário, identificado por e-mail, pode ter outros amigos [x] usuário(nome, email) [x] product[site/software](nome, admin) [ ] usersPerItem(productID, userID) -[x] item[licença](nome, productID, usedBy, usedSince) +[x] item[licença](nome, productID, used_by, usedSince) [ ] waiting(userID, itemID, waitingSince) ## VIEWS diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 5d17104..0347eda 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -5,7 +5,7 @@
There are no items for you yet. Include a product or an item here.
+There are no items shared with you yet. Share an item!
@endforelse