Created
November 7, 2016 05:50
-
-
Save yoosuf/381385f2f978c3481b95b84029e7cbdf to your computer and use it in GitHub Desktop.
Member::whereJsonContains()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO `members` (`id`, `name`, `msisdn`, `token`, `api_token`, `settings`, `created_at`, `updated_at`) | |
VALUES | |
(1, NULL, '343434343434', '303273', 'GIUalPNIiiBIiQsBeJDeeMvxhgL9wrDOrlE5AqGyZvHFWwPuuBPjHziTWZHu2xuM', '{\"topics\":[\"topic1\",\"topic2\"]}', '2016-11-05 07:56:55', '2016-11-05 07:56:55'), | |
(2, 'Haiooo', '0776002114', '150093', '5peAwwfkYo19sRQTZq21ePMynJrRlTLuTwvxGVoSvLIz4jRVQ830nnflZGv9cUK3', '{\"topics\":[\"topic1\",\"topic2\",\"topic3\",\"topic4\"]}', '2016-11-06 02:27:31', '2016-11-06 02:27:53'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `members` ( | |
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | |
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, | |
`msisdn` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | |
`token` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, | |
`api_token` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | |
`settings` text COLLATE utf8_unicode_ci, | |
`created_at` timestamp NULL DEFAULT NULL, | |
`updated_at` timestamp NULL DEFAULT NULL, | |
PRIMARY KEY (`id`), | |
UNIQUE KEY `members_msisdn_unique` (`msisdn`), | |
UNIQUE KEY `members_api_token_unique` (`api_token`) | |
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MemberController extends controller { | |
public function index() { | |
$member = Member::whereRaw('JSON_CONTAINS(settings->"$.topics", \'["topic3"]\')')->get(); | |
return $member; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment