I'm trying to add a new match into the database but if I purposely don't enter anything into the form, no errors are displayed. I have based this on my registration form which works perfectly. If I correctly fill out the form all data goes into the database correctly.
MatchController.php
public function postCreate()
{
$validator = Validator::make(Input::all(), Match::$rules);
if ($validator->passes())
{
$datetime = Input::get('year')."-".Input::get('month')."-".Input::get('day')." ".Input::get('time').":00";
$match = new Match;
$match->type = Input::get('match_type');
$match->associate = Input::get('associate');
$match->date = $datetime;
$match->location = Input::get('location');
$match->save();
$matchp1 = new Matchplayer;
$matchp1->user_id = Input::get('id');
$matchp1->match_id = $match->id;
$matchp1->team = 1;
$matchp1->save();
$matchp2 = new Matchplayer;
$matchp2->user_id = Input::get('opponent');
$matchp2->match_id = $match->id;
$matchp2->team = 2;
$matchp2->save();
return Redirect::to('members/matches/create')->with('message', 'Match created!');
}else{
return Redirect::to('members/matches/create')->withErrors($validator)->withInput();
}
}
Match Model (Match.php)
class Match extends Eloquent{
protected $table = 'matches';
public static $rules = array(
'match_type'=>'required',
'associate'=>'alpha|min:2'
'location'=>'required|alpha|min:2',
'team_mate2'=>'required_if:match_type,doubles',
'opponent2'=>'required_with:team_mate2'
);
}
Match Creation View (matchCreate.php)
<div class="row clearfix">
<!-- Error Message Box -->
#if(Session::has('message'))
<div class="col-md-8 col-md-offset-2">
<div class="alert alert-info">{{ Session::get('message') }}</div>
</div>
#endif
<div class="col-md-9">
<!-- Top Menu BEGIN -->
<ul class="nav nav-pills nav-justified">
<li>{{ HTML::link('members/logout', 'Profiles') }}</li>
<li>{{ HTML::link('members/logout', 'Leagues') }}</li>
<li class="active">{{ HTML::link('members/logout', 'Add Match') }}</li>
<li>{{ HTML::link('members/logout', 'Results & Fixtures') }}</li>
<li>{{ HTML::link('members/logout', 'Matchboard') }}</li>
</ul>
<!-- Top Menu END -->
<div class="page-header">
<h3>Create a Match</h3>
</div>
<div class="col-sm-6">
{{ Form::open(array('url'=>'members/matches/create', 'action' => 'post', 'class'=>'form-horizontal')) }}
{{ form::hidden('id', Auth::user()->id) }}
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Match Type</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('match_type', '<span class="help-block">:message</span>') }}
{{ Form::select('match_type', array('singles' => 'Singles', 'doubles' => 'Doubles'), 'singles', array('id' => 'match_type', 'class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-5 control-label col-sm-pad">League Associate</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('associate', '<span class="help-block">:message</span>') }}
{{ Form::text('associate', Input::old('associate'), array('class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Team Mate #1<br><small></small></label>
<div class="col-sm-7 col-sm-pad">
<p class="form-control-static">{{ Auth::user()->first_name." ".Auth::user()->last_name }}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Opponent #1</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('opponent', '<span class="help-block">:message</span>') }}
{{ Form::select('opponent', $users, 'key', array('class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Team Mate #2<br><small>(Doubles Only)</small></label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('team_mate2', '<span class="help-block">:message</span>') }}
{{ Form::select('team_mate2', $users, 'key', array('class' => 'form-control input')); }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Opponent #2<br><small>(Doubles Only)</small></label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('opponent2', '<span class="help-block">:message</span>') }}
{{ Form::select('opponent2', $users, 'key', array('class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Date</label>
{{ $errors->first('day', '<span class="help-block">:message</span>') }}
<div class="col-lg-2 col-sm-pad">
{{ Form::selectRange('day', 1, 31, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
<div class="col-lg-2 col-sm-pad">
{{ Form::selectRange('month', 1, 12, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
<div class="col-lg-3 col-sm-pad">
{{ Form::selectRange('year', 2014, 2015, 'a', array('class' => 'form-control input-sm input dob-form-control')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Time</label>
<div class="col-lg-3 col-sm-pad">
{{ $errors->first('time', '<span class="help-block">:message</span>') }}
{{ Form::select('time', $times, 'key', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Location</label>
<div class="col-sm-7 col-sm-pad">
{{ Form::text('location', Input::old('location'), array('class' => 'form-control input')) }}
</div>
</div>
{{ Form::submit('Create', array('class'=>'btn btn-success btn-block')) }}
{{ Form::token() . Form::close() }}
</div>
<div class="col-sm-6">
</div>
</div>
#include('includes.sidemenu')
</div>
routes.php
Route::post('members/matches/create', 'MatchController#postCreate');
You're creating your Validator object incorrectly. The make() method has four parameters:
/**
* Create a new Validator instance.
*
* #param array $data
* #param array $rules
* #param array $messages
* #return \Illuminate\Validation\Validator
*/
public function make(array $data, array $rules, array $messages = array(), array $customAttributes = array()) { ... }
You're passing each of your validation rules as a separate array, rather than together as one array. Subsequently, you aren't passing any of your input data, either, so it has no actual data to validate against.
Related
I have a User Entity and I collect all the data in a form called Register. But once after registering, I want to edit some of the fields of a user by a form. But some fields are avoided being updated (email) and Password field is optional. I tried rendering the same register form but $form->handleRequest($request) throws an error saying:
Expected argument of type "string", "NULL" given at property path
"password".
I want to know if there is a way to do this?
I tried $form->submit($request->request->get($form->getName()),false);
instead of $form->handleRequest($request); but it didn't work.
// This is my controller.
/**
* #Route("/update/{id}", name="update")
* #param $id
* #param Request $request
* #param UserPasswordEncoderInterface $passwordEncoder
* #param UserRepository $userRepository
* #return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function updateUser($id,Request $request, UserPasswordEncoderInterface $passwordEncoder, UserRepository $userRepository){
$user = $userRepository->find($id);
$form = $this->createFormBuilder($user)
->add('email',EmailType::class,[
'label'=>'Email',
'required' => false,
'attr'=>['placeholder'=>"Email"]
])
->add('password',RepeatedType::class,[
'type' => PasswordType::class,
'invalid_message' => 'The password fields must match.',
'required' => false,
'options' => ['attr' => ['class' => 'password-field']],
'first_options' => ['label' => 'Password','attr'=>['placeholder'=>"Password"]],
'second_options' => ['label' => 'Confirm Password','attr'=>['placeholder'=>"Confirm Password"]],
])
->add('firstName',TextType::class,['label'=>'First Name', 'attr'=>['placeholder'=>"First Name"]])
->add('lastName',TextType::class,['label'=>'Last Name','attr'=>['placeholder'=>"Last Name"]])
->add('address',TextareaType::class,['required' => false,'label'=>'Address','attr'=>['placeholder'=>"Address"]])
->add('idNumber',TextType::class,['label'=>'NIC Number','attr'=>['placeholder'=>"NIC Number"]])
->add('phoneNumber',TelType::class,['label'=>'Phone Number','attr'=>['placeholder'=>"Phone Number"]])
->add('image',FileType::class,['label'=>'Photo','required'=>false,'attr'=>['hidden'=>"hidden", 'accept'=>"image/jpeg, image/png"]])
->add('save',SubmitType::class,[
'label'=>'Register',
'attr' => [
'class'=>"btn btn-outline-success float-right"
]
])
->getForm();
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
if($user->getPassword() !=""){
$user->setPassword($passwordEncoder->encodePassword($user,$user->getPassword()));
}
$em = $this->getDoctrine()->getManager();
$em->flush();
return $this->redirectToRoute('home');
}
return $this->render('register/update.html.twig', [
'form'=>$form->createView(),
]);
}
// And this is my TWIG file.
{% extends 'base.html.twig' %}
{% block title %}Edit Info{% endblock %}
{% block refHome %}{{ path('main') }}{% endblock %}
{% block body %}
<div class="container" style=" margin-left: auto;margin-right: auto;margin-top: 1cm;" >
<div class="row">
{# <div class="col-lg-2"></div>#}
<div class="col-lg-10">
<div class="card" style="width: 50rem;text-align: center;">
<div class="card-body">
<h3 class="card-title float-left">Edit Info</h3>
<div style="margin-top: 2cm;">
<p class="card-text">
<form name="register" id="register_form" method="post" enctype="multipart/form-data">
<div id="register">
<div class="container">
<div class="row">
<div class="col-sm-5">
{{ form_errors(form.firstName) }}
{{ form_widget(form.firstName) }}
</div>
<div class="col-sm-2"></div>
<div class="col-sm-5">
{{ form_errors(form.lastName) }}
{{ form_widget(form.lastName) }}
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="row">
<div class="col-sm-6">
{{ form_errors(form.email) }}
{{ form_widget(form.email) }}
</div>
<div class="col-sm-1"></div>
<div class="col-sm-5">
{{ form_errors(form.idNumber) }}
<input type="text" id="register_idNumber" placeholder="NIC Number" onkeypress="isInputNumber(event)" pattern="^[0-9]{9}[a-zA-Z]$" value="{{ form.idNumber.vars.value }}" name="register[idNumber]" required="required" class="form-control" " /> <div class="input-group-append">
</div>
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="row">
<div class="col-sm-5">
<div style="margin-top: 0.5cm;"></div>
{{ form_errors(form.phoneNumber) }}
<input type="tel" id="register_phoneNumber" value="{{ form.phoneNumber.vars.value }}" name="register[phoneNumber]" onkeypress="isPhone(event)" required="required" placeholder="Phone Number" class="form-control" pattern="^[0-9]{10}$" />
</div>
<div class="col-sm-2"></div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="row" >
<div class="col-sm-7">
{{ form_errors(form.address) }}
{{ form_widget(form.address) }}
</div>
<div class="col-sm-1" hidden="hidden">
{{ form_widget(form.image) }}
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="form-group row">
<div class="col-sm-7">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="defaultUnchecked" style="float: left">
<label class="custom-control-label" for="defaultUnchecked">Change Password</label>
</div>
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div id="register_password" >
<div class="form-group row">
{% for passwordField in form.password %}
<div class="col-sm-5">
{{ form_errors(passwordField) }}
{{ form_widget(passwordField) }}
</div>
<div class="col-sm-2"></div>
{% endfor %}
</div>
<div style="margin-top: 0.5cm;"></div>
</div>
</div>
{{ form_widget(form.save,{'label':"Update"}) }}
{{ form_widget(form._token) }}
{{ form_errors(form) }}
</form>
</p>
</div>
</div>
</div>
</div>
<div class="col-lg-1"></div>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script>
const checkBoxPwd = document.getElementById('defaultUnchecked');
const pwdDiv = document.getElementById('register_password');
pwdDiv.style.visibility = "hidden";
checkBoxPwd.addEventListener("change",function () {
if (checkBoxPwd.checked == true){
pwdDiv.style.visibility = "visible";
}else{
pwdDiv.style.visibility = "hidden";
}
});
</script>
<script>
function isInputNumber(eve) {
var ch = String.fromCharCode(eve.which);
if (document.getElementById('register_idNumber').value.length < 9){
if (!(/[0-9]/.test(ch))){
eve.preventDefault();
}
}else {
if (!(/[a-zA-Z]/.test(ch))){
eve.preventDefault();
}
}
if (document.getElementById('register_idNumber').value.length > 9){
eve.preventDefault();
}
}
function isPhone(eve) {
var ch = String.fromCharCode(eve.which);
if (!(/[0-9]/.test(ch))){
eve.preventDefault();
}
if (document.getElementById('register_phoneNumber').value.length > 9){
eve.preventDefault();
}
}
</script>
{% endblock %}
I had developed a system that use maddhatter/laravel-fullcalendar.It works and i had no problem to display the calendar with the events.However, there is the problem that the calendar show all events include from different users.Can someone help me to solve this?
Controller
//show the events in the calendar
$events = Schedule::get();
$events->user()->id;
$event_list = [];
foreach ($events as $key => $event) {
$event_list[] = Calendar::event(
$event->event_name,
false,
new \DateTime($event->start_date),
new \DateTime($event->end_date),
null,
// Add color and link on event
[
'color' => '#05B06C',
//'url' => 'http://full-calendar.io',
]);
}
//Display Fullcalendar
$calendar_details = Calendar::addEvents($event_list)
->setOptions([ //set fullcalendar options
'firstDay'=> 1,
'editable'=> true,
'navLinks'=> true,
'selectable' => true,
'durationeditable' => true,
]);
return view('front.teacher.schedule.index', compact('calendar_details','events') );
}
Model
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Schedule extends Model
{
protected $fillable=[
'event_name','start_date','end_date'
];
}
View
{!! Form::open(array('route' =>'schedule:addEvents','method'=>'POST','files'=>'true'))!!}
<div class ="row">
<div class="col-xs-12 col-sm-12 col-md-12">
#if(Session::has('success'))
<div class="alert alert-success">{{Session::get('success')}}</div>
#elseif (Session::has('warning'))
<div class="alert alert-danger">{{Session::get('warning')}}</div>
#endif
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
{!! Form::label('event_name','Name:') !!}
<div class="">
{!! Form::text('event_name',null,['class'=>'form-control'])!!}
{!! $errors->first('event_name','<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-sm-3">
<div class="form-group">
{!! Form::label('start_date','Start Date:')!!}
<div class="">
{!! Form::input('datetime-local','start_date',\Carbon\Carbon::now(),['class' => 'form-control']) !!}
{!! $errors->first('start_date', '<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
{!!Form::label('end_date','End Date:')!!}
<div class="">
{!! Form::input('datetime-local','end_date',null, ['class' => 'form-control']) !!}
{!! $errors->first('end_date', '<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-1 col-sm-1 cold-md-1 text-center"> <br/>
{!! Form::submit('Add Event',['class'=>'btn btn-primary']) !!}
</div>
</div>
{!!Form::close() !!}
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">My Event Details</div>
<div class="panel-body">
{!! $calendar_details->calendar() !!}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar_details->script() !!}
Schedule Table
Table
I'm trying to update the fields in the database, but I couldn't
here is my routes :
Route::get('orders', [
'uses' => 'OrderController#postOrder',
'as' => 'order.show'
]);
here the controller:
public function postOrder()
{
$this->orderForm->validate(Input::all());
$order = $this->orders->getNew([
'link' => Input::post('link'),
'size' => Input::post('size'),
'color' => Input::post('color')
]);
$this->orders->save($order);
return Redirect::back()->withMessage('Order has been updated');
}
here is the blade:
{{ Form::open() }}
<div class="box-body">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
{{ Form::label('title', 'Product:') }}
{{ Form::text('title', $order->title, ['class' => 'form-control', ]) }}
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
{{ Form::label('link', 'Link:') }}
{{ Form::text('link', $order->link, ['class' => 'form-control']) }}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
{{ Form::label('size', 'Size:') }}
{{ Form::text('size', $order->size, ['class' => 'form-control']) }}
</div>
</div>
<div class="col-lg-6">
</div>
</div>
<div class="box-footer">
{{ Form::submit('Save', ['class' => 'btn btn-primary']) }}
</div>
{{ Form::close() }}
so each time I try to update the order I got error "MethodNotAllowedHttpException ", I tried a lot of methods but I'm lost. I'm still beginner in php and this problem drive me crazy, so I'll be glad if you can help guys.
thanks
*** I've updated the code
So you're posting to the route, /orders. Therefor you need a HTTP POST request. You're now assigning a GET request to the /orders route.
You need to change your code to:
Route::post('orders', [
'uses' => 'OrderController#postOrder',
'as' => 'order.show'
]);
Also you need to add a CSRF Token, this can be done through adding {!! csrf_field() !!} in your blade (inside your Form open and close).
{{ Form::open() }}
{!! csrf_field() !!}
<div class="box-body">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
{{ Form::label('title', 'Product:') }}
{{ Form::text('title', $order->title, ['class' => 'form-control', ]) }}
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
{{ Form::label('link', 'Link:') }}
{{ Form::text('link', $order->link, ['class' => 'form-control']) }}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
{{ Form::label('size', 'Size:') }}
{{ Form::text('size', $order->size, ['class' => 'form-control']) }}
</div>
</div>
<div class="col-lg-6">
</div>
</div>
<div class="box-footer">
{{ Form::submit('Save', ['class' => 'btn btn-primary']) }}
</div>
{{ Form::close() }}
Hope this works!
You must specify the method in the Form::open method.
{{ Form::open(array('method' => 'post')) }}
Just added this in the repository:
public function updateOrder($id, array $data)
{
$orders = $this->getById($id);
if (!empty($data['title'])) {
$orders->title = $data['title'];
}
if (!empty($data['link'])) {
$orders->link = $data['link'];
}
(AND SO ON)
$orders->save();
and in the controller:
public function postOrder($id)
{
$this->orders->updateOrder($id, Input::all());
return Redirect::back()->withMessage('Updated');
}
and that's it
I am using symfony2. Actually i have created form using form type. but when i render the form, following error occurred
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Symfony\Component\Form\FormRenderer::searchAndRenderBlock() must be an instance of Symfony\Component\Form\FormView
Here is my code
Controller
$profile = new profile();
$myForm = $this->createForm(new ProfileFormType(), $profile);
return $this->render('ProfileBundle:Profle:profile.html.twig', array(
'form' => $myForm,
'vendor' => $vendor,
'productId' => $productId
));
profile.twig.html
<form action="{{ path('profile_new') }}" method="POST" {{ form_enctype(form) }} id="frmProfile">
<div class="box-body col-sm-6">
<div class="form-group">
<label class="control-label">First Name: </label>
{{ form_widget(form.firstName, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
<div class="serverError">{{ form_errors(form.firstName) }}</div>
</div>
</div>
<div class="box-body col-sm-6">
<div class="form-group">
<label class="control-label">Last Name: </label>
{{ form_widget(form.lastName, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
<div class="serverError">{{ form_errors(form.lastName) }}</div>
</div>
</div>
<div class="box-body col-sm-6">
<div class="form-group">
<label class="control-label">User Name: </label>
{{ form_widget(form.username, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
<div class="serverError">{{ form_errors(form.username) }}</div>
</div>
</div>
</form>
What am i doing wrong?
Replace 'form' => $myForm with 'form' => $myForm->createView(). Function createView() will create view of form object.
return $this->render('ProfileBundle:Profle:profile.html.twig', array(
'form' => $myForm->createView(), // << Add "->createView()"
'vendor' => $vendor,
'productId' => $productId
));
My required_if validation does not work. No error is output when "doubles" is selected but "team_mate2 and opponent2" are not selected. I need the form to require a second team mate and opponent when doubles is selected as the match type.
Match.php (Model)
<?php
class Match extends Eloquent{
protected $table = 'matches';
public static $rules = array(
'match_type'=>'required',
'associate'=>'alpha|min:2',
'location'=>'required|alpha|min:2',
'opponent'=>'numeric',
'team_mate2'=>'required_if:match_type,doubles',
'opponent2'=>'required_with:team_mate2'
);
public static $messages = array(
'opponent.numeric'=>'You must select a player.'
);
}
MatchController.php
public function postCreate()
{
$validator = Validator::make(Input::all(), Match::$rules, Match::$messages);
if ($validator->passes())
{
$datetime = Input::get('year')."-".Input::get('month')."-".Input::get('day')." ".Input::get('time').":00";
$match = new Match;
$match->type = Input::get('match_type');
$match->associate = Input::get('associate');
$match->date = $datetime;
$match->location = Input::get('location');
$match->save();
$matchp1 = new Matchplayer;
$matchp1->user_id = Input::get('id');
$matchp1->match_id = $match->id;
$matchp1->team = 1;
$matchp1->save();
$matchp2 = new Matchplayer;
$matchp2->user_id = Input::get('opponent');
$matchp2->match_id = $match->id;
$matchp2->team = 2;
$matchp2->save();
return Redirect::to('members/matches/create')->with('message', 'Match created!');
}else{
return Redirect::to('members/matches/create')->withErrors($validator)->withInput();
}
}
Match Create View
{{ Form::open(array('url'=>'members/matches/create', 'action' => 'post', 'class'=>'form-horizontal')) }}
{{ form::hidden('id', Auth::user()->id) }}
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Match Type</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('match_type', '<span class="help-block">:message</span>') }}
{{ Form::select('match_type', array('singles' => 'Singles', 'doubles' => 'Doubles'), 'singles', array('id' => 'match_type', 'class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-5 control-label col-sm-pad">League Associate</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('associate', '<span class="help-block">:message</span>') }}
{{ Form::text('associate', Input::old('associate'), array('class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Team Mate #1<br><small></small></label>
<div class="col-sm-7 col-sm-pad">
<p class="form-control-static">{{ Auth::user()->first_name." ".Auth::user()->last_name }}</p>
</div>
</div>
<div class="form-group{{ $errors->first('opponent', ' has-error') }}">
<label class="col-sm-5 control-label col-sm-pad">Opponent #1</label>
<div class="col-sm-7 col-sm-pad">
{{ Form::select('opponent', $users, 'key', array('class' => 'form-control input')) }}
{{ $errors->first('opponent', '<span class="help-block">:message</span>') }}
</div>
</div>
<div class="form-group{{ $errors->first('team_mate2', ' has-error') }}">
<label class="col-sm-5 control-label col-sm-pad">Team Mate #2<br><small>(Doubles Only)</small></label>
<div class="col-sm-7 col-sm-pad">
{{ Form::select('team_mate2', $users, 'key', array('class' => 'form-control input')); }}
{{ $errors->first('team_mate2', '<span class="help-block">:message</span>') }}
</div>
</div>
<div class="form-group{{ $errors->first('opponent2', ' has-error') }}">
<label class="col-sm-5 control-label col-sm-pad">Opponent #2<br><small>(Doubles Only)</small></label>
<div class="col-sm-7 col-sm-pad">
{{ Form::select('opponent2', $users, 'key', array('class' => 'form-control input')) }}
{{ $errors->first('opponent2', '<span class="help-block">:message</span>') }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Date</label>
{{ $errors->first('day', '<span class="help-block">:message</span>') }}
<div class="col-lg-2 col-sm-pad">
{{ Form::selectRange('day', 1, 31, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
<div class="col-lg-2 col-sm-pad">
{{ Form::selectRange('month', 1, 12, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
<div class="col-lg-3 col-sm-pad">
{{ Form::selectRange('year', 2014, 2015, 'a', array('class' => 'form-control input-sm input dob-form-control')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Time</label>
<div class="col-lg-3 col-sm-pad">
{{ Form::select('time', $times, 'key', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
</div>
<div class="form-group{{ $errors->first('location', ' has-error') }}">
<label class="col-sm-5 control-label col-sm-pad">Location</label>
<div class="col-sm-7 col-sm-pad">
{{ Form::text('location', Input::old('location'), array('class' => 'form-control input')) }}
{{ $errors->first('location', '<span class="help-block has-error">:message</span>') }}
</div>
</div>
{{ Form::submit('Create', array('class'=>'btn btn-success btn-block')) }}
{{ Form::token() . Form::close() }}
When I don't use a model like so:
$validator = Validator::make(
array('match_type' => Input::get('match_type')),
array('opponent' => 'required_if:match_type,doubles')
);
This seems to work. I still am unsure on why my method does not work, does the match_type value not pass over to required_if when in a Model?