earthgirlllc Posted July 9, 2020 Share Posted July 9, 2020 (edited) Hi all - I'm trying to learn how to create add-on modules & hooks. The documentation is good but I could use some more examples or pointers. I've created a form field within the Admin Domain Details tab that inserts data to mod_ table on save. That part works fine. But now I need the Admin Domain Details tab to populate those values on load. I'm muddling through Laravel docs too (eek) and can't seem to figure this out. Table: mod_domain_restrictionField 1: (unique/int) dr_domainid (the domain_id)Field 2: (boolean) dr_restrict_domain The formfield is a radio input and I just need to tell it, essentially, if `mod_domain_restriction`.`dr_domainid` exists and matches $vars['id'] (right?), then: return ['Restrict Domain' => '<input type="radio" name="restrict_domain" value="0" id="off"> <label for="off">Off</label> <input type="radio" name="restrict_domain" value="1" id="on" checked> <label for="on">On</label>', ]; else return [ 'Restrict Domain' => '<input type="radio" name="restrict_domain" value="0" id="off" checked> <label for="off">Off</label> <input type="radio" name="restrict_domain" value="1" id="on"> <label for="on">On</label>', ]; I'm not sure how to do that initial query with Laravel. This is what I've pieced together - I know it's way wrong but I'm trying. 🙂 (Note: I'm working with domain_id 1 so I just hard coded it in for testing. I need that to be dynamic too, but one thing at a time!) EDIT: Solution-> this worked -- use Illuminate\Database\Capsule\Manager as Capsule; add_hook('AdminClientDomainsTabFields', 1, function(array $params) { try { $results = Capsule::table('mod_domain_restriction') ->where('dr_domainid', '1') ->get(); if ($results == 0) { -- The hook logs aren't giving me much. Even when I'm able to get the syntax worked out, I don't get any results. So, I'm on the wrong path and would love input? Once I get this first part figured, I can try to figure out the "if exists - update, otherwise insert". Thanks!! Date Description Username IP Address 09/07/2020 06:25 Hooks Debug: Hook File Loaded: /home/***/public_html/modules/addons/domain_restriction/hooks.php admin 09/07/2020 06:25 Hooks Debug: Could not include file: /home/***/public_html/modules/addons/domain_restriction/hooks.php. Error: syntax error, unexpected 'else' (T_ELSE), expecting ',' or ')' admin Edited July 10, 2020 by earthgirlllc 0 Quote Link to comment Share on other sites More sharing options...
earthgirlllc Posted July 10, 2020 Author Share Posted July 10, 2020 I figured it out use Illuminate\Database\Capsule\Manager as Capsule; add_hook('AdminClientDomainsTabFields', 2, function(array $params) { $domainId = $_GET['id']; try { $results = Capsule::table('mod_domain_restriction') ->where('dr_domainid', $domainId) ->where('dr_restrict', 1) ->first(); if ($results >= 1) { // DO THIS } 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.