Check if model exists for use in custom method

Posted 2 years ago by ehsanquddusi

I have created a method reach() inside Campaign model. The reach() method processes data from the model instance. How can I check whether the data is loaded in current instance or not? e.g,

$campaign = new Campaign;
$campaign->reach();

It won't work with this instance, since the eloquent object will be empty this time, but it should work with

$campaign = Campaign::find(1);
$campaign->reach();

Here $campaign will be instance with data loaded from campaigns table.

My question is, how can I know, if the object instance is newly created or loaded with data.

Please sign in or create an account to participate in this conversation.