$errors returns null in laravel 5.4












0















So i'm working with laravel 5.4 and i'm stuck in this error and can't figure it out.I researched about this error and i've seen that this happened before to, but the solutions are not working on my project.



I created a form to add comments in my page and it works if i type something it saves it in database and validation is working to because its not letting me add empty comment but its not showing the errors in page.
This is the comment form in views



<form method="post" action="{{ route('comments.store') }}">
{{ csrf_field() }}

<input type="hidden" name="commentable_type" value="AppCompany">
<input type="hidden" name="commentable_id" value="{{ $company->id }}">

<h2>Add a comment</h2>
<div class="form-group @if($errors->has('url')) has-error @endif">
<label for="comment-content">Work done (url/title)</label>
<textarea placeholder="Enter url/title"
style="resize: vertical;"
id="comment-content"
name="url"
rows="2"
spellcheck="false"
class="form-control autosize-target text-left">
</textarea>
</div>

<div class="form-group @if($errors->has('body')) has-error @endif">
<label for="comment-content">Comment</label>
<textarea placeholder="Enter comment"
style="resize: vertical;"
id="comment-content"
name="body"
rows="3"
spellcheck="false"
class="form-control autosize-target text-left">
</textarea>
</div>

<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit"/>
</div>
</form>


This is the CommentsControlles.php



public function store(CommentSubmitFormRequest $request)
{
$comment = Comment::create([
'body' => $request->input('body'),
'url' => $request->input('url'),
'commentable_type' => $request->input('commentable_type'),
'commentable_id' => $request->input('commentable_id'),
'user_id' => Auth::user()->id
]);

if ($comment)
{
return back()->with('success', 'Comment added successfully');
}
}


And this is the Request CommentSubmitFormRequest.php



class CommentSubmitFormRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'body' => 'required',
'url' => 'required',
];
}
}


When i submit the empty comment form the $errors is returning null and not the errors










share|improve this question





























    0















    So i'm working with laravel 5.4 and i'm stuck in this error and can't figure it out.I researched about this error and i've seen that this happened before to, but the solutions are not working on my project.



    I created a form to add comments in my page and it works if i type something it saves it in database and validation is working to because its not letting me add empty comment but its not showing the errors in page.
    This is the comment form in views



    <form method="post" action="{{ route('comments.store') }}">
    {{ csrf_field() }}

    <input type="hidden" name="commentable_type" value="AppCompany">
    <input type="hidden" name="commentable_id" value="{{ $company->id }}">

    <h2>Add a comment</h2>
    <div class="form-group @if($errors->has('url')) has-error @endif">
    <label for="comment-content">Work done (url/title)</label>
    <textarea placeholder="Enter url/title"
    style="resize: vertical;"
    id="comment-content"
    name="url"
    rows="2"
    spellcheck="false"
    class="form-control autosize-target text-left">
    </textarea>
    </div>

    <div class="form-group @if($errors->has('body')) has-error @endif">
    <label for="comment-content">Comment</label>
    <textarea placeholder="Enter comment"
    style="resize: vertical;"
    id="comment-content"
    name="body"
    rows="3"
    spellcheck="false"
    class="form-control autosize-target text-left">
    </textarea>
    </div>

    <div class="form-group">
    <input type="submit" class="btn btn-primary" value="Submit"/>
    </div>
    </form>


    This is the CommentsControlles.php



    public function store(CommentSubmitFormRequest $request)
    {
    $comment = Comment::create([
    'body' => $request->input('body'),
    'url' => $request->input('url'),
    'commentable_type' => $request->input('commentable_type'),
    'commentable_id' => $request->input('commentable_id'),
    'user_id' => Auth::user()->id
    ]);

    if ($comment)
    {
    return back()->with('success', 'Comment added successfully');
    }
    }


    And this is the Request CommentSubmitFormRequest.php



    class CommentSubmitFormRequest extends FormRequest
    {
    public function authorize()
    {
    return true;
    }
    public function rules()
    {
    return [
    'body' => 'required',
    'url' => 'required',
    ];
    }
    }


    When i submit the empty comment form the $errors is returning null and not the errors










    share|improve this question



























      0












      0








      0


      0






      So i'm working with laravel 5.4 and i'm stuck in this error and can't figure it out.I researched about this error and i've seen that this happened before to, but the solutions are not working on my project.



      I created a form to add comments in my page and it works if i type something it saves it in database and validation is working to because its not letting me add empty comment but its not showing the errors in page.
      This is the comment form in views



      <form method="post" action="{{ route('comments.store') }}">
      {{ csrf_field() }}

      <input type="hidden" name="commentable_type" value="AppCompany">
      <input type="hidden" name="commentable_id" value="{{ $company->id }}">

      <h2>Add a comment</h2>
      <div class="form-group @if($errors->has('url')) has-error @endif">
      <label for="comment-content">Work done (url/title)</label>
      <textarea placeholder="Enter url/title"
      style="resize: vertical;"
      id="comment-content"
      name="url"
      rows="2"
      spellcheck="false"
      class="form-control autosize-target text-left">
      </textarea>
      </div>

      <div class="form-group @if($errors->has('body')) has-error @endif">
      <label for="comment-content">Comment</label>
      <textarea placeholder="Enter comment"
      style="resize: vertical;"
      id="comment-content"
      name="body"
      rows="3"
      spellcheck="false"
      class="form-control autosize-target text-left">
      </textarea>
      </div>

      <div class="form-group">
      <input type="submit" class="btn btn-primary" value="Submit"/>
      </div>
      </form>


      This is the CommentsControlles.php



      public function store(CommentSubmitFormRequest $request)
      {
      $comment = Comment::create([
      'body' => $request->input('body'),
      'url' => $request->input('url'),
      'commentable_type' => $request->input('commentable_type'),
      'commentable_id' => $request->input('commentable_id'),
      'user_id' => Auth::user()->id
      ]);

      if ($comment)
      {
      return back()->with('success', 'Comment added successfully');
      }
      }


      And this is the Request CommentSubmitFormRequest.php



      class CommentSubmitFormRequest extends FormRequest
      {
      public function authorize()
      {
      return true;
      }
      public function rules()
      {
      return [
      'body' => 'required',
      'url' => 'required',
      ];
      }
      }


      When i submit the empty comment form the $errors is returning null and not the errors










      share|improve this question
















      So i'm working with laravel 5.4 and i'm stuck in this error and can't figure it out.I researched about this error and i've seen that this happened before to, but the solutions are not working on my project.



      I created a form to add comments in my page and it works if i type something it saves it in database and validation is working to because its not letting me add empty comment but its not showing the errors in page.
      This is the comment form in views



      <form method="post" action="{{ route('comments.store') }}">
      {{ csrf_field() }}

      <input type="hidden" name="commentable_type" value="AppCompany">
      <input type="hidden" name="commentable_id" value="{{ $company->id }}">

      <h2>Add a comment</h2>
      <div class="form-group @if($errors->has('url')) has-error @endif">
      <label for="comment-content">Work done (url/title)</label>
      <textarea placeholder="Enter url/title"
      style="resize: vertical;"
      id="comment-content"
      name="url"
      rows="2"
      spellcheck="false"
      class="form-control autosize-target text-left">
      </textarea>
      </div>

      <div class="form-group @if($errors->has('body')) has-error @endif">
      <label for="comment-content">Comment</label>
      <textarea placeholder="Enter comment"
      style="resize: vertical;"
      id="comment-content"
      name="body"
      rows="3"
      spellcheck="false"
      class="form-control autosize-target text-left">
      </textarea>
      </div>

      <div class="form-group">
      <input type="submit" class="btn btn-primary" value="Submit"/>
      </div>
      </form>


      This is the CommentsControlles.php



      public function store(CommentSubmitFormRequest $request)
      {
      $comment = Comment::create([
      'body' => $request->input('body'),
      'url' => $request->input('url'),
      'commentable_type' => $request->input('commentable_type'),
      'commentable_id' => $request->input('commentable_id'),
      'user_id' => Auth::user()->id
      ]);

      if ($comment)
      {
      return back()->with('success', 'Comment added successfully');
      }
      }


      And this is the Request CommentSubmitFormRequest.php



      class CommentSubmitFormRequest extends FormRequest
      {
      public function authorize()
      {
      return true;
      }
      public function rules()
      {
      return [
      'body' => 'required',
      'url' => 'required',
      ];
      }
      }


      When i submit the empty comment form the $errors is returning null and not the errors







      php laravel laravel-5.4






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 13:20







      Ardit Imeri

















      asked Nov 22 '18 at 13:04









      Ardit ImeriArdit Imeri

      115




      115
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Your validation rules are incomplete. It only said to be required and in your case your body and url are sent because the fields do exists. You should set a minimum amount of characters or do active_url/url for the url field.



          public function rules()
          {
          return [
          'body' => 'required|min:1', // minimum length of 1 character
          'url' => 'required|url', // must be a valid URL
          ];
          }





          share|improve this answer
























          • This form is not letting me add empty body or not valid url in database which is good but the message is not showing in the page. The $errors is returning null again!

            – Ardit Imeri
            Nov 22 '18 at 13:31













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431679%2ferrors-returns-null-in-laravel-5-4%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Your validation rules are incomplete. It only said to be required and in your case your body and url are sent because the fields do exists. You should set a minimum amount of characters or do active_url/url for the url field.



          public function rules()
          {
          return [
          'body' => 'required|min:1', // minimum length of 1 character
          'url' => 'required|url', // must be a valid URL
          ];
          }





          share|improve this answer
























          • This form is not letting me add empty body or not valid url in database which is good but the message is not showing in the page. The $errors is returning null again!

            – Ardit Imeri
            Nov 22 '18 at 13:31


















          0














          Your validation rules are incomplete. It only said to be required and in your case your body and url are sent because the fields do exists. You should set a minimum amount of characters or do active_url/url for the url field.



          public function rules()
          {
          return [
          'body' => 'required|min:1', // minimum length of 1 character
          'url' => 'required|url', // must be a valid URL
          ];
          }





          share|improve this answer
























          • This form is not letting me add empty body or not valid url in database which is good but the message is not showing in the page. The $errors is returning null again!

            – Ardit Imeri
            Nov 22 '18 at 13:31
















          0












          0








          0







          Your validation rules are incomplete. It only said to be required and in your case your body and url are sent because the fields do exists. You should set a minimum amount of characters or do active_url/url for the url field.



          public function rules()
          {
          return [
          'body' => 'required|min:1', // minimum length of 1 character
          'url' => 'required|url', // must be a valid URL
          ];
          }





          share|improve this answer













          Your validation rules are incomplete. It only said to be required and in your case your body and url are sent because the fields do exists. You should set a minimum amount of characters or do active_url/url for the url field.



          public function rules()
          {
          return [
          'body' => 'required|min:1', // minimum length of 1 character
          'url' => 'required|url', // must be a valid URL
          ];
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 13:24









          Yoram de LangenYoram de Langen

          3,90511727




          3,90511727













          • This form is not letting me add empty body or not valid url in database which is good but the message is not showing in the page. The $errors is returning null again!

            – Ardit Imeri
            Nov 22 '18 at 13:31





















          • This form is not letting me add empty body or not valid url in database which is good but the message is not showing in the page. The $errors is returning null again!

            – Ardit Imeri
            Nov 22 '18 at 13:31



















          This form is not letting me add empty body or not valid url in database which is good but the message is not showing in the page. The $errors is returning null again!

          – Ardit Imeri
          Nov 22 '18 at 13:31







          This form is not letting me add empty body or not valid url in database which is good but the message is not showing in the page. The $errors is returning null again!

          – Ardit Imeri
          Nov 22 '18 at 13:31




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431679%2ferrors-returns-null-in-laravel-5-4%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'