Skip to content

Commit

Permalink
Merge pull request #65 from kt-321/feature/laravel#62
Browse files Browse the repository at this point in the history
マイプロフィールを更新するAPI作成/Userモデルにてブラックリスト方式に変更し、編集を認めないカラムを設定#62
  • Loading branch information
kt-321 committed Feb 24, 2020
2 parents 7624db8 + ba391d5 commit 370fb31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 9 additions & 2 deletions app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace App\Http\Controllers\Api;


use Illuminate\Http\Request;

use App\Http\Requests\UpdateUserRequest;

use App\User;
use App\Song;
Expand Down Expand Up @@ -61,9 +60,17 @@ public function create(Request $request)
);
return \Route::dispatch($token);
}

// ユーザー一覧取得
public function index(Request $request) {
$users = User::all();
return $users->toJson();
}

// ユーザー情報更新
public function update(UpdateUserRequest $request, $id)
{
$user = User::find($id);
$user->update($request->all());
}
}
7 changes: 5 additions & 2 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ class User extends Authenticatable
*
* @var array
*/
protected $fillable = [
"name", "email", "password", "age", "gender", "image_url", "favorite_music_age", "favorite_artist", "comment",
protected $guarded = [
'id',
'role',
'created_at',
'updated_at'
];

/**
Expand Down
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
Route::group(['middleware' => ['auth:api']], function () {
// ユーザー一覧取得
Route::get('users', 'Api\UsersController@index');
// ユーザー情報更新
Route::put('user/update/{id}', 'Api\UsersController@update');
});

0 comments on commit 370fb31

Please sign in to comment.