Call to undefined method error in Laravel

Tharindu Sandaruwan

I have the following function:

public function addSubject(Request $request) {
    $student=User::find($request->invisible);
    $classsubjects = $request['classsubjects'];
    $student->classSubjects()->attach($cclasssubjects);
}

This gives me an error saying:

BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::attach()

Nandhi Kumar

The function classSubjects() in your Package model has to return a BelongsToMany relationship in order to use attach().

public function classSubjects() {
  return $this->belongsToMany('classSubjects');
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Call to undefined method error

Routing error in Laravel resulting in: Call to undefined method ReflectionUnionType::getName()

Laravel 5.4 - Error Call to undefined method Illuminate\Http\JsonResponse::count()

laravel error Call to undefined method Illuminate\Hashing\BcryptHasher::driver()

Call to undefined method App\User::admin() error in Session in Laravel

Laravel Error: Call to undefined method App\Cart::delete()

laravel save() returns error Call to undefined method stdClass::save()

Call to undefined method create() error

Laravel Call to undefined method on a method I created

Call to undefined method Illuminate\Database\Query\Builder::method() error in laravel 5

Call to undefined method [loadRoutesFrom] error in laravel 5.2 after installing jeremykenedy-laravel-logger package

PHP Error: Fatal error: Call to undefined method

CakePHP error: Call to undefined method FlashComponent::error()

Laravel call to undefined method App\Seo::mapInto()

Call to undefined method stdClass::delete() in laravel

Laravel Seeder, call to undefined method ::create

Call to undefined method App\User::role() in Laravel

Laravel - Carbon Macro Call to undefined Method

Call to undefined method exception in laravel/php

laravel search paginate Call to undefined method links()

Laravel - Call to undefined method TrainingFacade::save()

Call to undefined method after upgrading to laravel 5.4

Laravel 5.5 Call to undefined method stdClass::update()

Laravel 4 : Call to undefined method Redis::connection()

Laravel Request::input Call to undefined method

Call to undefined method stdClass:: Laravel 5.3

Laravel 5.5 Tests - Call to undefined method ::see()

Function forget() return Call to undefined method in Laravel

Laravel Call to undefined method Query\Builder