dk4210

dk4210

Member Since 3 Years Ago

Experience Points
18,820
Total
Experience

1,180 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
151
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 4
18,820 XP
Jul
07
1 month ago
Activity icon

Replied to Verify Output - Null Or Empty

Hi,

I'm expecting to see all these array values with some value. No nulls or empty strings from the array. I'm doing a var_dump($e_source_database) to see the following output.

array(4) {
  [0] =>
  string(0) ""
  [1] =>
  NULL
  [2] =>
  NULL
  [3] =>
  string(0) ""
}
Activity icon

Replied to Verify Output - Null Or Empty

Yea I tried that also

if(empty($e_source_database)){
	echo "No source database info";
}
Activity icon

Replied to Verify Output - Null Or Empty

Hi Joel

I also tried that.

It looked like this

if(is_null($e_source_database)){
    echo "No source database info";
    }

It didn't work, Is this the correct syntax?

Activity icon

Started a new Conversation Verify Output - Null Or Empty

Hello Guys,

I'm trying to validate the value of a static method call.

My static method call output currently looks like this

array(4) {
  [0] =>
  string(0) ""
  [1] =>
  NULL
  [2] =>
  NULL
  [3] =>
  string(0) ""
}

I want to create an if statement that will echo some sort of message if there are no values. I tried this and didn't work

if($e_source_database === NULL){
	echo "No source database info";
}

I also tried this

if($e_source_database == ""){
	echo "No source database info";
}

any ideas?

Thanks!

May
26
2 months ago
Activity icon

Started a new Conversation Class Interfaces Explanation

Hello guys,

I'm trying to understand interfaces. Can you explain the reason for interfaces or maybe a tutorial/video?

Thanks!

May
12
3 months ago
Activity icon

Replied to Getting Value From Json_decode ( PHP )

Tykus

That worked. Thank you!

Activity icon

Replied to Getting Value From Json_decode ( PHP )

Hi RamjithAp,

Thanks for the reply.

I updated the code.

$econfig = json_decode(file_get_contents("url.json", TRUE));

echo "This is the dit endpoint". $econfig["uris"]["DIT"];

I get the following error message

Cannot use object of type stdClass as array
Activity icon

Started a new Conversation Getting Value From Json_decode ( PHP )

Hello Guys,

I 'm trying to get this value, but having some issues

So I have a file called url.json and i'm loading it here $econfig = json_decode(file_get_contents("url.json"));

The code looks like this

"uris": {
		"DIT": "http://test1.com",
		"FIT": "http://test2.com",
		"UAT": "http://test3.com",
		"PROD": "http://test4.com",
		"PROD2": "http://test5.com"
	},
	"endpoints": {
		"create": "migrate",
		"status": "migrate"
	},
	"emails": [

	]
}

When I do var_dump($econfig) It outputs this

class stdClass#4 (3) {
  public $uris =>
  class stdClass#5 (5) {
    public $DIT =>
    string(42) "http://test1.com"
    public $FIT =>
    string(78) "http://test2.com"
    public $UAT =>
    string(85) "http://test3com"
    public $PROD =>
    string(81) "http://test4.com"
    public $PROD2 =>
    string(81) "http://test5.com/"
  }

How can I compare the env, for example "DIT" and get the value (Which in this case is http://test1.com)?

I know it will be something like $econfig>DIT;

Help is appreciated.

Mar
10
5 months ago
Activity icon

Replied to Guzzle How To Send Body Values.

Thanks for the response. I read that, but can't figure out how to place it in the code.

Activity icon

Started a new Conversation Guzzle How To Send Body Values.

Hello Everyone,

I'm trying to figure out how to pass info in the body. When I do, I get the following response

Passing in the "body" request option as an array to send a POST request has been deprecated. Please use the "form_params" request option to send a application/x-www-form-urlencoded request, or a the "multipart" request option to send a multipart/form-data request.

I've research it, but I don't quite understand how to pass with form_params. Can you please take a look at my code and see if you can help?

<?php

namespace Emt\Vantage;

use DBaaS\HTTP\Client;
use DBaaS\Log\BaseLogger as Logger;
use Exception;

/**
 * Activate/Deactive downtime page for Clients.
 */
class Downtime extends Client
{
    /**
     * ORGOID of client to manipulate.
     *
     * @var string
     */
    private $orgOID;

    /**
     * Supported actions.
     *
     * @var array
     */
    private $actions;

    /**
     * Properties related to client.
     *
     * @var array
     */
    private $clientProperties = null;

    /**
     * Setup configuration for proper endpoint.
     *
     * @param array $meta Request meta
     */
    public function __construct($meta)
    {
        // Load downtime configuration
        $config = json_decode(
            file_get_contents(APP_ROOT.'env/config/main_code/downtime/downtime.json'),
            true
        );
		
		// print_r($config);

        // Confrim URI is supported
        $env   = $meta['_args']['env_target'];
        $url   = isset($config['uris'][$env]) ? $config['uris'][$env] : false;
		
		//echo "This is the url" . $url;
		
        if (!$url) {
            throw new Exception("Environment '${env}' is not configured within DBaaS!");
        }
		
		 // Class globals
        $this->orgOID  = $meta['_args']['targetCOID'];
        $this->actions = $config['actions'];
		
		//var_dump($config['actions']);
		

        // Get token
        //$creds = $config['credentials'][$env];
        parent::__construct([
            'base_uri' => $url,
            'headers'  => [
               // 'Authorization' => $creds,
                'Content-Type'  => 'application/json',
            ],
			
         ]);
		 
        $response = $this->get(''.$url.''.$this->orgOID.'/rrg/apps/myPortal/comps/pt01/');
		//echo "This is the response - ". $response;
        $data     = (array) json_decode($response->getBody(), true);
		
				
       // $token    = $data['token'];

       
		
		$orgid = $meta['_args']['targetCOID'];

        
        $headers = [
           // 'Cookie'         => "token=${token}",
            'Content-Type'   => 'application/json;charset=UTF-8',
			'Accept'         => 'application/vnd.siren+json',
           // 'sourceAssocOID' => $meta['sourceAOID'],
           // 'targetAssocOID' => $meta['targetAOID'],
        ];
		
		 $body = [
          'ClientPOD' => 'godown',
        ];
		
		
		 
			
        Logger::print_notice('Setting headers...');
        $this->printData($headers);
		
		Logger::print_notice('Setting body...');
        $this->printData($body);
		
        // Setup API to prepare for calls
        Logger::print_notice("${env} URL: ${url}");
        parent::__construct([
            'base_uri'    => $url,
            'headers'     => $headers,
			'body'        => $body,
			
        ]);
    }
	
	

    /**
     * Return client properties.
     *
     * @return array client properties
     */
    public function getClientProperties()
    {
        return $this->clientProperties;
    }

    /**
     * Ensure client exists in vantage meta and that it
     * contains supported actions to run.
     *
     * @return bool true if valid
     */
    public function validateClient()
    {
        try {
            // Validate client exists
            Logger::print_notice('Validating orgoid '.$this->orgOID.'...');
			            $response = $this->get('/wt/v1/clients/orgoids/'.$this->orgOID.'/rg/apps/myPortal/comps/pt01');
						
            if ($response->getStatusCode() != 200) {
                throw new Exception($response->getStatusCode().' code recieved instead of 200!');
            }
			
			
			
            $data = (array) json_decode($response->getBody(), true);
			
			//var_dump($data);
			
			//echo "This is the data". print_r($data);
			
            Logger::print_notice('Client found:');
           

            return true;
        } catch (Exception $e) {
            Logger::print_error('Validation Error: '.$e->getMessage());

            return false;
        }
    }

    /**
     * Activate Vantage client.
     *
     * @return int 0 for success
     */
    public function activate()
    {
        Logger::print_notice('Activating client...');

        return $this->executePut($this->actions['activate']);
    }

    /**
     * Deactivate Vantage client.
     *
     * @return int 0 for success
     */
    public function deactivate()
    {
        Logger::print_notice('Deactivating client...');

        return $this->executePut($this->actions['ClientPOD:godown']);
    }

    /**
     * Execute PUT command.
     *
     * @param string $endpoint Path to command
     *
     * @return int 0 for success
     */
    private function executePut($endpoint)
    {
        try {
            Logger::print_notice("Executing ...");
            
					
            if ($response->getStatusCode() != 200) {
                throw new Exception($response->getStatusCode().' code recieved instead of 200!');
            }
            Logger::print_notice('Call successful, review response:');
            $this->printData((array) json_decode($response->getBody()));

            return 0;
        } catch (Exception $e) {
            Logger::print_error("ERROR: ".$e->getMessage());
			 return 1;
        }
    }

    /**
     * Dump data to screen in readable format.
     *
     * @param array $data Data to print
     */
    private function printData(array $data = [])
    {
        print_r(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
        echo "\n\n";
    }
}



Feb
11
6 months ago
Activity icon

Replied to Host To Access A Variable In Static Method

I did change it from the static method.

Activity icon

Replied to Host To Access A Variable In Static Method

Actually, its related due to this is my actual code. I'm not sure if due to the Variable that I'm trying to pass inside the method.

Activity icon

Started a new Conversation Host To Access A Variable In Static Method

Hello guys,

if I have something like this

class test
{

      public function __construct()

    {

    $var = 123;

    }

      public static method mytest()

      {

      // How do I access the $var from the construct?


      }


}

I'm trying to figure out how to share the variables in the same class among methods. I have the hardest problem understanding this concept.

Thanks!