简体   繁体   English

laravel vuejs 和 axios 没有数据显示与 auth 用户

[英]laravel vuejs and axios no data shows with auth user

No data shows when i add find(Auth::id()) But with find(1);当我添加 find(Auth::id()) 时没有数据显示但是使用 find(1); data retrieves.数据检索。

Axios script axios 脚本

export default {
  data () {
return {
 jobs: []
}
  },
mounted() {
    axios
  .get('/api/dashboard')
  .then(response => (this.jobs = response.data))
     },
}

api.php router api.php 路由器

    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);当我添加 find(Auth::id()) 时没有数据显示但是使用 find(1); data retrives.数据恢复。

Why are you using Auth::id();你为什么使用 Auth::id(); ? ?

Try to use尝试使用

User::find(Auth::user()->id);

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.我认为我的 api.php 路由器有一些问题,我只是将路由器文件从 api.php 切换到 web.php 并修复了问题。 Thank you who took their time to solve the issue.感谢您花时间解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM