samedi 3 novembre 2018

Realationship Between Mongodb and Mysql use of laravel

I am Trying to get data from mysql and mongodb in laravel framework.I am using HybridRelations to fetch data realated data but I stuck.please help me.

I got Error like that.
Call to undefined relationship [Country] on model [App\Models\State].

Here is my code. country model;

namespace App;

namespace App\Models;

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class Country extends Eloquent {

protected $connection = 'mongodb';

protected $collection = 'countries';

protected $fillable = [ 'country' ];


public function country()
{
    return $this->hasMany(State::class,'country_id');

}

}

my state model:

<?php

namespace App\Models;

use Jenssegers\Mongodb\Eloquent\HybridRelations;

use Illuminate\Database\Eloquent\Model;

class State extends Model {

    use HybridRelations;

protected $connection = 'mysql';

protected $table = 'state';
protected $primaryKey = 'state_id';

protected $fillable = [  'name','code','status' ];

public function state()
{
    return $this->belongsTo(Country::class, '_id');
}

}

can you please help me..



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire