UserモデルにAuthenticatableとModelを継承しようとしております。
PHP(laravel)で投稿機能のあるウェブアプリをつくっています。
authをつかってアカウント認証に必要な機能を実装しました。
その後Userが持つpostsをhasmanyで呼び出せるようにしたいのですが、
記述場所に困っています。
authを使ったことでAuthenticatableがUserクラスにすでに継承されており、
Modelを継承することができません。
調べたところ複数継承するにはtraitを使うようなのですが、
Authenticatableクラス・Modelクラスの中身が分からず、traitに置き換えることができません。
###該当のソースコード
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Database\Eloquent\Model; 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', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; } /* class User extends Model { public function posts() { return $this->hasMany('App\Post'); } } */
下の方でコメントアウトしている部分を使えるようにしたいです。
この問題の解決方法がわかる方がいらっしゃいましたら、
お手数ですが少しだけでいいのでヒントをください。お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/16 01:20