Add method for retrieving all players

This commit is contained in:
Pig Fang 2018-07-30 15:45:08 +08:00
parent 6102d27530
commit 7b000bcab0
3 changed files with 30 additions and 0 deletions

View File

@ -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();

View File

@ -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');

View File

@ -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