php - create a form and given with Laravel sauvgarde of 5 -
i beginner , using laravel 5, have same problem recovring data , saving them. think thing missing . source code:
this blade page: .blade.php
<form class="form-horizontal" role="form" method="post" action="{{ url('ajoutannonce') }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <div class="form-group"> <label class="col-md-4 control-label">name of building</label> <div class="col-md-6"> <input type="text" class="form-control" name="nom" value="{{ old('nom') }}"> </div> </div> <input type="hidden" class="form-control" name="emplacement" id="test2" value="{{ '$mylatlng' }}"> <div class="form-group"> <div class="form-group"> <label class="col-md-4 control-label">description</label> <div class="col-md-6"> <textarea class="form-control" rows="3" name="description" value="{{ old('description') }}"> </textarea> </div> </div>
this controlleur:
<?php namespace app\http\controllers; use auth; use app\immobilier; use app\http\controllers\controller; use validator; class annoncecontroller extends controller { public $restful = true; public function get_index() { return view('ajoutannonce'); } protected function validator(array $data){ return validator::make($data, [ 'nom' => 'required|max:255', 'description' => 'required | max:600' , ]); } protected function create(array $data) { return immobilier::create([ 'nom' => $data['nom'], 'description' => $data['description'], 'id_promoteur' => auth::user()->id ]); } public function post_index() { return view('ajoutannonce'); } }
and request:
<?php namespace app\http\requests; use app\http\requests\request; class annoncerequest extends request { public function authorize() { return true; } public function rules() { return [ 'nom' => 'required', 'description'=> 'required|max;600' ]; } }
your rule should be:
public function rules() { return [ 'nom' => 'required', 'description' => 'required|max:600' //not max;600 ]; }
this making fail validation every time.
Comments
Post a Comment