Make inclusions of the respective user Laravel 5.5 Auth Standard

Asked

Viewed 92 times

1

I have a simple question, I am setting up some registrations for the purpose of studying the framework Aravel, with People, Accounts and etc..

I am using Laravel’s default authentication, and now I have come across the following situation, the registrations of people, and all releases of accounts to pay and receive that I have registered by a respective user is visible to others as well.. I believe it’s because I’m using the method Suppliers::all(); etc.. What should I do to return only the Suppliers that has been registered by this respective user so that it is not visible by all

  • Inside the tables has a field intended to record the id of the user who recorded that record?

  • @Virgilionovic I was checking it out right now! I just need to have the user ID in the register of people, that the other tables are already related, but in Personcontroller@store I am using request->all(), as I do for only the id_user field to be filled automatically with the id of the respective logged in user?

  • Auto::user()->id would be that

  • @Virgilionovic would look like this $person = Person::create($request->all(Auto::user()->id));

  • Inside the person table has the user id field or equivalent?

  • Yes, I just modified it, I inserted a user_id column as a foreign key to the user table id, and I already set up hasMany and Belongsto

  • Vendors::Where('user_id', Auth::user()->id)

Show 2 more comments

1 answer

1


You can put the logged in user in the store method in your controller. for example:

$data = $request->all();
$data['user_id'] = Auth::user()->id;

$pessoa = Pessoa::create($data);

And when you go and find the suppliers that belong to the person, you can do it that way:

$fornecedores = App\Fornecedor::with(['pessoa' => function ($query) {
    $query->where('user_id', '=', Auth::user()->id);
}])->get();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.