mercredi 4 novembre 2015

HasMany and BelongsTo not returning any results

we all know that eloquent relationships are fairly easy, but I've found myself in a bit of a problem. It seems that I can't get the basic functionality of any relationship to work.

Below are my Models:

<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class Musician extends Model {

protected $fillable = ['user_id', 'musician_name', 'zip_code', 'bio', 'lat', 'lng'];

public function connections()
{
    return $this->hasMany('App\Models\Connection');
}

}

And my second one:

<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class Connection extends Model {

protected $guarded = ['id'];

public function musician(){

    return $this->belongsTo('App\Models\Musician');
}

}

My Route

Route::get('ngmusicians/{filter}', function($filter){
     $connections = App\Models\Musician::find(Session::get('musician_id'))->connections;

I'm yielding no results from the database at all. Any help would be great.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire