我能夠顯示現有文本,如名稱和地址,但無法在編輯窗體中顯示圖像。 我的show.blade.php在編輯表單中顯示現有圖像並使用laravel進行更新
@section('content')
<p>This is user {{ $profile->name }}</p>
<p>This is address {{ $profile->address }}</p>
<img src= "/storage/images/{{ $profile->images }}" style="width:504px;height:228px />
@endsection
這工作正常。
現在edit.blade.php
<div class="container">
<form method="POST" action="/profiles/{{$profile->id}}" enctype="multipart/form-data">
{{ method_field('PATCH') }}
{{ csrf_field() }}
<div class="form-group">
name <input type="text" name="name" value="{{ $profile->name }}" />
</div>
<div class="form-group">
address <input type="textarea" name="address" value="{{ $profile->address }}" />
</div>
<div class="form-group">
@if ("/storage/images/{{ $profile->images }}")
<img src="{{ $profile->image }}">
@else
<p>No image found</p>
@endif
image <input type="file" name="image" value="{{ $profile->images }}"/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>``
</div>
當我嘗試保存表單更新的圖像時,即一個不同勢圖像路徑保存在數據庫表
/tmp/phpHs0Io6
存儲控制器是
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|max:255',
'address' => 'nullable' ,
]);
$profile = new profile;
$profile-> user_id = auth()->id();
$profile-> name = $request->name;
$profile-> address = $request->address;
$request->image->store('public/images');
$path = $request->image->hashName();
$profile-> images = $path;
$profile->save();
return redirect('/home');
}
和更新控制器是
public function update(Request $request, profile $profile)
{
$this->validate($request, [
'name' => 'required|max:255',
'address' => 'nullable' ,
]);
$profile->update($request->all());
$profile-> name = $request->name;
$profile-> address = $request->address;
$request->image->store('public/images');
$path = $request->image->hashName();
$profile-> images = $path;
$profile->save();
return redirect('/home');
}