#4: Added a basic template for the comment design. Comments now display nested. Renamed the columns in the database table so the default validation error messages look better. Corrected a few issues with the TinyMCE implementation.
This commit is contained in:
@@ -74,7 +74,7 @@ class PhotoCommentController extends Controller
|
||||
|
||||
if (is_null($parentComment))
|
||||
{
|
||||
$request->getSession()->flash('success', trans('gallery.photo_comment_posted_successfully'));
|
||||
//TODO $request->getSession()->flash('success', trans('gallery.photo_comment_posted_successfully'));
|
||||
return redirect($photo->url());
|
||||
}
|
||||
}
|
||||
@@ -82,14 +82,14 @@ class PhotoCommentController extends Controller
|
||||
try
|
||||
{
|
||||
$this->validate($request, [
|
||||
'commentor_name' => 'required|max:255',
|
||||
'commentor_email' => 'sometimes|max:255|email',
|
||||
'comment_text' => 'required'
|
||||
'name' => 'required|max:255',
|
||||
'email' => 'sometimes|max:255|email',
|
||||
'comment' => 'required'
|
||||
]);
|
||||
|
||||
$comment = new PhotoComment();
|
||||
$comment->photo_id = $photo->id;
|
||||
$comment->fill($request->only(['commentor_email', 'commentor_name', 'comment_text']));
|
||||
$comment->fill($request->only(['name', 'email', 'comment']));
|
||||
|
||||
if (!is_null($parentComment))
|
||||
{
|
||||
|
||||
+31
-3
@@ -12,9 +12,9 @@ class PhotoComment extends Model
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'commentor_name',
|
||||
'commentor_email',
|
||||
'comment_text'
|
||||
'name',
|
||||
'email',
|
||||
'comment'
|
||||
];
|
||||
|
||||
public function approvedBy()
|
||||
@@ -22,6 +22,21 @@ class PhotoComment extends Model
|
||||
return $this->belongsTo(User::class, 'approved_user_id');
|
||||
}
|
||||
|
||||
public function approvedChildren()
|
||||
{
|
||||
return $this->children()->whereNotNull('approved_at');
|
||||
}
|
||||
|
||||
public function authorDisplayName()
|
||||
{
|
||||
return is_null($this->createdBy) ? $this->name : $this->createdBy->name;
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(PhotoComment::class, 'parent_comment_id');
|
||||
}
|
||||
|
||||
public function createdBy()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_user_id');
|
||||
@@ -45,4 +60,17 @@ class PhotoComment extends Model
|
||||
{
|
||||
return $this->belongsTo(PhotoComment::class, 'parent_comment_id');
|
||||
}
|
||||
|
||||
public function textAsHtml()
|
||||
{
|
||||
$start = '<p>';
|
||||
$end = '</p>';
|
||||
$isHtml = (
|
||||
strlen($this->comment) > (strlen($start) + strlen($end)) && // text contains both our start + end string
|
||||
strtolower(substr($this->comment, 0, strlen($start))) == strtolower($start) && // text starts with our start string
|
||||
strtolower(substr($this->comment, strlen($this->comment) - strlen($end))) == strtolower($end) // text ends with our end string
|
||||
);
|
||||
|
||||
return $isHtml ? $this->comment : sprintf('<p>%s</p>', $this->comment);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user