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.
php laravel eloquent laravel-5.6
|
show 3 more comments
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.
php laravel eloquent laravel-5.6
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
|
show 3 more comments
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.
php laravel eloquent laravel-5.6
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
php laravel eloquent laravel-5.6
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
|
show 3 more comments
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
|
show 3 more comments
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
It Worked, Thanks.
– Soheil Rt
Nov 10 at 8:22
add a comment |
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
It Worked, Thanks.
– Soheil Rt
Nov 10 at 8:22
add a comment |
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
It Worked, Thanks.
– Soheil Rt
Nov 10 at 8:22
add a comment |
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
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
answered Nov 10 at 8:14
Mahdi Younesi
3,0621530
3,0621530
It Worked, Thanks.
– Soheil Rt
Nov 10 at 8:22
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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