我创建的社交媒体允许用户查看他/她访问过的地方。我已经通过了评级,内容以及审核该地点的用户ID,但我似乎无法通过该地方的ID。这是我发布评论的控制器:
class PlaceController extends Controller
{
public function postReview(Request $request)
{
$rating = $request['rating'];
$content = $request['content'];
$review = new Review();
$review ->rating=$rating;
$review ->content=$content;
$request->user()->reviews()->save($review);
return redirect()->back();
}
}
以下是我的评论模型:
class Review extends Model
{
use SoftDeletes;
protected $table = 'place_reviews';
protected $dates = ['deleted_at'];
public function place()
{
return $this->belongsTo('Keleus\Eloquent\Place\Place');
}
public function user()
{
return $this->belongsTo('Keleus\Eloquent\User\User');
}
public function scopeOfPlace($query, $placeId)
{
return $query->where('place_id', $placeId)->whereNotNull('place_id');
}
}
请注意,评论的输入仅为评分和内容,用户ID和地点ID。