Eloquent Relationships method does not exists









up vote
0
down vote

favorite












I have two tables, "teachers" & "teacher_certificates" which keep teachers certificates.



I'm trying to save teachers certificates by eloquent relationship like here https://laravel.com/docs/5.7/eloquent-relationships#the-create-method



Teacher Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentRelationsRelation;
use IlluminateDatabaseEloquentSoftDeletes;

class Teacher extends Model

public function Certificates()

return $this->hasMany(TeacherCertificates::class, 'teacher_id');


}


TeacherCertificate Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;

class TeacherCertificates extends Model

protected $table='teacher_certificates';
protected $fillable=['teacher_id','certificate'];
protected $touches=[Teacher::class];
public $timestamps=false;




And the controller:



namespace AppHttpControllersDashboard;

use AppHttpControllersController;
use AppModelsTeachersExperiences;
use AppModelsTeachersSkills;
use AppModelsTeachersTeacher;
use AppModelsTeachersTeacherCertificates;
use AppUser;
use IlluminateHttpRequest;
use AppHttpRequestsTeacherCreateRequest;
use IlluminateSupportFacadesDB;

class TeacherController extends Controller


public function store(TeacherCreateRequest $request)

DB::transaction(function () use ($request)
$data = $request->all();
$user = User::create($data);
$data[ 'user_id']=$user->id;

$teacher = Teacher::create($data);



//certificates
$certificates=array_map(
function ($certificate) use ($teacher)
return ['teacher_id' => $teacher->id,
'certificate' => $certificate];
, explode('n', $request->certifications));


$teacher->Certificates()->createMany($certificates);





I'm getting this error:



BadMethodCallException
Method IlluminateDatabaseQueryBuilder::AppModelsTeachersTeacher does not exist.









share|improve this question























  • Add your controller use statements to question. Ex: use AppExample;
    – Manpreet
    Nov 10 at 7:42











  • @Manpreet Added
    – Soheil Rt
    Nov 10 at 7:48










  • You say u have certificates table but you are using: protected $table='teacher_certificates'; Some misinformation in question.
    – Manpreet
    Nov 10 at 7:50










  • What is the namespace of Teacher model ? Copy head of file here
    – Mahdi Younesi
    Nov 10 at 7:55











  • @MahdiYounesi I Added the namespace and usage of Teacher model
    – Soheil Rt
    Nov 10 at 7:58














up vote
0
down vote

favorite












I have two tables, "teachers" & "teacher_certificates" which keep teachers certificates.



I'm trying to save teachers certificates by eloquent relationship like here https://laravel.com/docs/5.7/eloquent-relationships#the-create-method



Teacher Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentRelationsRelation;
use IlluminateDatabaseEloquentSoftDeletes;

class Teacher extends Model

public function Certificates()

return $this->hasMany(TeacherCertificates::class, 'teacher_id');


}


TeacherCertificate Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;

class TeacherCertificates extends Model

protected $table='teacher_certificates';
protected $fillable=['teacher_id','certificate'];
protected $touches=[Teacher::class];
public $timestamps=false;




And the controller:



namespace AppHttpControllersDashboard;

use AppHttpControllersController;
use AppModelsTeachersExperiences;
use AppModelsTeachersSkills;
use AppModelsTeachersTeacher;
use AppModelsTeachersTeacherCertificates;
use AppUser;
use IlluminateHttpRequest;
use AppHttpRequestsTeacherCreateRequest;
use IlluminateSupportFacadesDB;

class TeacherController extends Controller


public function store(TeacherCreateRequest $request)

DB::transaction(function () use ($request)
$data = $request->all();
$user = User::create($data);
$data[ 'user_id']=$user->id;

$teacher = Teacher::create($data);



//certificates
$certificates=array_map(
function ($certificate) use ($teacher)
return ['teacher_id' => $teacher->id,
'certificate' => $certificate];
, explode('n', $request->certifications));


$teacher->Certificates()->createMany($certificates);





I'm getting this error:



BadMethodCallException
Method IlluminateDatabaseQueryBuilder::AppModelsTeachersTeacher does not exist.









share|improve this question























  • Add your controller use statements to question. Ex: use AppExample;
    – Manpreet
    Nov 10 at 7:42











  • @Manpreet Added
    – Soheil Rt
    Nov 10 at 7:48










  • You say u have certificates table but you are using: protected $table='teacher_certificates'; Some misinformation in question.
    – Manpreet
    Nov 10 at 7:50










  • What is the namespace of Teacher model ? Copy head of file here
    – Mahdi Younesi
    Nov 10 at 7:55











  • @MahdiYounesi I Added the namespace and usage of Teacher model
    – Soheil Rt
    Nov 10 at 7:58












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have two tables, "teachers" & "teacher_certificates" which keep teachers certificates.



I'm trying to save teachers certificates by eloquent relationship like here https://laravel.com/docs/5.7/eloquent-relationships#the-create-method



Teacher Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentRelationsRelation;
use IlluminateDatabaseEloquentSoftDeletes;

class Teacher extends Model

public function Certificates()

return $this->hasMany(TeacherCertificates::class, 'teacher_id');


}


TeacherCertificate Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;

class TeacherCertificates extends Model

protected $table='teacher_certificates';
protected $fillable=['teacher_id','certificate'];
protected $touches=[Teacher::class];
public $timestamps=false;




And the controller:



namespace AppHttpControllersDashboard;

use AppHttpControllersController;
use AppModelsTeachersExperiences;
use AppModelsTeachersSkills;
use AppModelsTeachersTeacher;
use AppModelsTeachersTeacherCertificates;
use AppUser;
use IlluminateHttpRequest;
use AppHttpRequestsTeacherCreateRequest;
use IlluminateSupportFacadesDB;

class TeacherController extends Controller


public function store(TeacherCreateRequest $request)

DB::transaction(function () use ($request)
$data = $request->all();
$user = User::create($data);
$data[ 'user_id']=$user->id;

$teacher = Teacher::create($data);



//certificates
$certificates=array_map(
function ($certificate) use ($teacher)
return ['teacher_id' => $teacher->id,
'certificate' => $certificate];
, explode('n', $request->certifications));


$teacher->Certificates()->createMany($certificates);





I'm getting this error:



BadMethodCallException
Method IlluminateDatabaseQueryBuilder::AppModelsTeachersTeacher does not exist.









share|improve this question















I have two tables, "teachers" & "teacher_certificates" which keep teachers certificates.



I'm trying to save teachers certificates by eloquent relationship like here https://laravel.com/docs/5.7/eloquent-relationships#the-create-method



Teacher Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentRelationsRelation;
use IlluminateDatabaseEloquentSoftDeletes;

class Teacher extends Model

public function Certificates()

return $this->hasMany(TeacherCertificates::class, 'teacher_id');


}


TeacherCertificate Model:



namespace AppModelsTeachers;

use AppUser;
use IlluminateDatabaseEloquentModel;

class TeacherCertificates extends Model

protected $table='teacher_certificates';
protected $fillable=['teacher_id','certificate'];
protected $touches=[Teacher::class];
public $timestamps=false;




And the controller:



namespace AppHttpControllersDashboard;

use AppHttpControllersController;
use AppModelsTeachersExperiences;
use AppModelsTeachersSkills;
use AppModelsTeachersTeacher;
use AppModelsTeachersTeacherCertificates;
use AppUser;
use IlluminateHttpRequest;
use AppHttpRequestsTeacherCreateRequest;
use IlluminateSupportFacadesDB;

class TeacherController extends Controller


public function store(TeacherCreateRequest $request)

DB::transaction(function () use ($request)
$data = $request->all();
$user = User::create($data);
$data[ 'user_id']=$user->id;

$teacher = Teacher::create($data);



//certificates
$certificates=array_map(
function ($certificate) use ($teacher)
return ['teacher_id' => $teacher->id,
'certificate' => $certificate];
, explode('n', $request->certifications));


$teacher->Certificates()->createMany($certificates);





I'm getting this error:



BadMethodCallException
Method IlluminateDatabaseQueryBuilder::AppModelsTeachersTeacher does not exist.






php laravel eloquent laravel-5.6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 8:12

























asked Nov 10 at 7:03









Soheil Rt

215




215











  • Add your controller use statements to question. Ex: use AppExample;
    – Manpreet
    Nov 10 at 7:42











  • @Manpreet Added
    – Soheil Rt
    Nov 10 at 7:48










  • You say u have certificates table but you are using: protected $table='teacher_certificates'; Some misinformation in question.
    – Manpreet
    Nov 10 at 7:50










  • What is the namespace of Teacher model ? Copy head of file here
    – Mahdi Younesi
    Nov 10 at 7:55











  • @MahdiYounesi I Added the namespace and usage of Teacher model
    – Soheil Rt
    Nov 10 at 7:58
















  • Add your controller use statements to question. Ex: use AppExample;
    – Manpreet
    Nov 10 at 7:42











  • @Manpreet Added
    – Soheil Rt
    Nov 10 at 7:48










  • You say u have certificates table but you are using: protected $table='teacher_certificates'; Some misinformation in question.
    – Manpreet
    Nov 10 at 7:50










  • What is the namespace of Teacher model ? Copy head of file here
    – Mahdi Younesi
    Nov 10 at 7:55











  • @MahdiYounesi I Added the namespace and usage of Teacher model
    – Soheil Rt
    Nov 10 at 7:58















Add your controller use statements to question. Ex: use AppExample;
– Manpreet
Nov 10 at 7:42





Add your controller use statements to question. Ex: use AppExample;
– Manpreet
Nov 10 at 7:42













@Manpreet Added
– Soheil Rt
Nov 10 at 7:48




@Manpreet Added
– Soheil Rt
Nov 10 at 7:48












You say u have certificates table but you are using: protected $table='teacher_certificates'; Some misinformation in question.
– Manpreet
Nov 10 at 7:50




You say u have certificates table but you are using: protected $table='teacher_certificates'; Some misinformation in question.
– Manpreet
Nov 10 at 7:50












What is the namespace of Teacher model ? Copy head of file here
– Mahdi Younesi
Nov 10 at 7:55





What is the namespace of Teacher model ? Copy head of file here
– Mahdi Younesi
Nov 10 at 7:55













@MahdiYounesi I Added the namespace and usage of Teacher model
– Soheil Rt
Nov 10 at 7:58




@MahdiYounesi I Added the namespace and usage of Teacher model
– Soheil Rt
Nov 10 at 7:58












1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










The problem resides in definition of $touches property of Teacher class, Which should be name of a method in your class.



For more info read Laravel's Doc






share|improve this answer




















  • It Worked, Thanks.
    – Soheil Rt
    Nov 10 at 8:22










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236756%2feloquent-relationships-method-does-not-exists%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










The problem resides in definition of $touches property of Teacher class, Which should be name of a method in your class.



For more info read Laravel's Doc






share|improve this answer




















  • It Worked, Thanks.
    – Soheil Rt
    Nov 10 at 8:22














up vote
3
down vote



accepted










The problem resides in definition of $touches property of Teacher class, Which should be name of a method in your class.



For more info read Laravel's Doc






share|improve this answer




















  • It Worked, Thanks.
    – Soheil Rt
    Nov 10 at 8:22












up vote
3
down vote



accepted







up vote
3
down vote



accepted






The problem resides in definition of $touches property of Teacher class, Which should be name of a method in your class.



For more info read Laravel's Doc






share|improve this answer












The problem resides in definition of $touches property of Teacher class, Which should be name of a method in your class.



For more info read Laravel's Doc







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 8:14









Mahdi Younesi

3,0621530




3,0621530











  • It Worked, Thanks.
    – Soheil Rt
    Nov 10 at 8:22
















  • It Worked, Thanks.
    – Soheil Rt
    Nov 10 at 8:22















It Worked, Thanks.
– Soheil Rt
Nov 10 at 8:22




It Worked, Thanks.
– Soheil Rt
Nov 10 at 8:22

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236756%2feloquent-relationships-method-does-not-exists%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20