1

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.

13
  • Did you check dumping data of Auth::id()? Commented Feb 12, 2020 at 9:20
  • Yes By Dumping shows the user data! if access home page data shows there not showing only in vuewjs template Commented Feb 12, 2020 at 9:24
  • Well your index() method does not return anything. Try using return User::find(Auth::id()); Commented Feb 12, 2020 at 9:28
  • Same issue! blank no data Commented Feb 12, 2020 at 9:34
  • Well what was that dumped data? Can you show us? Commented Feb 12, 2020 at 9:38

3 Answers 3

1

Why are you using Auth::id(); ?

Try to use

User::find(Auth::user()->id);
Sign up to request clarification or add additional context in comments.

2 Comments

Error reported on Console with no data!app.js:699 Uncaught (in promise) Error: Request failed with status code 500
I just want to access the data of logged in user. User Profile page you can say to edit.
0

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.

Comments

0

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.