Merge photo comments feature #114
@ -11,6 +11,7 @@ use App\PhotoComment;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PhotoCommentController extends Controller
|
||||
{
|
||||
@ -45,7 +46,7 @@ class PhotoCommentController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StorePhotoCommentRequest $request, $albumUrlAlias, $photoFilename)
|
||||
public function store(Request $request, $albumUrlAlias, $photoFilename)
|
||||
{
|
||||
$album = DbHelper::getAlbumByPath($albumUrlAlias);
|
||||
if (is_null($album))
|
||||
@ -64,11 +65,9 @@ class PhotoCommentController extends Controller
|
||||
return redirect($photo->url());
|
||||
}
|
||||
|
||||
$comment = new PhotoComment();
|
||||
$comment->photo_id = $photo->id;
|
||||
$comment->fill($request->only(['commentor_email', 'commentor_name', 'comment_text']));
|
||||
|
||||
// Validate and link the parent comment, if provided
|
||||
// We do this here so if the validation fails, we still have the parent comment available in the catch block
|
||||
$parentComment = null;
|
||||
if ($request->has('parent_comment_id'))
|
||||
{
|
||||
$parentComment = $photo->comments()->where('id', intval($request->get('parent_comment_id')))->first();
|
||||
@ -78,7 +77,22 @@ class PhotoCommentController extends Controller
|
||||
$request->getSession()->flash('success', trans('gallery.photo_comment_posted_successfully'));
|
||||
return redirect($photo->url());
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->validate($request, [
|
||||
'commentor_name' => 'required|max:255',
|
||||
'commentor_email' => 'sometimes|max:255|email',
|
||||
'comment_text' => 'required'
|
||||
]);
|
||||
|
||||
$comment = new PhotoComment();
|
||||
$comment->photo_id = $photo->id;
|
||||
$comment->fill($request->only(['commentor_email', 'commentor_name', 'comment_text']));
|
||||
|
||||
if (!is_null($parentComment))
|
||||
{
|
||||
$comment->parent_comment_id = $parentComment->id;
|
||||
}
|
||||
|
||||
@ -95,10 +109,21 @@ class PhotoCommentController extends Controller
|
||||
if ($request->isXmlHttpRequest())
|
||||
{
|
||||
return response()->json(['redirect_url' => $photo->url()]);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
return redirect($photo->url());
|
||||
}
|
||||
}
|
||||
catch (ValidationException $e)
|
||||
{
|
||||
if (!is_null($parentComment))
|
||||
{
|
||||
return redirect()->to($photo->replyToCommentFormUrl($parentComment->id))->withErrors($e->errors());
|
||||
}
|
||||
else
|
||||
{
|
||||
return redirect()->back()->withErrors($e->errors());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StorePhotoCommentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'commentor_name' => 'required|max:255',
|
||||
'commentor_email' => 'sometimes|max:255|email',
|
||||
'comment_text' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
@ -39,8 +39,15 @@ function PhotoViewModel(urls) {
|
||||
|
||||
var formData = form.serialize();
|
||||
$.post(formUrl, formData, function(result)
|
||||
{
|
||||
if (result.redirect_url)
|
||||
{
|
||||
window.location = result.redirect_url;
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#comment-reply-form-content').html(result);
|
||||
}
|
||||
});
|
||||
},
|
||||
replyToComment: function(e) {
|
||||
|
Loading…
Reference in New Issue
Block a user