jeudi 6 juin 2019

Call to undefined relationship [xxx] on model [App\xxx]

My tables:

  • **escuderias **
    esc_id
  • usuarios_escuderias
    usuesc_idEscuderia usuesc_idUser
  • users id

My Models:

** Escuderia ***

use App\CompeticionEvento;
use App\UsuarioEscuderia;


class Escuderia extends Model
{

    public function pilotos() {
        return $this->hasMany('App\UsuarioEscuderia','usuesc_idEscuderia','esc_id');
    }
}

Model UsuarioEscuderia:

use App\User; use App\Escuderia;

class UsuarioEscuderia extends Model {

 public function escuderia()
{
    return $this->belonsTo('App\Escuderia','usuesc_idEscuderia','esc_id');

}

 public function datosUsuario()
{
    //modelo --> clave foranea --> clave local
    return $this->belonsTo('App\User','usuesc_idUser','id');

}

}

Model User

use App\UsuarioEscuderia;

class User extends Authenticatable
{

    public function usuariosEscuderia() {
        return $this->belonsToMany('App\UsuarioEscuderia','usuesc_idUser','id');

    }

}

In my Controller I have the following:

class EscuderiaController extends Controller
{
    //
    public function index(Escuderia $model,Request $request)
    {
    $resultado = Escuderia::with('pilotos')->with('usuariosEscuderia')->get();

    }
}

I have the following error: "Call to undefined relationship [usuariosEscuderia] on model [App\Escuderia]."

Can you help me? Thank You



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2XCXvWQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire