4 months ago

Update data with current image file using same form request from store function

Posted 4 months ago by FareedR

how can i use same form request on update function ? it keep display to me " Image field is required " but i dont want to update image , i just want to update other data only . not image .

// form request
public function rules()
        return [
            'title' => 'required|min:6',
            'image' => 'required|image|mimes:png|dimensions:width=1920,height=1076',
            'description' => 'required|min:6',
            'status' => 'required'
 public function updateBanner(BannerFormRequest $request,$id)
        $banner = Banner::findOrFail($id);

            $oldImage = Storage::disk('public')->delete('{{ $banner->image }}');
            $image = $request->file('image')->store('banners','public');

        $banner->title = $request->get('title');
        $banner->description = $request->get('description');
        $banner->status = $request->get('status');

        toastr()->success('Banner has been updated');
        return redirect()->route('list-banner');
<div class="block-content">
            <form action="{{ route('update-banner', $banner->id) }}" method="post" enctype="multipart/data">
                <div class="form-group">
                    <label for="input-title">Title</label>
                    <input type="text" class="form-control" name="title" value="{{ $banner->title }}">
                <div class="form-group">
                    <label for="input-image">Image</label>
                    <input type="file" class="form-control" name="image">
                    <div class="img">
                        <img class="img-fluid" style="width:50%" src="{{ Storage::url($banner->image) }}">
                <div class="form-group">
                    <label for="input-description">Description</label>
                    <input type="text" class="form-control" name="description" value="{{ $banner->description }}">
                <div class="form-group">
                    <label for="input-status">Status</label>
                    <select name="status" class="form-control">
                        <option value="0">Inactive</option>
                        <option value="1" selected>Active</option>
                        <option value="0" selected>Inactive</option>
                        <option value="1">Active</option>
                <div class="form-group">
                    <button type="submit" class="btn btn-alt-primary">Submit</button>

Please sign in or create an account to participate in this conversation.