1

i have a laravel app that uses laravel passport and vue.js for the front-end. Currently when i show a list from the database it shows all the elements of the table and i want it to show me only the data from the current user

I've seen that this function is made in the controller

public function index()
{
    $prospect = prospect::all();

    return $prospect;
}

In the database table i have a variable 'Salesman' that equals to the variable 'first' of current user

do you now how can i achieve this?

Ersoy
  • 8,816
  • 6
  • 34
  • 48

1 Answers1

1

If the route is inside an 'auth' middleware, you should be able to use the Auth facade, and limit your query as so:

public function index() {
    $prospects = Prospect::where('user_id', Auth::id())->get();
    return $prospects;
}
D. Petrov
  • 1,147
  • 15
  • 27
JoeGalind
  • 3,545
  • 2
  • 29
  • 33