mirror of
https://github.com/brunofontes/shareit.git
synced 2025-01-18 14:30:47 +00:00
Including occupied username and renaming DB field
Now it shows the username of who is using an item. Item db field 'usedBy' was renamed to 'used_by' to keep consistence.
This commit is contained in:
parent
925c378d1e
commit
ea3ffaad39
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use \App\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class HomeController extends Controller
|
class HomeController extends Controller
|
||||||
@ -23,7 +24,17 @@ class HomeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$items = \App\User::find(\Auth::id())->items()->get();
|
$items = User::find(\Auth::id())->items()->get();
|
||||||
return view('home', compact('items'));
|
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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class ReturnController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$item = User::find(\Auth::id())->items()->find(request('item'));
|
$item = User::find(\Auth::id())->items()->find(request('item'));
|
||||||
$item->usedBy = null;
|
$item->used_by = null;
|
||||||
$item->save();
|
$item->save();
|
||||||
|
|
||||||
return redirect('home');
|
return redirect('home');
|
||||||
|
@ -11,7 +11,7 @@ class TakeController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$item = User::find(\Auth::id())->items()->find(request('item'));
|
$item = User::find(\Auth::id())->items()->find(request('item'));
|
||||||
$item->usedBy = \Auth::id();
|
$item->used_by = \Auth::id();
|
||||||
$item->save();
|
$item->save();
|
||||||
return redirect('home');
|
return redirect('home');
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class UserController extends Controller
|
|||||||
|
|
||||||
if ($item->product->user_id == \Auth::id()) {
|
if ($item->product->user_id == \Auth::id()) {
|
||||||
$returnItem = User::findOrFail(request('user_id'))->items()->findOrFail(request('item_id'));
|
$returnItem = User::findOrFail(request('user_id'))->items()->findOrFail(request('item_id'));
|
||||||
$returnItem->usedBy = null;
|
$returnItem->used_by = null;
|
||||||
$returnItem->save();
|
$returnItem->save();
|
||||||
User::findOrFail(request('user_id'))->items()->detach([request('item_id')]);
|
User::findOrFail(request('user_id'))->items()->detach([request('item_id')]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +23,7 @@ class Item extends Model
|
|||||||
return $query->where([
|
return $query->where([
|
||||||
['user_id', $user_id],
|
['user_id', $user_id],
|
||||||
['product_id', $product_id],
|
['product_id', $product_id],
|
||||||
['usedBy', ''],
|
['used_by', ''],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ class CreateItemsTable extends Migration
|
|||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->integer('product_id');
|
$table->integer('product_id');
|
||||||
$table->integer('usedBy')->nullable();
|
$table->integer('used_by')->nullable();
|
||||||
$table->dateTime('usedSince')->nullable();
|
$table->integer('waiting_user_id')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ Cada usuário, identificado por e-mail, pode ter outros amigos
|
|||||||
[x] usuário(nome, email)
|
[x] usuário(nome, email)
|
||||||
[x] product[site/software](nome, admin)
|
[x] product[site/software](nome, admin)
|
||||||
[ ] usersPerItem(productID, userID)
|
[ ] usersPerItem(productID, userID)
|
||||||
[x] item[licença](nome, productID, usedBy, usedSince)
|
[x] item[licença](nome, productID, used_by, usedSince)
|
||||||
[ ] waiting(userID, itemID, waitingSince)
|
[ ] waiting(userID, itemID, waitingSince)
|
||||||
|
|
||||||
## VIEWS
|
## VIEWS
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">Dashboard</div>
|
<div class="card-header"><h3>Your items</h3></div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@if (session('status'))
|
@if (session('status'))
|
||||||
@ -14,37 +14,21 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<h4>Your itens</h4>
|
|
||||||
@forelse ($items as $item)
|
@forelse ($items as $item)
|
||||||
<hr class="ml-5 mr-5">
|
@if (!$loop->first)
|
||||||
<li class="mt-1 mb-1">
|
<hr class="m-3">
|
||||||
|
@endif
|
||||||
|
<div class="my-4 p-2">
|
||||||
<strong>{{$item->name}}</strong> ({{$item->product->name}})
|
<strong>{{$item->name}}</strong> ({{$item->product->name}})
|
||||||
|
|
||||||
@if ($item->usedBy)
|
@if ($item->used_by)
|
||||||
@if ($item->usedBy == \Auth::id())
|
@include('home.usedItem')
|
||||||
<span class="float-right">
|
|
||||||
<form action="/return" method="POST">
|
|
||||||
{{ csrf_field() }}
|
|
||||||
<input type="hidden" name="item" value="{{$item->id}}">
|
|
||||||
<button type="submit" class="btn-xm btn-danger">Return It</button>
|
|
||||||
</form>
|
|
||||||
</span>
|
|
||||||
<span class="float-right mr-3"><em>{{\Carbon\Carbon::parse($item->updated_at)->diffForHumans()}}</em></span>
|
|
||||||
@else
|
|
||||||
<div class="alert alert-danger" role="alert">In use by {{$item->usedBy}}, since {{$item->updated_at->diffForHumans()}}</div>
|
|
||||||
@endif
|
|
||||||
@else
|
@else
|
||||||
<span class="float-right">
|
@include('home.unusedItem')
|
||||||
<form action="/take" method="POST">
|
|
||||||
{{ csrf_field() }}
|
|
||||||
<input type="hidden" name="item" value="{{$item->id}}">
|
|
||||||
<button type="submit" class="btn-xm btn-success">Take It</button>
|
|
||||||
</form>
|
|
||||||
</span>
|
|
||||||
@endif
|
@endif
|
||||||
</li>
|
</div>
|
||||||
@empty
|
@empty
|
||||||
<p>There are no items for you yet. Include a product or an item <a href="/product">here.</a></p>
|
<p>There are no items shared with you yet. <a href="/product">Share an item!</a></p>
|
||||||
@endforelse
|
@endforelse
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
7
resources/views/home/unusedItem.blade.php
Normal file
7
resources/views/home/unusedItem.blade.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<span class="float-right">
|
||||||
|
<form action="/take" method="POST">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="item" value="{{$item->id}}">
|
||||||
|
<button type="submit" class="btn btn-sm btn-success">Take It</button>
|
||||||
|
</form>
|
||||||
|
</span>
|
21
resources/views/home/usedItem.blade.php
Normal file
21
resources/views/home/usedItem.blade.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
@if ($item->used_by == \Auth::id())
|
||||||
|
<span class="float-right">
|
||||||
|
<form action="/return" method="POST">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="item" value="{{$item->id}}">
|
||||||
|
<button type="submit" class="btn btn-sm btn-danger">Return It</button>
|
||||||
|
</form>
|
||||||
|
</span>
|
||||||
|
<span class="float-right mr-3"><em>{{\Carbon\Carbon::parse($item->updated_at)->diffForHumans()}}</em></span>
|
||||||
|
@else
|
||||||
|
<span class="float-right">
|
||||||
|
<form action="/alert" method="POST">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="item" value="{{$item->id}}">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-secondary">Alert me</button>
|
||||||
|
</form>
|
||||||
|
</span>
|
||||||
|
<span class="float-right mr-3">
|
||||||
|
<em>{{str_limit($users[$item->used_by], 15, '...')}} ({{$item->updated_at->diffForHumans()}})</em>
|
||||||
|
</span>
|
||||||
|
@endif
|
@ -19,7 +19,7 @@
|
|||||||
<strong>Other items from the same product:</strong>
|
<strong>Other items from the same product:</strong>
|
||||||
<ul>
|
<ul>
|
||||||
@forelse ($otherItems as $otherItem)
|
@forelse ($otherItems as $otherItem)
|
||||||
@if (!$otherItem->usedBy)
|
@if (!$otherItem->used_by)
|
||||||
<li><a href="/item/{{ $otherItem->id }}">{{ $otherItem->name }}</a></li>
|
<li><a href="/item/{{ $otherItem->id }}">{{ $otherItem->name }}</a></li>
|
||||||
@endif
|
@endif
|
||||||
@empty
|
@empty
|
||||||
|
Loading…
Reference in New Issue
Block a user