Reputation: 11
No data shows when i add find(Auth::id()) But with find(1); data retrieves.
Axios script
export default {
data () {
return {
jobs: []
}
},
mounted() {
axios
.get('/api/dashboard')
.then(response => (this.jobs = response.data))
},
}
api.php router
Route::middleware('auth:api')->get('/user', function
(Request
$request) {
return $request->user();
});
Route::resource('dashboard', 'HomeController');
Homecontroller
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\User;
public function index(){
return User::find(Auth::id());
}
No data shows when i add find(Auth::id()) But with find(1); data retrives.
Upvotes: 1
Views: 616
Reputation: 1
Your api.php file is all fine. In your kernel.php file just look for this line \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class and uncomment it, now you can use routes in your api.php to access Auth
Upvotes: 0
Reputation: 11
I have fixed the issue! I think my api.php router having some issue I just switch router file from api.php to web.php and issue fixed. Thank you who took their time to solve the issue.
Upvotes: 0
Reputation: 373
Why are you using Auth::id(); ?
Try to use
User::find(Auth::user()->id);
Upvotes: 1