samedi 27 août 2016

summernote (data not saving in DB) (laravel 5.2)

I am using laravel 5.2 and integrating summernote js in the site.

I want that when user fills the form and click on save ,all the data get stored in Database.

It worked for a single field but not for two or more.

my view:

    <form action="" id="acc" class="ac" method="post">
  <div class="col-lg-3"><label>Estado</label>

  @foreach($accounts as $account)
  @if($user== $account->user)
  {!! $account->estado !!}
  <textarea  style="display:none;" name="textfield4" id="textfield4"></textarea></div>

  <div class="col-lg-2 es" id="estado"></div>


 <a span class="fa fa-heartbeat"  id="sex" aria-hidden="true">
    </span></a>
</div>
  <div class="col-lg-4"></div>
</div>
<div class="row">
  <section class="col-lg-3"><div><br><label for="textfield5">I'm Good At:</label>


   <p>{!! $account->goodat !!}</p>


   <textarea  style="display:none;" name="textfield5" id="textfield5"></textarea></div>
  <div class="col-lg-2 es" id="goodat"></div>
   @endif
  @endforeach

my JS in view:

 <script>

var edit = function() {
  $('#estado').summernote({focus: true});
   $('#goodat').summernote({focus: true});
};

var save = function() {
  var makrup = $('#estado').summernote('code');
  $('#estado').summernote('destroy');

  var makrup = $('#goodat').summernote('code');
  $('#goodat').summernote('destroy');
};

$(".acc").submit(function(e) {
     var self = this;
     e.preventDefault();


    //$('#estado').summernote('destroy');
     var estado = $('#estado').summernote('code');
     $("#textfield4").html(estado); //populate text area



      var goodat = $('#goodat').summernote('code');
     $("#textfield5").html(goodat); //populate text area
     self.submit();
     return false; 


});



</script>

my controller:

 se App\Account;

use Illuminate\Support\Facades\Auth;


class AccountController extends Controller
{

 public function account(Request $request)
    {

        $account = new Account();
        $account->estado = $request->input('textfield4');
        $account->goodat = $request->input('textfield5');
        $request->user()->accounts()->save($account);


        return redirect()->route('myplace',['username'=>Auth::user()->username]);
    }



}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire