Laravel Tutorials
- What is laravel
- Laravel Installation
- Directory Structure
- htaccess
- Remove public from url
- Artisan Command
- Laravel Configuration
- Routing Configuration
- Namespaces
- Request
- Response
- Controller
- Model
- User Authentication
- Multi User Authentication
- Database Seeding
- Database
- Database Query
- ORM
- One-to-One Relationship
- One-to-Many Relationship
- Many to Many Eloquent Relationship
- Has One Through
- Has Many Through
- Querying Relations
- Middleware
- Laravel Views
- Blade Views
- Print data on view page
- Get Site URL
- Get URL Segment
- Get images from Storage folder
- Clear cache
- Form Class not found
- Flash Message in laravel
- Redirections
- path
- CRUD Projerct
- CRUD in Laravel
- CRUD progran
- Laravel Validation
- Jquery Validation
- Cookie
- Session
- Email Send in laravel
- File uploading
- CSRF Protection
- Helper in Laravel
- Helper Functions
- Guzzle Http Client
- Paypal Payment Gatway Integration
- Cron Job in laravel
- Flash message
- path
- Errors Handling
- Date Format
- Date Format Validation
- Display Image on View Page
- Update User Status using toggle button
- Delete Multiple Records using Checkbox in Laravel?
- Confirmation Before Delete Record
- Delete image from storage
- Remove/Trim Empty & Whitespace From Input Requests
- Block IP Addresses from Accessing Website
- How to Disable New User Registration in Laravel
- Redirect HTTP To HTTPS Using Laravel Middleware
- CKEditor
- slug generate unique
- Prevent Browser's Back Button After Logout
- Datatable dunamically
- encrypt & Decript
- Download File
- Rest API
- Shopping Cart
- Shopping Cart Example
- Dynamic Category-Subcategory Menu
- Ajax Search
- Interview Question
- laravel Tutorilal link
- laravel Tutorilal
Important Links
validation in laravel?
Laravel will always check for errors in the session data, and automatically bind them to the view if they are available.
$errors variable will always be used in all of your views on every request.
File name : index.php
Accepted
Active URL
After (Date)
Alpha
Alpha Dash
Alpha Numeric
Array
Before (Date)
Between
Boolean
Confirmed
Date
Date Format
Different
Digits
Digits Between
E-Mail
Exists (Database)
Image (File)
In
Integer
IP Address
JSON
Max
MIME Types(File)
Min
Not In
Numeric
Regular Expression
Required
Required If
Required Unless
Required With
Required With All
Required Without
Required Without All
Same
Size
String
Timezone
Unique (Database)
URL
The $errors variable will be an instance of Illuminate\Support\MessageBag. Error message can be displayed in view file
@if (count($errors) > 0)
<div class = "alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
UserRegisterController.php
public function validateform(Request $request) {
print_r($request->all());
$this->validate($request,[
'name' => 'required|max:8|min:4',
'email' => 'required|email',
'mobile' => 'required|Numeric|max:10',
'gender' => 'required',
'hobbies' => 'required',
'message' => 'required|alphaNum|min:20'
'post' => 'required|unique:posts|max:255',
'title' => 'required|unique|max:255',
"amount" =>" required|regex:/^\d+(\.\d{1,2})?$/",
"amount" =>" required|regex:/^\d{1,13}(\.\d{1,4})?$/",
//'name' => 'required|alpha',
//'name' => 'required|alpha_spaces',
'name' => 'regex:/([A-Za-z])+/',
'email' => 'required|email',
'password' => 'required|alphaNum|max:20|min:4',
//'phone' => 'required|digits:10', // work fine
'phone' => 'required|numeric|digits:10|starts_with: 6,7,8,9'
//'phone' => 'required|numeric|between:9,11',
//'phone' => 'required|min:10|numeric',
//'phone' => 'required|regex:/(01)[0-9]{9}/',
//'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10'
]);
}
ContactController.php
public function contact(Request $request)
{
$rules = [
'name' => 'required',
'email' => 'required|email',
'message' => 'required|min:5',
];
$this->validate($request, $rules);
// send contact details to email address
return back()->with("status", "Your message has been received, We'll get back to you shortly.");
}
validation in inline input field
File name : index.php
<div class="form-group {{ $errors->has('name') ? 'has-error' : ''}}">
<label for="name" class="col-sm-3 control-label">Name: </label>
<div class="col-sm-6">
<input class="form-control" required="required" name="name" type="text" id="name">
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
File name : index.php
<div class="col-md-8">
<!-- <form method="post" action="{{ url('/main/checklogin') }}"> -->
<form name="frm" action="{{url('emailsend')}}" method="post">
<!-- {{ csrf_field() }} -->
@csrf
<!-- <input type = "hidden" name = "_token" value = "<?php //echo csrf_token(); ?>">-->
<div class="form-group" {{ $errors->has('name') ? 'has-error' : ''}}>
<label>Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter Name">
{!! $errors->first('name', '<p class="help-block" style="color:red;">:message</p>') !!}
</div>
<div class="form-group">
<label>Email</label> <input type="text" class="form-control" name="email" id="email"
placeholder="Enter Email">
{!! $errors->first('email', '<p class="help-block" style="color:red;">:message</p>') !!}
</div>
<div class="form-group">
<label>Mobile</label> <input type="text" class="form-control" name="mobile" id="mobile"
placeholder="Enter Mobile">
{!! $errors->first('mobile', '<p class="help-block" style="color:red;">:message</p>') !!}
</div>
<div class="form-group">
<label>Gender</label>
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="female">Female
</div>
<input type="checkbox" name="hobbies[]" value="Musics">Musics
<input type="checkbox" name="hobbies[]" value="cricket">cricket
<input type="checkbox" name="hobbies[]" value="NET">NET
<input type="checkbox" name="hobbies[]" value="Sweeming">Sweeming
<div class="form-group">
<label for="exampleFormControlTextarea1">Message</label>
<textarea class="form-control" name="message"
id="message" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
Validation Form :-
<form action="{{ url('contact') }}" method="POST">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" value="{{ old('name')}}">
<small class="text-danger">{{ $errors->first('name') }}</small>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email">Email Address</label>
<input type="email" name="email" class="form-control" value="{{ old('email')}}">
<small class="text-danger">{{ $errors->first('email') }}</small>
</div>
<div class="form-group{{ $errors->has('message') ? ' has-error' : '' }}">
<label for="message">Message</label>
<textarea name="message" class="form-control" rows="5">{{ old('message')}}</textarea>
<small class="text-danger">{{ $errors->first('message') }}</small>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" value="{{ old('name')}}">
<small class="text-danger">{{ $errors->first('name') }}</small>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email">Email Address</label>
<input type="email" name="email" class="form-control" value="{{ old('email')}}">
<small class="text-danger">{{ $errors->first('email') }}</small>
</div>
<div class="form-group{{ $errors->has('message') ? ' has-error' : '' }}">
<label for="message">Message</label>
<textarea name="message" class="form-control" rows="5">{{ old('message')}}</textarea>
<small class="text-danger">{{ $errors->first('message') }}</small>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
NO Space validation
File name : index.php
public function store(Request $request)
{
\Validator::extend('without_spaces', function($attr, $value){
return preg_match('/^\S*$/u', $value);
});
$request->validate([
'username' => 'required|without_spaces|unique:user_detail,username',
]);
return redirect()->back();
}
NO Space validation
File name : index.php
public function store(Request $request)
{
$request->validate([
'username' => 'required|regex:/^\S*$/u',
]);
return redirect()->back();
}
File name : index.php
File name : index.php