jsrosas
3 years ago

Set new instance of model in controller

Posted 3 years ago by jsrosas

Hiya all, Thanks in advance for any help you can provide. I have a controller which sets some fields for a model Member. Now this model Member is a customer that will be referred by other Member. So the User has a field where they can select the name of the Member that referred them. In the controller I have to find that Member(referrer) and assign its ID to the referrer_id field of the new Member. The problem is that when I go and fetch the referrer Member it holds the information from the new Member. How do I create a new instance of the Member model in my controller so that I can do my query? I am trying:

$refer = new Member::where('vendorname', $vendorname)->firstOrFail();

But I get:

Class App\Http\Controllers\MemberProfileController does not exist

It does though lol. Not sure why it throws this error. Either way when I remove the new from my query and I dd($refer), It gives me the information of the new Model being edited. Again thanks in advance.

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