7-Views - Page 2 of 8 - Developers Blog

How To Debug Queries In Laravel

Posted by
January 31, 2021

We can do this by #1 Simple Query Debugging $results = User::where(function($q) use ($request) { $q->orWhere(‘name’, ‘like’, ‘%7-Views%’); $q->orWhere(’email’, ‘=’, ‘info@7-views.com’); })->toSql(); The above method does not include query bindings. #2 Listening For Query Events \DB::listen(function($sql, $bindings, $time) { dump($sql); dump($bindings); dump($time); }); This method returns queries with timings and bindings.        

read more

How to get the current user in a __construct method of controller

Posted by
January 31, 2021

This issue arises because the controller __construct method executes before any middleware. so it returns null when we call auth()->user() So the solution of the issue is, inside your Controller __construct method call this. public function __construct() { $this->middleware(function ($request, $next) { dump(auth()->user()); return $next($request); }); }  

read more

Reverse Geocoding – Get formatted address from latitude and longitude

Posted by
July 3, 2020

<script> function getmylocation(lat, lng) { var currAddress, addtress= []; var geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(lat, lng); if (geocoder) { geocoder.geocode({‘latLng’: latlng}, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { currAddress = results[0].formatted_address; addtress.push(currAddress ); } else { alert(‘No results found’); } } else { alert(‘Geocoder failed due […]

read more