【发布时间】:2021-05-12 00:08:10
【问题描述】:
我从 Laravel 5.5 开始。 尝试将数据发送到编辑表单时出现错误:
`非法字符串偏移'name'(查看:C:\xampp\htdocs\laravel-ads\resources\views\admin\edit.blade.php)
public function edit($id)
{
//
$user = User::findOrFail($id);
//var_dump($user['name']);
return view('admin.edit', compact('user'));
}
<div class="container">
<h1 class="text center">Editor de Usuario</h1>
{!! Form::model($user, ['method' => 'PATCH', 'action' => ['AdminController@update', $user->id], 'files' => true]) !!}
<div class="form-group">
{!! Form::label('id', 'Id') !!}
{!! Form::number('id', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('id_rol', 'Rol') !!}
{!! Form::number('id_rol', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('imagen', 'Imagen') !!}
{!! Form::file('imagen', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('name', 'Nombre') !!}
{!! Form::text('name', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('email', 'Email') !!}
{!! Form::email('email', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password', 'Password') !!}
{!! Form::password('password', '', ['class' => 'form-control']) !!}
</div>
{!! Form::submit('Editar', ['class' => 'btn btn-success']) !!}
{!! Form::close() !!}
</div>
路线:
Route::resource('admin', 'AdminController');
我的 index.blade.php:
<div class="container-fluid"></div>
<h1 class="text-center"> Usuarios</h1>
<div class="table-responsive">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Rol</th>
<th scope="col">Foto</th>
<th scope="col">Nombre</th>
<th scope="col">Email</th>
<th scope="col">Ultima actualizacion</th>
<th scope="col">Creado</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<th scope="row">{{$user->id}}</th>
<td>{{$user->id_rol}}</td>
<td><img src="images/{{$user->imagen}}" alt="imagen de usuario" width="150"></td>
<td><a href="{{route('admin.edit',$user->id)}}"> {{$user->name}}</a></td>
<td>{{$user->email}}</td>
<td>{{$user->updated_at}}</td>
<td>{{$user->created_at}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
问题跳到 Laravel 这个地方:
* @param string $value
* @param array $options
*
* @return \Illuminate\Support\HtmlString
*/
public function input($type, $name, $value = null, $options = [])
{
$this->type = $type;
if (! isset($options['name'])) {
$options['name'] = $name;
}
// We will get the appropriate value for the given field. We will look for the
// value in the session for the value in the old input data then we'll look
// in the model instance if one is set. Otherwise we will just use empty.
$id = $this->getIdAttribute($name, $options);
if (! in_array($type, $this->skipValueTypes)) {
$value = $this->getValueAttribute($name, $value);
}
// Once we have the type, value, and ID we can merge them into the rest of the
// attributes array so we can convert them into their HTML attribute format
// when creating the HTML element. Then, we will return the entire input.
$merge = compact('type', 'value', 'id');
【问题讨论】:
标签: laravel-5 laravelcollective