Add method for retrieving all players
This commit is contained in:
parent
6102d27530
commit
7b000bcab0
@ -55,6 +55,14 @@ class PlayerController extends Controller
|
||||
->with('user', $user);
|
||||
}
|
||||
|
||||
public function listAll()
|
||||
{
|
||||
return Auth::user()
|
||||
->players()
|
||||
->select('pid', 'player_name', 'preference', 'tid_steve', 'tid_alex')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
@ -54,6 +54,7 @@ Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'user'], function ()
|
||||
|
||||
// Player
|
||||
Route::any ('/player', 'PlayerController@index');
|
||||
Route::get ('/player/list', 'PlayerController@listAll');
|
||||
Route::post('/player/add', 'PlayerController@add');
|
||||
Route::any ('/player/show', 'PlayerController@show');
|
||||
Route::post('/player/preference', 'PlayerController@setPreference');
|
||||
|
@ -25,6 +25,27 @@ class PlayerControllerTest extends TestCase
|
||||
->assertViewHas('user');
|
||||
}
|
||||
|
||||
public function testListAll()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$default = factory(Player::class)->create(['uid' => $user->uid]);
|
||||
$slim = factory(Player::class, 'slim')->create(['uid' => $user->uid]);
|
||||
$this->actingAs($user)
|
||||
->get('/user/player/list')
|
||||
->assertJson([
|
||||
[
|
||||
'pid' => $default->pid,
|
||||
'player_name' => $default->player_name,
|
||||
'preference' => $default->preference,
|
||||
],
|
||||
[
|
||||
'pid' => $slim->pid,
|
||||
'player_name' => $slim->player_name,
|
||||
'preference' => $slim->preference,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
// Without player name
|
||||
|
Loading…
Reference in New Issue
Block a user