lundi 17 juin 2019

Existing image is not displaying in edit form to update in larvel(5.8)

I am trying to make todo list wherein updating form other field value is shown but for image the value is read from the folder but not display in the input field.

everything works fine else this problem.

This display the image name<?php echo $task->img; ?>

I use dd("$task->img"); to check the values.

edit.blade.php

        <label for="title">Task Title</label>
        <input type="text" value="" class="form-control" id="taskTitle"  name="title" >
      </div>
      <div class="form-group col-6">
        <label for="description">Task Description</label>
        <input type="text" value="" class="form-control" id="taskDescription" name="description" >
      </div>
 <div class="form-group col-6">
        <label for="img">Task Image</label>
        <input type="file" value="{!! $task->img !!}" class="form-control" id="taskImg" name="img" >
      </div>

taskcontroller.php

 public function update(Request $request, Task $task)
    {

        // dd("$task");
        //Validate
        $request->validate([
            'title' => 'required|min:3',
            'description' => 'required',
            'img' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',

        ]);

        $task->title = $request->title;
        $task->description = $request->description;

        if($request->hasFile('img')) {
            $file = $request->file('img');
            $newVar = strtotime(date('d-m-Y h:i:s'));
            $extension = $file->getClientOriginalExtension(); // getting image extension
            $filename = $newVar.'.'.$extension;
            $file->move('task',$filename);
            $task->img = $filename;
        }


        $task->update();
        $request->session()->flash('message', 'Successfully modified the task!');
       return redirect()->route('tasks.index');
    }```



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire