PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 26, 2022

[FIXED] Trying to get property 'name' of non-object when passing object to a class

 February 26, 2022     laravel, php     No comments   

Issue

I have a route in my controller:

$emailRecipient = DB::select("
            select 
                e.ID empID,
                e.lname lname,
                e.fname fname,
                e.email email,
                e.teamID,
                e.agencyID,
                e.accessProfileID, 
                e.accessTeams,
                c.ID coID,
                c.dDesc companyName
                c.product,
                c.modules
            from 
                emailrecipient_tb er
                    left join employee_tb e on er.empID = e.ID
                    left join company_tb c on er.coID = c.ID
            where 
                er.isDAR = 1 and 
                er.isActive = 1 and
                c.isActive = 1
        ");

        foreach ($emailRecipient as $rowRecipient) {
            Mail::to($rowRecipient->email)->send(new DailyActivityReport2($rowRecipient));
        }

and then in my DailyActivityReport2 class I have:

    public $coID;
    public $companyName;
    public $product;
    public $rEmpID;
    public $rLname;
    public $rFname;
    public $rEmail;
    public $rAccessTeamID;
    public $rAccessAgencyID;
    public $rAccessProfileID;
    public $rAccessTeams;
    public $rModules;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($rowRecipient)
    {
        $coID = $rowRecipient->coID;
        $companyName = $rowRecipient->companyName;
        $product = $rowRecipient->product;
        $rEmpID = $rowRecipient->empID;
        $rLname = $rowRecipient->lname;
        $rFname = $rowRecipient->fname;
        $rEmail = $rowRecipient->email;
        $rAccessTeamID = $rowRecipient->teamID;
        $rAccessAgencyID = $rowRecipient->agencyID;
        $rAccessProfileID = $rowRecipient->accessProfileID;
        $rAccessTeams = $rowRecipient->accessTeams;
        $rModules = json_decode($rowRecipient->modules);
    }

then I get an error:

Trying to get property 'coID' of non-object

the error is at:

$coID = $rowRecipient->coID;

The thing is if I try to use $rowRecipient->coID in the controller then the code works, only when I pass it in the class, then it no longer works...


Solution

I'm stupid, I didn't realize I hard-coded coID in the controller (for testing).



Answered By - jove0610
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing