I am trying to learn laravel 5, so I strated by creating some simple forms. My form contains (id, title,..) and radio button
<label for="importance">Importance</label>
<input type="radio" name="Importance"
<?php if (isset($importance) && $importance=="tres_important") echo "checked";?>
value="tres_important">très important
<input type="radio" name="importance"
<?php if (isset($importance) && $importance=="important") echo "checked";?>
value="important">important
Now, I need to know what I should add to my migration file, to make it work "create_projets_table"
public function up()
{
Schema::create('projets', function (Blueprint $table) {
$table->increments('id',true);
$table->string('title');
$table->date('dateDebut');
$table->timestamps();
});
}
Thank you in advance
UPDATES :
Based on the comments bellow, I made some changes, but still not working, it seems like something went wrong with "submit.blade.php"
submit.blade.php :
<div class="form-group">
<label class="radio-inline">
<input type="radio" id="tres_important" name="importance" value="tres_important">Très important</label>
<label class="radio-inline">
<input type="radio" id="important" name="importance" value="important">Important</label>
</div>
and this is my migration "create_projets_table.php" :
public function up()
{
Schema::create('projets', function (Blueprint $table) {
$table->increments('id',true);
$table->string('title');
$table->date('dateDebut');
$table->date('dateFin');
$table->float('cout');
$table->integer('importance');
$table->timestamps();
});
}
This route.php :
Route::post('/submit', function(Request $request) {
$validator = Validator::make($request->all(), [
'title' => 'required|max:255',
'annee_realisation' => 'required|max:255',
'cout' => 'required|max:255',
'importance' => 'required',
]);
if ($validator->fails()) {
return back()
->withInput()
->withErrors($validator);
}
$projet = new \App\Projet;
$projet->title = $request->title;
$projet->annee_realisation = $request->annee_realisation;
$projet->cout = $request->cout;
$projet->importance = $request->importance;
$projet->save();
return redirect('/');
});
And this my controller "Project_Controller" :
class Project_Controller extends Controller
{
//
$this->validate(request(), [
'importance' => 'required'
]);
}
I got the following error :
Undefined variable : importance
echo Form::radio('name', 'value', true);in laravel's blade template$table->boolean('important').$table->integer('importance')and use maybe a zero to indicate "important" and one to indicate "more important" and so on