Php 500内部服务器错误ajax/laravel
因此,我试图创建一个动态评论部分,但这个问题似乎困扰我500内部服务器错误。我读过一些关于这个问题的文章,但我无法解决它。我使用了一些代码片段来查找问题,但仍然找不到问题所在 create.blade.php-Php 500内部服务器错误ajax/laravel,php,laravel,Php,Laravel,因此,我试图创建一个动态评论部分,但这个问题似乎困扰我500内部服务器错误。我读过一些关于这个问题的文章,但我无法解决它。我使用了一些代码片段来查找问题,但仍然找不到问题所在 create.blade.php- <h1>Create comment</h1> {!! Form::open(['id' => 'myForm', 'enctype' => 'multipart/form-data']) !!} <div class="form-group"
<h1>Create comment</h1>
{!! Form::open(['id' => 'myForm', 'enctype' => 'multipart/form-data']) !!}
<div class="form-group">
{{ Form::textarea('body', '', ['class' => 'form-control', 'id' => 'article-ckeditor', 'placeholder' => 'Share your thoughts related to this post']) }}
</div>
{{ Form::hidden('post_id', $post->id) }}
{{Form::submit('Submit', ['class' => 'btn btn-primary', 'id' => 'submitComment'])}}
{!! Form::close() !!}
CommentsController@store-
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'body' => 'required'
]);
if ($validator->fails()) {
if($request->ajax())
{
return response()->json(array(
'success' => false,
'message' => 'There are incorect values in the form!',
'errors' => $validator->getMessageBag()->toArray()
), 422);
}
$this->throwValidationException(
$request, $validator
);
}
// Create Post
$comment = new Comment;
$comment->body = $request->body;
$comment->user_name = auth()->user()->name;
$comment->post_id = $request->post_id;
$comment->profile_picture = auth()->user()->profile_picture;
$comment->save();
return response()->json(['success'=>'Data is successfully added']);
//return redirect()->back()->with('success', 'Comment Created');
检查错误日志以了解实际错误及其位置thrown@Nikola请发布你的错误。。。并检查您的laravel或更深入地挖掘服务器日志。。。
Route::resource('/comments', 'CommentsController');
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'body' => 'required'
]);
if ($validator->fails()) {
if($request->ajax())
{
return response()->json(array(
'success' => false,
'message' => 'There are incorect values in the form!',
'errors' => $validator->getMessageBag()->toArray()
), 422);
}
$this->throwValidationException(
$request, $validator
);
}
// Create Post
$comment = new Comment;
$comment->body = $request->body;
$comment->user_name = auth()->user()->name;
$comment->post_id = $request->post_id;
$comment->profile_picture = auth()->user()->profile_picture;
$comment->save();
return response()->json(['success'=>'Data is successfully added']);
//return redirect()->back()->with('success', 'Comment Created');