我正在制作laravel api,并希望将user_id存储在数据库中,但它提供了非对象,我在laravel的home控制器中获取了user_id,但在api控制器中却没有获取id,请帮助我如何解决此类错误在laravel中
api / blogController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use Session;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$userdata = Auth::user();
// return $userdata;
Session::put('login_user_id',Auth::user()->id);
$uid = Session::get('login_user_id');
dd($uid);
exit;
return view('home');
}
}
api.php
Route::group(['middleware' => ['api']], function () {
Route::post('blog', 'BlogController@storeBlog');});