Я создал форму для обновления ролевой модели, но при нажатии на кнопку «Сохранить» она, похоже, не подчиняется методу контроллера. Даже сообщение об ошибках проверки не появляется, если поле ввода имени неверно. Ниже вы можете найти код, используемый для формы.
Форма:
{!! Form::model($role, ['route' => ['roles.update', $role->id], 'method' => 'put']) !!}
@include('roles.fields')
{!! Form::close() !!}
Поля для формы:
<!-- Name Field -->
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<!-- Display Name Field -->
<div class="form-group col-sm-6">
{!! Form::label('display_name', 'Display Name:') !!}
{!! Form::text('display_name', null, ['class' => 'form-control']) !!}
</div>
<!-- Description Field -->
<div class="form-group col-sm-12 col-lg-12">
{!! Form::label('description', 'Description:') !!}
{!! Form::textarea('description', null, ['class' => 'form-control', 'rows' => '5']) !!}
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{!! route('roles.index') !!}" class="btn btn- default">Cancel</a>
</div>
Запрос:
namespace App\Http\Requests;
use App\Http\Requests\Request;
use App\Models\Role;
class UpdateRoleRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return Role::$rules;
}
}
Контроллер:
/**
* Update the specified Role in storage.
*
* @param int $id
* @param UpdateRoleRequest $request
*
* @return Response
*/
public function update($id, UpdateRoleRequest $request)
{
$role = $this->roleRepository->findWithoutFail($id);
if (empty($role)) {
Flash::error('Role not found');
return redirect(route('roles.index'));
}
$role = $this->roleRepository->update($request->all(), $id);
Flash::success('Role updated successfully.');
return redirect(route('roles.index'));
}
Модель:
<?php
namespace App\Models;
use Eloquent as Model;
use Zizaco\Entrust\EntrustRole;
use Illuminate\Database\Eloquent\SoftDeletes;
class Role extends EntrustRole
{
use SoftDeletes;
public $table = 'roles';
protected $dates = ['deleted_at'];
public $fillable = [
'name',
'display_name',
'description'
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'name' => 'string',
'display_name' => 'string'
];
/**
* Validation rules
*
* @var array
*/
public static $rules = [
'name' => 'required|unique:roles'
];
}
Пожалуйста, помогите, если это возможно. Спасибо!