Make inclusion of the respective user Laravel 5.5 Auth Default

1

I have a simple question, I am putting together some registers for the purpose of studying the laravel framework, with People, Chart of Accounts and etc.

I'm using Laravel's default authentication, and now I came across the following situation, people's records, and all postings of accounts payable and receivable that I registered for a respective user is visible to others as well .. I believe

I am using the Suppliers :: all (); etc method. What should I do to return only the Suppliers that have been registered by this respective user so that it is not visible by all

    
asked by anonymous 27.02.2018 / 13:16

1 answer

1

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

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

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

And when you fetch the vendors that belong to the person, you can do it this way:

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