Monday 18 July 2016

Laravel Form

1. composer  require illuminate/html
     ref : https://github.com/illuminate/html

     Steps : ->Go to Config/app.php
             ->Add HTML service provider in service provider list
                 Illuminate/Html/HtmlServiceProvider
             -> Add Html Facade in alias section 
                  'Html' => 'Illuminate/Html/Facades/HtmlFacad'
                  'Form' => 'Illuminate/Html/Facades/FormFacad'


Form Design :

{!! Form::open() !!}

    <div class="form-group">
      {!!  Form::label('name', 'Name')  !!}
     {!!  Form::text('name', null,['class' => 'form-control'])  !!}
   </div>


    <div class="form-group">
      {!!  Form::label('body', 'Body')  !!}
     {!!  Form::textarea('body' , null,['class' => 'form-contro'l])  !!}
   </div>



    <div class="form-group">
      {!!  Form::label('published_at', 'Published On')  !!}
     {!!  Form::input('date','published_at' , null,['class' => 'form-contro'l])  !!}
     
                                          OR
{!!  Form::input('date','published_at' , Carbon\Carbon::now()->format('Y-m-d'),['class' => 'form-contro'l])  !!}
                                            OR


{!!  Form::input('date','published_at' , date('Y-m-d'),['class' => 'form-contro'l])  !!}
   
</div>



    <div class="form-group">
     {!!  Form::submit('Add') , null,['class' => ' btn btn-primary form-control']) !!}   </div>

{!!Form::close() !!}




In Model  : for full date with time
public function setPublishedAtAttribute($date){
   // this give current time
   $this->attributes['published_at'] =  Carbon::createFormFormat('Y-m-d',$date);

                                    OR
  // This gives 00 hr,min,sec
$this->attributes['published_at'] =  Carbon::parse ($date);
}



                 

No comments:

Post a Comment