Larvel - problem kod update-a u modal window

poruka: 1
|
čitano: 423
|
moderatori: Lazarus Long, XXX-Man, vincimus
1
+/- sve poruke
ravni prikaz
starije poruke gore
5 godina
neaktivan
offline
Larvel - problem kod update-a u modal window-u

Imam problem kod update-a u modal window-u (Bootstrap).

Pokazujem mi dobre podatke u update modal prozoru (osim select-a), ali mi kad kliknem gumb update/edit uvijek 'pregazi' istu osobu. 

Ne znam gdje sam pogriješila. Evo mog koda. 

 

DirectoriesController

 

publicfunctionedit($id)

   {

     $directories = Directory::find($id);

     return view('pages.admin.directory', compact('directories','id'));

   }

 

directory.blade.php

 

<tableclass="table table-hover">

<theadclass="text-center">

<tr>

<thscope="col">#</th>

<thscope="col">Ime</th>

<thscope="col">Prezime</th>

<thscope="col">Email</th>

<thscope="col">Telefon</th>

<thscope="col">Grad</th>

<thscope="col">Država</th>

<thscope="col">Spol</th>

<thscope="col">Status</th>

<thscope="col">Izmijeni</th>

<thscope="col">Izbriši</th>

</tr>

</thead>

<tbodyclass="text-center"> @foreach($directories as $key => $item)

<tr>

<tdscope="row">{{ $key+1 }}</td>

<tdhidden="hidden">{{ $item->id }}</td>

<td>{{ $item->name }}</td>

<td>{{ $item->surname }}</td>

<td>{{ $item->email }}</td>

<td>{{ $item->phone }}</td>

<td>{{ $item->town }}</td>

<td>{{ $item->country }}</td>

<td>{{ $item->gender }}</td>

<td>{{ $item->status }}</td>

<td><ahref="#editDirectory/{{ $item->id }}

"data-item-id="{{ $item->id }}

"data-item-name="{{ $item->name }}

"data-item-surname="{{ $item->surname }}

"data-item-email="{{ $item->email }}

"data-item-phone="{{ $item->phone }}

"data-item-town="{{ $item->town }}

"data-item-country="{{ $item->country }}

"data-item-gender="{{ $item->gender }}

"data-item-status="{{ $item->status }}

"data-target="#editDirectory"data-toggle="modal">

<buttontype="submit"><imgsrc="/storage/admin/edit.png"class="mx-auto d-block img-crud"/></button>

</a>

</td>

<td>

<ahref="#deleteDirectory/{{ $item->id }}"data-item-id="{{ $item->id }}"data-target="#deleteDirectory"data-toggle="modal"><buttontype="submit"><imgsrc="/storage/admin/delete.png"class="mx-auto d-block img-crud"/></button>

</a>

</td>

</tr> @endforeach

</tbody>

</table>

 

Form

 

<divclass="modal fade bd-example-modal-md"id="editDirectory"tabindex="-1"role="dialog"aria-labelledby="editDirectoryModalLabel"aria-hidden="true"data-backdrop="false">

<divclass="modal-dialog modal-md"role="document">

<divclass="modal-content">

<divclass="modal-header">

<h5class="modal-title"id="editDirectoryModalLabel">Ažuriranje novog korisnika</h5>

<buttontype="button"class="close"data-dismiss="modal"aria-label="Close">

<spanaria-hidden="true">&times;</span>

</button>

</div>

<divclass="modal-body">

{!! Form::open (['method' => 'POST', 'action' => ['DirectoriesController@update',$item->id]]) !!}

{!! csrf_field() !!}

@include('pages.admin.forms-admin.edit.edit-directory')

{!! Form::hidden('_method','PATCH')!!} {!! Form::close() !!}

</div>

</div>

</div>

</div>

 

<div class="form-group">

{{Form::label('name','Ime')}}

{{Form::text('name',$item->name, ['class' => 'form-control','placeholder' => 'Upišite ime'])}}

</div>

<div class="form-group">

{{Form::label('surname','Prezime')}}

{{Form::text('surname',$item->surname, ['class' => 'form-control','placeholder' => 'Upišite prezime'])}}

</div>

<div class="form-group">

{{Form::label('email','Email')}}

{{Form::email('email',$item->email, ['class' => 'form-control','placeholder' => 'ime@mail.com'])}}

</div>

<div class="form-group">

{{Form::label('phone','Telefon')}}

{{Form::number('phone',$item->phone, ['class' => 'form-control','placeholder' => '38591222333'])}}

</div>

<div class="form-group">

{{Form::label('town','Grad')}} {{Form::text('town',$item->town, ['class' => 'form-control','placeholder' => 'Upiši grad'])}}

</div>

<div class="form-group">

{{Form::label('country','Država')}}

{{Form::text('country',$item->country, ['class' => 'form-control','placeholder' => 'Upiši državu'])}}

</div>

<div class="form-group">

{{Form::label('gender','Spol')}}

{{Form::select('gender', $genders, $item->gender, ['class' => 'form-control'])}}

</div>

<div class="form-group">

{{Form::label('status','Status')}}

{{Form::select('status', $statuses, $item->status, ['class' => 'form-control'])}}

</div>

<div class="modal-footer">

<input type="submit" class="btn btn-primary" value="Ažuriraj"/>

{{--{{Form::submit('Ažuriraj',['class'=> 'btn btn-primary'])}}--}}

<button type="button" class="btn btn-secondary" data-dismiss="modal">Zatvoriti</button>

</div>

 

 

app.js

 

/** * First we will load all of this project's JavaScript dependencies which * includes Vue and other libraries. It is a great starting point when * building robust, powerful web applications using Vue and Laravel.*/

require('./bootstrap');

window.Vue = require('vue');

/** * Next, we will create a fresh Vue application instance and attach it to * the page. Then, you may begin adding components to this application * or customize the JavaScript scaffolding to fit your unique needs. */

Vue.component('example-component',

require('./components/ExampleComponent.vue'));

const app = new Vue({ el: '#app' });

 

$( document ).ready(function() {

//Calls the modal when button is clicked

$('#editDirectory').on('show.bs.modal', function(event) {

//console.log('Modal opened');

var button = $(event.relatedTarget)

var name = button.data('item-name')

var surname = button.data('item-surname')

var email = button.data('item-email')

var phone = button.data('item-phone')

var town = button.data('item-town')

var country = button.data('item-country')

var gender = button.data('item-gender')

var status = button.data('item-status')

 

// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).

// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.

var modal = $(this)

modal.find('input[id="name"]').val(name)

modal.find('input[id="surname"]').val(surname)

modal.find('email[id="email"]').val(email)

modal.find('phone[id="phone"]').val(phone)

modal.find('input[id="town"]').val(town)

modal.find('input[id="country"]').val(country)

modal.find('select[id="gender"]').val(gender)

modal.find('select[id="status"]').val(status)

});

});

 

Daje mi ovaj error:

Here is an error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '24' for key 'PRIMARY' (SQL: update directory set id = 24, name = Mike, updated_at = 2018-11-07 14:34:45 where id = 23)

 

Poruka je uređivana zadnji put sri 7.11.2018 16:53 (MalaBo).
 
0 0 hvala 0
1
Nova poruka
E-mail:
Lozinka:
 
vrh stranice