'Registration not working in Laravel 5
I am trying to use the validation for a registration page but not getting success, just displaying the same page and no data is getting inserted into the database neither on unique email nor on repeated email. I am doing this in Laravel 5.
Here if my route in routes.php file:
Route::get('/registration_page', 'makelogin@registration_function');
Here is controller
public function registration_function(Request $request)
{
$nam_value = $request->nam;
$email_value = $request->r_email;
$password_value = $request->r_password;
$city_value = $request->city;
$this->validate($request, [
'email' => 'required|unique:registered|max:255',
'password' => 'required',
]);
$reg=DB::table('registered')->insert(['name' => $nam_value, 'email' => $email_value,
'password'=>$password_value,'city'=>$city_value]);
return redirect('makelogin_page')->with('status','Registered Successfully');
}
and here is the blade.php file(view)
<div class="container">
<h3>New user ?</h3>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#registration">Register</button>
<!-- Modal -->
<div class="modal fade" id="registration" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Registration</h4>
</div>
<div class="modal-body">
<p>Please Register Yourself Here</p>
<form role="form" action="registration_page" method="get">
<div class="form-group">
<input type="text" class="form-control" name="nam" placeholder="Your Name Please" style="width:265px;">
</div>
<div class="form-group">
<input type="email" class="form-control" name="r_email" placeholder="Your Email Please" style="width:265px;">
</div>
<div class="form-group">
<input type="password" class="form-control" name="r_password" placeholder="Please enter a password" style="width:265px;">
</div>
<div class="form-group">
<input type="text" class="form-control" name="city" placeholder="Please enter your city" style="width:265px;">
</div>
<div class="form-group">
<input type="submit" class="btn btn-info" value="Register">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Solution 1:[1]
Here is its route
Route::get('/registration_page', 'makelogin@registration_function');
Here is its controller
> public function registration_function(Request $request)
> {
> $nam_value = $request->nam;
> $email_value = $request->r_email;
> $password_value = $request->r_password;
> $city_value = $request->city;
> $hashed_password = bcrypt($password_value);
> $valid_user = DB::table('registered')
> ->where('email',$email_value)
> ->get();
> if($valid_user)
> {
> return redirect('makelogin_page')->with('status_validate','You are already registered with us, Plaese login, Did you forgot your
> password ?');
> }
> else
> {
> $reg=DB::table('registered')->insert(['name' => $nam_value, 'email' => $email_value,
> 'password'=>$hashed_password,'city'=>$city_value]);
> return redirect('makelogin_page')->with('status','Registered Successfully');
> }
> }
And here is its view
> <div class="container">
> <h3>New user ?</h3>
> <!-- Trigger the modal with a button -->
> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#registration">Register</button>
> <!-- Modal -->
> <div class="modal fade" id="registration" role="dialog">
> <div class="modal-dialog modal-sm">
> <div class="modal-content">
> <div class="modal-header">
> <button type="button" class="close" data-dismiss="modal">×</button>
> <h4 class="modal-title">Registration</h4>
> </div>
> <div class="modal-body">
> <p>Please Register Yourself Here</p>
> <form role="form" action="registration_page" method="get">
> <div class="form-group">
> <input type="text" class="form-control" name="nam" placeholder="Your Name Please" style="width:265px;" required/>
> </div>
> <div class="form-group">
> <input type="email" class="form-control" name="r_email" placeholder="Your Email Please" style="width:265px;"
> required/>
> </div>
> <div class="form-group">
> <input type="password" class="form-control" name="r_password" placeholder="Please enter a password"
> style="width:265px;" required/>
> </div>
> <div class="form-group">
> <input type="text" class="form-control" name="city" placeholder="Please enter your city" style="width:265px;" required/>
> </div>
> <div class="form-group">
> <input type="submit" class="btn btn-info" value="Register">
> </div>
> </form>
> </div>
> <div class="modal-footer">
> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
> </div>
> </div>
> </div>
> </div> </div>
Solution 2:[2]
The published trigger is used in both cases here (independently of the tag), because your workflow will start for published OR tags (with the informed pattern) events.
To perform an operation only for a specific tag, you would have to extract the tag version from the $GITHUB_REF (env-var), for example using a step as below with an output in a first job:
- name: Get the version
id: get_tag_version
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}
And then use an if condition on 2 others jobs to check if the tag version contains prod- or dev- (needing the first job) to perform the operation you want for each scenario.
Here is an complete example of what could be used:
name: Example
on:
release:
types: [published]
jobs:
job1:
runs-on: ubuntu-latest
outputs:
tag_version: ${{ steps.get_tag_version.outputs.version }}
steps:
- name: Get the version
id: get_tag_version
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}
job2: # will be executed on for dev- tag
runs-on: ubuntu-latest
needs: [job1]
if: contains( needs.job1.outputs.tag_version , 'dev-')
steps:
[...]
job3: # will be executed on for prod- tag
runs-on: ubuntu-latest
needs: [job1]
if: contains( needs.job1.outputs.tag_version , 'prod-')
steps:
[...]
I coded a workflow to test the implementation above and it worked as expected creating a prod-2 release tag:
EDIT: Note that you could also use a startWith instead of a contains function for the if expression.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nimantha |
| Solution 2 |

