Редактировать и обновить данные в LaravelPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Редактировать и обновить данные в Laravel

Сообщение Anonymous »

У меня возникают проблемы с редактированием данных в Ларавеле. Вот кнопка, чтобы показать Edit View: < /p>

{{ Form::open(array('route' => array('edit_spk', 'id'=> $spk_data->id), 'method' => 'GET', 'style' => 'display:inline')) }}

Edit

{{Form::close()}}
< /code>

Вот маршрут: < /p>

Route::get('spk/edit/{id}', array('as'=>'edit_spk','uses'=>'SpkController@edit'));
Route::put('spk/update/{id}', array('as'=>'update_spk','uses'=>'SpkController@update'));
< /code>

Вот контроллер: < /p>

public function edit($id){
$spk = Spk::find($id);
$spk->distribution_code=Input::get('distribution_code');
$spk->destination=Input::get('destination');
$spk->hlr=Input::get('hlr');
$spk->first_iccid=Input::get('first_iccid');
$spk->last_iccid=Input::get('last_iccid');
$spk->quantity=Input::get('quantity');
return View::make('modals.edit-spk', compact('spk'));
}

public function update($id) {
$rules = array(
'distribution_code' => 'required',
'destination' => 'required',
'hlr'=> 'required',
'first_iccid' => 'required',
'last_iccid' => 'required',
'quantity' => 'required'
);

$validator = Validator::make(Input::all(), $rules);

if ($validator->fails()) {
return Redirect::to('modals.edit-spk')->withErrors($validator);
} else {
// store
$update = Spk::find($id);
$update->distribution_code=Input::get('distribution_code');
$update->destination=Input::get('destination');
$update->hlr=Input::get('hlr');
$update->first_iccid=Input::get('first_iccid');
$update->last_iccid=Input::get('last_iccid');
$update->quantity=Input::get('quantity');
$update->save();

// redirect
Session::flash('message', 'Successfully updated SPK !');
return Redirect::to('spk_view');
}
}
< /code>

и вот представление об обновлении данных: < /p>

@extends('dashboard.dashboard')
@section('content')
@if (Session::has('message'))
{{ Session::get('message') }}
@endif

{{link_to('dashboard','Home');}} > {{link_to('spk_view','SPK');}} > Update SPK


Update SPK

{{ Form::model($spk,array('method' => 'PUT', 'class'=>'form-horizontal','route'=>array('update_spk', $spk->id))) }}

Distribution Code



M99/99/99/9999



{{ $errors->first('distribution_code',
'
×
Anda belum mengisi data dengan benar !

') }}



Destination



{{ $errors->first('destination',
'
×
Anda belum mengisi data dengan benar !

') }}



HLR



{{ $errors->first('hlr',
'
×
Anda belum mengisi data dengan benar !

') }}



First ICCID



{{ $errors->first('first_iccid',
'
×
Anda belum mengisi data dengan benar !

') }}



Last ICCID



{{ $errors->first('last_iccid',
'
×
Anda belum mengisi data dengan benar !

') }}



Quantity



{{ $errors->first('quantity',
'
×
Anda belum mengisi data dengan benar !

') }}



{{ Form::submit('Update SPK', array('class' => 'btn btn-primary btn-line btn-rect')) }}

{{Form::close()}}


@stop
< /code>

Это представление не работает, и в форме не может получить выбранные данные из $ id < /code>. Это возвращает эту ошибку: < /p>


"Неопределенное свойство: illuminate \ database \ eloquent \ collection :: $ id (View: c: \ xampp \ htdocs \ ims2 \ app \ siew \ modals \ edit-spk.blade.php)" < /p>
< /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < /> < />>

Подробнее здесь: https://stackoverflow.com/questions/300 ... in-laravel
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»