Search
 
SCRIPT & CODE EXAMPLE
 

HTML

Server side validations Laravel

//First, validate the request object and add a message for every field

$validatedData = $request->validate([
                'name' => 'required',
                'password' => 'required|min:5',
                'email' => 'required|email|unique:users'
            ], [
                'name.required' => 'Name is required',
                'password.required' => 'Password is required'
            ]);
            
//Second, add a condition in the view to show the error, if it exist

<div class="form-group">
<label>Name:</label>
<input type="text" name="name" class="form-control" placeholder="Name">
@if ($errors->has('name'))
	<span class="text-danger">{{ $errors->first('name') }}</span>
@endif
</div>


//alert version 

@if ($errors)
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                @foreach ($errors->all() as $error)
                    @if (count($errors->all()) > 1)
                        <strong>{{ $error }}</strong> <br>
                    @else
                        <strong>{{ $error }}</strong>
                    @endif
                @endforeach
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
        @endif
Comment

PREVIOUS NEXT
Code Example
Html :: how to italicize in html 
Html :: <p tag html 
Html :: bootstrap gutter 
Html :: ip html 
Html :: javascript inside html 
Html :: hack nasa with html 
Html :: html element hover help text 
Html :: how to put dowloadable resume on website html 
Html :: html scale svg 
Html :: The href Attribute in html 
Html :: html doc 
Html :: textbox with dropdown bootstrap 
Html :: visual studio code html template shortcut 
Html :: html elements 
Html :: button that links to controller html 
Html :: accordion html 
Html :: allow multiple select on radio button in html 
Html :: Installation of ionicons 
Html :: html insert image 
Html :: form controller in bootstrap 
Html :: simple html report template 
Html :: html small text 
Html :: tailwind css floating label 
Html :: best html emmet extension for vs code 
Html :: wright word with < in html p tag 
Html :: the function tag in js 
Html :: html code heavy left arrow 
Html :: a tag displays below img tag 
Html :: input type checkbox and hide checkbox 
Html :: game code in html 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =