php artisan make:auth
を実行してユーザ関連周りを構築しました。
Http/Controllers/.phpでは$request->user()
でユーザ情報を取得できるのですが、
Http/Contollers/api/.phpだと、nullが返ってきてしまいます。
Auth::user()
でも同様です。
apiのコントローラにてユーザ情報を取得し、Modelに渡したいのですが、
どうすれば良いのでしょうか。
routes/api.php
<?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; /* |-------------------------------------------------------------------------- | API Routes |-------------------------------------------------------------------------- | | Here is where you can register API routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | is assigned the "api" middleware group. Enjoy building your API! | */ Route::group(['namespace' => 'API'], function() { Route::get('***/***', '***@***'); Route::get('***/***', '***@***'); Route::post('***/***/***', '***@create'); Route::post('***/***/***', '***@save'); Route::post('***/***/***', '***@update'); });
追加
ログインフォームにてログインした後、apiを使用します。