Skip to content

Instantly share code, notes, and snippets.

@Cerwyn
Created April 16, 2020 06:52
Show Gist options
  • Save Cerwyn/4089d9fdbceb71dccac8584566366aa7 to your computer and use it in GitHub Desktop.
Save Cerwyn/4089d9fdbceb71dccac8584566366aa7 to your computer and use it in GitHub Desktop.
One-to-many
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $fillable = [
'title', 'slug', 'body',
];
public function comments(){
return $this->hasMany('App\Comment');
}
public function set_best_comment($comment){
$this->best_comment_id = $comment->id;
return $this->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment