vendredi 9 octobre 2015

Call to undefined method with Eloquent in Laravel5.1

I'm using Laravel 5.1 and experiencing the error

Call to undefined method Illuminate\Database\Eloquent\Collection::votes()

when storing the data.

Business model

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Business extends Model
{
public function votes()
    {
        return $this->hasMany('App\Models\Vote');
    }
}

And then the form POST request to

$business = Business::where('business_area', $request->input('business_area'))->get();

        $vote = $business->votes()->create($request->all());

        return response()->json($vote, 201);

For some reason it cannot find the votes method. I'm stuck.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire