Last active
October 23, 2019 12:28
-
-
Save programarivm/e990795786e54288d724b12cbed19d18 to your computer and use it in GitHub Desktop.
Many-to-many relationship linked through an entity table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Restaurant extends Model | |
{ | |
public function reviews() | |
{ | |
return $this->hasMany(Review::class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Review extends Model | |
{ | |
public function restaurant() | |
{ | |
return $this->belongsTo(Restaurant::class); | |
} | |
public function user() | |
{ | |
return $this->belongsTo(User::class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Notifications\Notifiable; | |
use Illuminate\Contracts\Auth\MustVerifyEmail; | |
use Illuminate\Foundation\Auth\User as Authenticatable; | |
class User extends Authenticatable | |
{ | |
use Notifiable; | |
/** | |
* The attributes that are mass assignable. | |
* | |
* @var array | |
*/ | |
protected $fillable = [ | |
'name', 'email', 'password', | |
]; | |
/** | |
* The attributes that should be hidden for arrays. | |
* | |
* @var array | |
*/ | |
protected $hidden = [ | |
'password', 'remember_token', | |
]; | |
public function reviews() | |
{ | |
return $this->hasMany(Review::class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment