Hi guys able to simple validate the login details and signup details but unable to insert and fetch database of phpmyadmin using laravel 4.2. Can you help with this?
Following is my code for models
class Website extends Eloquent implements UserInterface, RemindableInterface
{
use UserTrait,RemindableTrait;
protected $table = 'websites';
protected $hidden = array('password', 'remember_token');
protected $protected = array();
protected $fillable = array('name',email','username','password','confirm_password','phone');
}
here is code for view file
here is view file
signup.blade.php
{{ Form::open(array('url' => 'register')) }}
@if($errors->has('name'))
{{ $errors->first('name') }}
@endif
{{ Form::label('name', 'Name:') }}
{{ Form::text('name') }}
@if($errors->has('username'))
{{ $errors->first('username') }}
@endif
{{ Form::label('username', 'Username:') }}
{{ Form::text('username') }}
@if($errors->has('password'))
{{ $errors->first('password') }}
@endif
{{ Form::label('password', 'Password:') }}
{{ Form::password('password') }}
@if($errors->has('password'))
{{ $errors->first('confirm_password') }}
@endif
{{ Form::label('password', 'Confirm Password:') }}
{{ Form::password('confirm_password') }}
@if($errors->has('email'))
{{ $errors->first('email') }}
@endif
{{ Form::label('email', 'Email:') }}
{{ Form::text('email') }}
@if($errors->has('phone'))
{{ $errors->first('phone') }}
@endif
{{ Form::label('phone', 'Phone:') }}
{{ Form::text('phone') }}
</div>
{{ Form::submit('Create', array('class' => 'btn btn-success')) }}
{{ Form::close() }}
here is login.blade.php
{{ Form::open(array('url' => 'login')) }}
<table>
<tr>
<td width="150px" class="table-responsive">
{{ Form::label('username', 'Username:') }}
{{ Form::text('username') }}
@if($errors->has('username'))
<label> {{ $errors->first('username') }} </label>
@endif
</td>
</tr>
<tr>
<td width="150px">
{{ Form::label('password', 'Password:') }}
{{ Form::text('password') }}
@if($errors->has('password'))
<label> {{ $errors->first('password') }} </label>
@endif
</td>
</tr>
<tr>
<td width="150px">
<div class="field">
<input type="checkbox" name="remember" id="remember">
<label for="remember">
Remember me
</td>
</tr>
</div>
<tr>
<td>
{{ Form::submit('Login', array('class' => 'btn btn-primary')) }}
</td>
</tr>
</table>
@if( $errors->count() > 0 )
<p>The following errors have occurred:</p>
<ul id="form-errors">
{{ $errors->first('username', '<li>:message</li>') }}
{{ $errors->first('password', '<li>:message</li>') }}
{{ $errors->first('password_confirmation', '<li>:message</li>') }}
</ul>
@endif{{ Form::close() }}
here is my code for controller for function
WebsiteController.php
<?php
class WebsiteController extends BaseController {
public function index()
{
return View::make('websites.index',compact('websites'));
}
public function login()
{
return View::make('websites.login');
}
public function signup()
{
return View::make('websites.signup');
}
public function show()
{
$input=Input::all();
$messages = array('username.required' => 'Please enter your username','password.required' => 'You have to set a password');
$rules = array( 'username' => 'required|alpha-num','password' => 'required');
$validator = Validator::make($input,$rules,$messages);
if ($validator->fails()) {
print_r($input);
echo 1;
return Redirect::to('login')->withErrors($validator);
}
else
{
return Redirect::to('websites')
->with('message', 'Your account has been created, please login'); print_r($input);
}
}
public function store()
{
$input=Input::all();
$messages = array(
'name.required' => 'Please enter your name',
'email.required' => 'your email address required',
'username.required' => 'Please enter your username',
'password.required' => 'You have to set a password',
'confirm_password.required' => 'Write again your password',
'confirm_password.matchpass' => 'The two passwords does not match');
$rules = array(
'name'=>'required|alpha',
'username' => 'required|alpha-num',
'password' => 'required',
'confirm_password'=>'required',
'email' => 'required|email',
'phone'=>'required|numeric'
);
$validator = Validator::make($input,$rules,$messages);
if ($validator->fails()) {
print_r($input);
echo 1;
return Redirect::to('register')->withErrors($validator)->withInput();
}
else
{
$user = new Website();
$user->username =$input['username'];
$user->email = $input['email'];
$user->password = $input['password'];
$user->name = $input['name'];
$user->phone =$input['phone'];
return Response::json(array('success' => true), 200);
return Redirect::to('login')
->with('global', 'Your account has been created! We have sent an email to activate your account');
// }
}
}
}
?>