7-Views - Page 2 of 8 - Developers Blog
How To Debug Queries In Laravel
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.
storage/oauth-private.key does not exist or is not readable
This issue arises when we run API in Laravel app using Passport but the passport package is not installed. The solution is: Go to Command Prompt and go to the project directory and run the following command. php artisan passport:install
How to get the current user in a __construct method of controller
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); }); }
Reverse Geocoding – Get formatted address from latitude and longitude
<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 […]
MySQL – UPDATE query with LIMIT
Many a times there are certain conditions where ou want to update your records with certain limit attached to it. To update multiple rows using limit in MySQL can be implement by a query: UPDATE table_name SET field=’1′ WHERE id IN (SELECT id FROM (SELECT id FROM table_name LIMIT 0, 10) tmp);