vendredi 29 septembre 2017

can u guide me how can i send data into two tables in a single form for doing Create and Update

this is my likes model

class Like extends Model { protected $fillable = [ 'user_id','post_id','value', ];

public function user()
{
    return $this->belongsTo('App\User');


    //$this->belongsTo(User::class);
    //return $this->belongsTo('App\User');
    //   return $this->belongsTo('App\User','id','user_id');

}
public function post()
{
    return $this->belongsTo('App\Post');


    //$this->belongsTo(User::class);
    //return $this->belongsTo('App\User');
    //   return $this->belongsTo('App\User','id','user_id');

}

Post.php

protected $fillable = [ 'user_id','content', 'live','post_on','likes' ]; protected $dates = ['post_on'];

public function SetLiveAttribute($value)
{
    $this->attributes['live'] = (boolean)($value);

}


public function getshortContAttribute(){
    return substr($this->content, 0, random_int(60,150)). '...';
}

public function SetPostOnAttribute($value){
    $this->attributes['post_on'] = Carbon::parse($value);
}


public function user()
{
    //$this->belongsTo(User::class);
    //return $this->belongsTo('App\User');
 //   return $this->belongsTo('App\User','id','user_id');
    return $this->belongsTo('App\User');


}
public function comment(){

    return $this->hasMany('App\Comment');
}
public function like()
{
    return $this->hasMany('App\Like');


    //$this->belongsTo(User::class);
    //return $this->belongsTo('App\User');
    //   return $this->belongsTo('App\User','id','user_id');

}

}

please help in this . i m confuse . i have used Method Field PUT in form .



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire