I'm searching for the best supported/secure approach to capture visitors Ip address.
At the moment I'm able to save visitor Ip by the following approach
Route from which call is made.
Route::get('/','VisitorController@multidisplay');
In multidisplay function, I'm calling another controller to capture and store Visitor Ip like->
public function multidisplay()
{
//calling log visitor controller
app()->call('App\Http\Controllers\LogVisitIpController@store');
return view('welcome')
->with('sliderimg', Sliderimage::all())
->with('postimg', PostImage::orderBy('created_at', 'desc')->take(3)->get())
;
}
and finally, the actual function to store visitor's Ip in LogVisitIpController
public function store(Request $request)
{
$bla=$this->getIp();
$myvisitor = new LogVisitIp();
$myvisitor->visitorIp=$bla;
$myvisitor->save();
}
Now i have two question.
Is it ok to use a controller like that in another controller?
Should I use another approach to capture visitor ip using one controller?
Note: VisitorController is used to save request from the visitors in DB and send mail, I can collect IP and pass it from the visitor's request but my aim is to capture Ip as soon as the visitor open my website or make a ping request.