How can I integrate the new Google Cloud Messaging in a PHP?

Published on

GCM with PHP (Google Cloud Messaging) The cURL code that’s on the page that Elad Nava has put here works. Elad has commented about the error he’s receiving. String describing an error that occurred while processing the message for that recipient. The possible values are the same as documented in the above table, plus “Unavailable” … Continue reading How can I integrate the new Google Cloud Messaging in a PHP?

How to Split a string every time it reaches 4 digits using regular expressions in php

Published on

Split a string every time it reaches 4 digits using regular expressions in php. Want to use preg_match_all: $str = ‘ABCDE1234ABCD1234ABCDEF1234’; preg_match_all(‘/[a-z]+[0-9]{4}/i’, $str, $matches); var_dump($matches); Output: array(1) { [0]=> array(3) { [0]=> string(9) “ABCDE1234” [1]=> string(8) “ABCD1234” [2]=> string(10) “ABCDEF1234”}} —————————————————/OR/————————————————- Use the principle of contrast: \D+\d{4} # requires at least one non digit # followed … Continue reading How to Split a string every time it reaches 4 digits using regular expressions in php

How to check if related model exists in Laravel

Published on

since @TheShiftExchange did not take the advice, there we go with generic solution working on all the relation types: if (count($model->relation)) { // exists} This will work for every relation since dynamic properties return Model or Collection. Both implement ArrayAccess. So it goes like this: single relations: hasOne / belongsTo / morphTo / morphOne // … Continue reading How to check if related model exists in Laravel

How to Redirect All Requests To HTTPS in Laravel

Published on

Using App::before You might be able to take advantage of the App::before() block in the app/filters.php file. Change the block to include a simple check to see if the current request is secure, and if not, redirect it. App::before(function($request) { if(! Request::secure()) { return Redirect::secure(Request::path());}}); Using Filters Another option might be to create a filter … Continue reading How to Redirect All Requests To HTTPS in Laravel

How to place HTTPS on my app in laravel 5 rather than .htaccess

Published on

Make it works with a Middleware class. Let me give you an idea. namespace MyApp\Http\Middleware; use Closure; class HttpsProtocol { public function handle($request, Closure $next) { if (!$request->secure() && env(‘APP_ENV’) === ‘prod’) { return redirect()->secure($request->getRequestUri());} return $next($request);}} Then, apply this middleware to every request adding setting the rule at Kernel.php file, like so: protected $middleware … Continue reading How to place HTTPS on my app in laravel 5 rather than .htaccess

PDOException SQLSTATE[HY000] [2002] No such file or directory

Published on

Laravel 4: Change “host” in the app/config/database.php file from “localhost” to “127.0.0.1” Laravel 5: Change “DB_HOST” in the. env file from “localhost” to “127.0.0.1” I had the exact same problem. None of the above solutions worked for me. I solved the problem by changing the “host” in the /app/config/database.php file from “localhost” to “127.0.0.1”. Not … Continue reading PDOException SQLSTATE[HY000] [2002] No such file or directory

TokenMismatchException in VerifyCsrfToken.php Line 67

Published on

Add this in your HTML meta tag area : <meta name=”csrf-token” content=”{{ csrf_token() }}”> Then under your JQuery reference, add this code : <script type=”text/javascript”> $.ajaxSetup({ headers: { ‘X-CSRF-TOKEN’: $(‘meta[name=”csrf-token”]’).attr(‘content’) } }); </script> If you are using the HTML form submit (not AJAX) then you need to put : {{ csrf_field() }} inside your form … Continue reading TokenMismatchException in VerifyCsrfToken.php Line 67