Because your $request doesnt have addCource. If you want to use this method you need to create model. $newModel=new Course(); and then use $newModel->addCourse();
Jun 27, 2017
3
Level 5
Laravel says an existing method does not exist.
I have a class named Course and a method on that course by the name addCourse. I've also set guarded to []. Here is the class
class Course extends Model
{
protected $guarded = [];
/**
* Add a course
*
* @return void
* @author
**/
public function addCourse($course)
{
$this->create($course);
}
}
On the store method I am calling the following
public function store(Request $request)
{
$request->addCourse([
'user_id' => request('user_id'),
'title' => request('title'),
'body' => request('body'),
'country' => request('country'),
'city' => request('city'),
'address' => request('address')
]);
return back();
}
But the following test
/**
* A user may create courses
*
* @return void
* @author
**/
function test_an_authenticated_user_may_create_courses()
{
$this->mockUser();
$course = factory('App\Course')->make();
$this->post('/courses', $course->toArray());
$this->assertCount(1, $this->course);
}
returns the following
BadMethodCallException: Method addCourse does not exist.
Level 4
1 like
Please or to participate in this conversation.