I'm trying to save some data to my model using a form and my controller.
The form looks like this:
<body>
<div class="container">
<h1>Assign days to event</h1>
<div class="form-group">
</div>
<div class="form-group">
</div>
</div>
</body>
My Create/Store functions in my Controller looks like this:
public function create()
{
$events = Event::pluck('id');
return View::make('days.create')
->with('events', $events);
}
public function store()
{
$rules = array(
'event_id' => 'required',
'day_number' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('days/create')
->withErrors($validator)
->withInput(Input::except('password'));
}
else {
$day = new day;
$day->event_id = Input::get('event_name');
$day->day_number = Input::get('day_number');
$day->save();
Session::flash('message', 'You have assigned this event a number of days');
return Redirect::to('days');
}
}
And my Model looks like this
class Day extends Model
{ protected $fillable = ['id','event_name','day_number'];
public function mods()
{
return $this->hasMany('App\Mod');
}
// Get the Event this day is attributed to
public function event()
{
return $this->belongsTo('App\Event');
}
}
The form will be created, however when I add values to the fields and hit 'Assign!' it will stay on the same page and will not indicate if it has done anything. Checking the table shows that it hasn't saved the data.
Am I missing something that causes the form to save the data via the controller, and if so what could it be?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire