12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace App;
- use Illuminate\Notifications\Notifiable;
- 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 posts() {
- return $this->hasMany(Post::class);
- }
- public function publish(Post $post) {
- // Why not $post->save(); ?
- // It would not carry the user information present in the posts() collection.
- $this->posts()->save($post);
- }
- }
|