mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-24 04:14:57 +00:00
Refactoring homeController code
This commit is contained in:
parent
9f67cbcbeb
commit
c1b4ac419d
@ -23,13 +23,7 @@ class HomeController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$items = \DB::table('items')
|
$items = \App\User::find(\Auth::id())->items()->get();
|
||||||
->join('item_user', 'item_user.item_id', '=', 'items.id')
|
|
||||||
->join('products', 'products.id', '=', 'items.id')
|
|
||||||
->where('item_user.user_id', \Auth::id())
|
|
||||||
->select('items.*', 'products.name as pname')
|
|
||||||
->orderBy('items.name')
|
|
||||||
->get();
|
|
||||||
return view('home', compact('items'));
|
return view('home', compact('items'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,23 +16,29 @@
|
|||||||
|
|
||||||
<h4>Your itens</h4>
|
<h4>Your itens</h4>
|
||||||
@forelse ($items as $item)
|
@forelse ($items as $item)
|
||||||
<li>
|
<hr class="ml-5 mr-5">
|
||||||
<strong>{{$item->name}}</strong> ({{$item->pname}})
|
<li class="mt-1 mb-1">
|
||||||
|
<strong>{{$item->name}}</strong> ({{$item->product->name}})
|
||||||
|
|
||||||
@if ($item->usedBy)
|
@if ($item->usedBy)
|
||||||
@if ($item->usedBy == \Auth::id())
|
@if ($item->usedBy == \Auth::id())
|
||||||
<span class="float-right">
|
<span class="float-right">
|
||||||
<form action="/item/{{$item->id}}" method="POST">
|
<form action="/return" method="POST">
|
||||||
<button type="button" class="btn btn-danger" disabled>Return It</button>
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="item" value="{{$item->id}}">
|
||||||
|
<button type="submit" class="btn-xm btn-danger">Return It</button>
|
||||||
</form>
|
</form>
|
||||||
</span>
|
</span>
|
||||||
|
<span class="float-right mr-3"><em>{{\Carbon\Carbon::parse($item->updated_at)->diffForHumans()}}</em></span>
|
||||||
@else
|
@else
|
||||||
<div class="alert alert-danger" role="alert">In use by {{$item->usedBy}}, since {{$item->usedSince->diffForHumans()}}</div>
|
<div class="alert alert-danger" role="alert">In use by {{$item->usedBy}}, since {{$item->updated_at->diffForHumans()}}</div>
|
||||||
@endif
|
@endif
|
||||||
@else
|
@else
|
||||||
<span class="float-right">
|
<span class="float-right">
|
||||||
<form action="/item/{{$item->id}}" method="POST">
|
<form action="/take" method="POST">
|
||||||
<button type="button" class="btn btn-success">Take It</button>
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" name="item" value="{{$item->id}}">
|
||||||
|
<button type="submit" class="btn-xm btn-success">Take It</button>
|
||||||
</form>
|
</form>
|
||||||
</span>
|
</span>
|
||||||
@endif
|
@endif
|
||||||
|
Loading…
Reference in New Issue
Block a user