Skip to main content

Posts

Showing posts with the label Laravel

PHP str_pad, Laravel PHP static function call

https://www.php.net/manual/en/function.str-pad.php Useful when for example add 0000 prefix to and ID (int) STR_PAD_LEFT / RIGHT https://www.w3resource.com/mysql/string-functions/mysql-lpad-function.php https://stackoverflow.com/questions/3446538/cleanest-way-to-skip-a-foreach-if-array-is-empty https://laravel.io/forum/07-28-2014-error-using-this-when-not-in-object-context $table is an instance variable, not a static variable, so you can't use it in a static function (basic PHP). Damn basic PHP that I miss, and many interview question asked this shit. Yeah, update Model func remove static and update Controller call: // Model public function findMyReviewedShop()  {} // Controller $data = (new AreaModel)->findMyReviewedShop($user_id, $area_id); // instead of :: https://stackoverflow.com/questions/34947862/how-to-use-hasmanythrough-with-more-than-3-tables-in-laravel Questions: 1. Is relation query return all related data ? ie. review->shopdata ... This is...

Notes on Redis Laravel

Actual data store and cache should be synchronized using the third approach you've already described in your question. As you add data to your definitive store (i.e. your SQL database), you need to enqueue this data to some service bus or message queue, and let some asynchronous service do the whole synchronization using some kind of background process. You don't want get into this cases (when not using a service bus and asynchronous service): - Make your requests or processes slower because the user needs to wait until the data is both stored in your database and cache. - Have the risk of a fail during the caching process and not being able to have a retry policy (which is usually a built-in feature in a service bus or some message queues). Also, this failure can end up in a partial or complete cache corruption and you won't be able to automatically and easily schedule some task to fix this situation. BTW, you won't be always on this case (if a key isn't ex...

Refactoring, Eloquent load vs with etc.

https://martinfowler.com/bliki/RefactoringMalapropism.html https://martinfowler.com/tags/refactoring.html https://stackoverflow.com/questions/26005994/laravel-with-method-versus-load-method Damn dump dd Laravel     "review" => array:5 [       0 => array:10 [ …10]       1 => array:10 [ …10]       2 => array:10 [ …10]       3 => array:10 [ …10]       4 => array:10 [ …10]     ] It seem clever to wrapping long array to look like above. But when I search for a missing record ID, it not show here. So I have to debug to figure out why it is missing in the first dump but show on latter result. https://www.owasp.org/index.php/SQL_Injection_Bypassing_WAF https://github.com/Intervention/image https://github.com/itsgoingd/clockwork composer pheanstalk https://duo.com/labs/research/apple-t2-xpc https://stac...

WP tuning p2 (API), Lumen, Laravel codepipeline Beanstalk

https://deliciousbrains.com/comparing-wordpress-rest-api-performance-admin-ajax-php/ https://stackoverflow.com/questions/3338220/how-to-simulate-high-traffic-load-on-a-web-application http://www.opensourcetesting.org/category/performance/page/2/ https://jmeter.apache.org/usermanual/get-started.html#non_gui curl -sH 'X-Papertrail-Token: YOUR-HTTP-API-KEY' https://papertrailapp.com/api/v1/archives.json |   grep -o '"filename":"[^"]*"' | egrep -o '[0-9-]+' |   awk '$0 >= "YYYY-MM-DD" && $0 < "YYYY-MM-DD" {     print "output " $0 ".tsv.gz"     print "url https://papertrailapp.com/api/v1/archives/" $0 "/download"   }' | curl --progress-bar -fLH 'X-Papertrail-Token: YOUR-HTTP-API-KEY' -K- https://help.papertrailapp.com/kb/how-it-works/permanent-log-archives/#usage-example https://medium.com/@avishayil/deploy-to-elastic-beanstalk-using-bitbuc...

Note some Laravel, NGINX, NodeJS deploy

Avoid/reduce log output on Laravel Console https://stackoverflow.com/questions/49346700/laravel-disable-artisan-console-output-when-running-tests Gcloud SSH issue Jun 20 06:37:18 instance-3 sshd[12753]: Connection closed by 113.190.235.xxx port 7600 [preauth] Jun 20 06:37:19 instance-3 sshguard[1393]: Blocking 113.190.235.188:4 for >630secs: 40 danger in 4 attacks over 184 seconds (all: 40d in 1 abuses over 184s). sudo service sshguard restart USER=root ; COMMAND=/usr/sbin/service sshguard restart Jun 20 06:45:11 instance-3 sudo: pam_unix(sudo:session): session opened for user root by vandung53cc(uid=0) Jun 20 06:45:11 instance-3 sshguard[1393]: Got exit signal, flushing blocked addresses and exiting... Jun 20 06:45:11 instance-3 sudo: pam_unix(sudo:session): session closed for user root Jun 20 06:45:11 instance-3 sshguard[12902]: Started with danger threshold=40 ; minimum block=420 seconds Jun 20 06:45:15 instance-3 sshd[12909]: Connection closed by 113.190.235.188 por...

Some Source code used often.

Mobile-Detect. Use simple code below: include 'Mobile_Detect.php'; $detect = new Mobile_Detect(); // Check for any mobile device. if ($detect->isMobile()) // mobile content else // other content for desktops Source code download here: Mobile Detect In Javascript, there are many script or lib to do this. Here one of mine: @extends('layouts.main') @section('head') @stop @section('content') login!! Facebook or Youtube login 【Sample CHECK!】 login!! screen 13 screen 15 screen 14 Some msg 3-12-12 笹川記念会館 Copyright ©C Official Web All rights reserved. @stop @section('script') @stop My script above is one of my index page. It write in Laravel bl...