Adding Take and Return controllers

This commit is contained in:
Bruno F. Fontes 2018-09-12 21:27:35 -03:00
parent 52eda15057
commit 9debf5548c
3 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers;
use \App\User;
use Illuminate\Http\Request;
class ReturnController extends Controller
{
public function store(Request $request)
{
$item = User::find(\Auth::id())->items()->find(request('item'));
$item->usedBy = null;
$item->save();
return redirect('home');
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers;
use \App\Item;
use \App\User;
use Illuminate\Http\Request;
class TakeController extends Controller
{
public function store(Request $request)
{
$item = User::find(\Auth::id())->items()->find(request('item'));
$item->usedBy = \Auth::id();
$item->save();
return redirect('home');
}
}

View File

@ -22,7 +22,10 @@ Route::post('/product', 'ProductController@store')->middleware('auth');
Route::get('/item', 'ItemController@index')->middleware('auth'); Route::get('/item', 'ItemController@index')->middleware('auth');
Route::get('/item/{item}', 'ItemController@show')->middleware('auth'); Route::get('/item/{item}', 'ItemController@show')->middleware('auth');
Route::post('/item', 'ItemController@store')->middleware('auth'); Route::post('/item', 'ItemController@store')->middleware('auth');
Route::delete('/item/{item}', 'ItemController@delete')->middleware('auth'); Route::delete('/item', 'ItemController@delete')->middleware('auth');
Route::post('/take', 'TakeController@store')->middleware('auth');
Route::post('/return', 'ReturnController@store')->middleware('auth');
Auth::routes(); Auth::routes();