#4: Comments can now be posted from a photo page in the gallery, and are saved in the database in the photo_comments table.

This commit is contained in:
2018-09-17 14:15:06 +01:00
parent c2e71b0084
commit 0ebd7a1c5f
11 changed files with 180 additions and 4 deletions
@@ -0,0 +1,50 @@
<?php
namespace App\Http\Controllers\Gallery;
use App\Facade\UserConfig;
use App\Helpers\DbHelper;
use App\Http\Controllers\Controller;
use App\PhotoComment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
class PhotoCommentController extends Controller
{
public function store(Request $request, $albumUrlAlias, $photoFilename)
{
$album = DbHelper::getAlbumByPath($albumUrlAlias);
if (is_null($album))
{
App::abort(404);
return null;
}
$this->authorizeForUser($this->getUser(), 'view', $album);
$photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename);
if (!UserConfig::get('allow_photo_comments'))
{
// Not allowed to post comments - redirect back to URL
return redirect($photo->url());
}
$comment = new PhotoComment();
$comment->photo_id = $photo->id;
$comment->fill($request->only(['commentor_email', 'commentor_name', 'comment_text']));
$user = $this->getUser();
if (!is_null($user) && !$user->isAnonymous())
{
$comment->created_user_id = $user->id;
}
$comment->save();
$request->getSession()->flash('success', trans('gallery.photo_comment_posted_successfully'));
return redirect($photo->url());
}
}
@@ -157,7 +157,8 @@ class PhotoController extends Controller
'is_original_allowed' => $isOriginalAllowed,
'next_photo' => $nextPhoto,
'photo' => $photo,
'previous_photo' => $previousPhoto
'previous_photo' => $previousPhoto,
'success' => $request->getSession()->get('success')
]);
}
+8
View File
@@ -77,6 +77,14 @@ class Photo extends Model
return $this->belongsToMany(Label::class, 'photo_labels');
}
public function postCommentUrl()
{
return route('postPhotoComment', [
'albumUrlAlias' => $this->album->url_path,
'photoFilename' => $this->storage_file_name
]);
}
public function thumbnailUrl($thumbnailName = null, $cacheBust = true)
{
$url = $this->album->getAlbumSource()->getUrlToPhoto($this, $thumbnailName);
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PhotoComment extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'commentor_name',
'commentor_email',
'comment_text'
];
}