I have two tables.
usersandcompany. i am using auth for login and registration. and i used user_id fromuserstable as a foreign key incompanytable. To store user_id from session i used hidden input field.
@if (Auth::user())
<input type="hidden" class="form-control" name="userid" value="{{ @Auth::user()->id }}">
@endif
query for insert data in company table.
public function insert(Request $request)
{
$name = $request->input('username');
$id = $request->input('userid');
DB::table('company')->insert(
['com_name' => $name,'id' => $id]
);
return view('home');
}
Now, User will login himself and create multiple companies.Next time when he will login he can see only list of his companies.
In current scenario i have this query but its not worth to used.
public function show(Request $request)
{
$companies = DB::table('company')->where('id', 1)->get();
return view('dashboard', ['users' => $companies]);
}