Method Illuminate Database Eloquent Collection::emails does not exist

Asked

Viewed 275 times

0

I’m trying to use "Sync" to feed a table that relates email to a person’s registration.

This table I created and intend to feed contains the registration id and email id.

To feed it, I will use the "Sync" and in the registration model I created the function

public function Emails(){
    return $this->belongsToMany('App\emails','cadastro_emails','cadastro_id','email_id');
}

To insert into the bank, I am doing as follows:

   $cadSa      = $cadastro::firstOrCreate($cad)->all();
   $cadSa->Emails()->sync([3,4]);

This function ("Emails") apparently works because, when it comes to bringing email data related to registrations, the answer is fast and right.

So, what’s wrong when doing synchronization on the intersection table via "Sync"?

  • Hello! It seems to me that you are missing a few lines in your code. Where is the title property called? Which line is the error happening? You can [Edit] the question including these details.

  • I solved the problem of emails...really I was calling him wrong, however, I still could not solve the issue.... come on: $id = $sign up::firstOrCreate($Cad)->id; $sign up->Emails()->Sync([3,4]); thus: $id = $cadastre::firstOrCreate($Cad)->id; $cadastro_email->cadastro_id=$id; $cadastro->Emails()->Sync([3,4]); yet he still says that the value of cadastro_id is null...

  • Post all class

  • follows the controller that does this:<? php namespace App Http Controllers; use Illuminate Http Request; use App cadastre; use App emails; use App phones; use App emails; class cadastroCtrl extends Controller { public Function all(cadastro $cadastro){ $all = $cadastro->all(); Return view('paginasCrm1.cadastros.home',Compact('all')); } public Funccadastion(Request $Request,cadastro $cadastro)' $cadastro:create:($Request->all()); $register->Emails()->Sync(['1']); } }

  • and the register class(model) <? php namespace App; use Illuminate Database Eloquent Model; class cadastro extends Model { protected $fillable=['name','Cpf','rg','birth','cargo_id']; protected $table= "entries"; public Function Positions(){ Return $this->belongsTo('App positions','cargo_id'); } public Function Emails(){ Return $this->belongsToMany('App emails','email signups','id','emails_id'); } }

  • $cadSa = $cadastro::firstOrCreate($cad) and then $cadSa->Emails()->sync([3,4]); you are doing wrong by that of the problems

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.