I am using Laravel 5.4 .There are two tables groups and contacts with the following structure. Every contact has a group.
contacts
groups
I also created a model for each one as below:
Group.php which is the groups model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Group extends Model
{
public function contact()
{
return $this->hasMany('App\Contact');
}
}
Contact.php which is the contacts model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
public function group(){
$this->belongsTo('App\Group');
}
}
Now using the php atrisan tinker, the following command reports the error:
App\Contact::find(3)->group
When I type App\Contact::find(3) it returns the contact with ID 3 successfully but the App\Contact::find(3)->group returns the error while I expect it to return the group of contact with ID 3
Thanks.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2w69WOh
via IFTTT
Aucun commentaire:
Enregistrer un commentaire