app/Http/Controllers/TasksController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request)
    {
        $this->validate($request, [
            'company' => 'required', 
            'title' => 'required',
            'assigned_to' => 'required',
            'priority' => 'required',
            'image.*' => 'mimes:jpg,jpeg,png|max:2000'
          ],[
            'image.*.mimes' => 'Only jpeg, png, jpg images are allowed',
            'image.*.max' => 'Sorry! Maximum allowed size for an image is 2MB',
        ]);
        if($request->hasFile('image'))
        {   
            $data = Task::find($request->task);
            foreach($request->file('image') as $image) 
            {
                $filename = $image->getClientOriginalName();
                $image->storeAs('tasks', $filename);
                $imgData = json_decode($data->image);
                array_push($imgData,$filename);
                $data->image = json_encode($imgData);
                $data->save();
            }
        }
        $data = Task::find($request->task);
        $data->title = $request->title;
        $data->description = $request->description;
        $data->department = $request->department;
        $data->assigned_to = json_encode($request->assigned_to);
        $data->contact_person = $request->contact_person;
        $data->priority = $request->priority;
        $data->company = $request->company;
        $data->save();
        session()->flash('success', 'Task updated successfully');
        $completed = Task::select('*')
            ->where('completed', '=', 0)
            ->orderBy('priority', 'asc')
            ->orderBy('updated_at', 'DESC')
            ->get();    
            return redirect()->route('tasks.show', $data->id)->with('companies', Company::all())->with('users', User::all())->withTasks($completed);
    }
public function update ( Request $ request ) { $ this -> validate ( $ request , [ 'company' => 'required' , 'title' => 'required' , 'assigned_to' => 'required' , 'priority' => 'required' , 'image.*' => 'mimes:jpg,jpeg,png|max:2000' ] , [ 'image.*.mimes' => 'Only jpeg, png, jpg images are allowed' , 'image.*.max' => 'Sorry! Maximum allowed size for an image is 2MB' , ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ data = Task :: find ( $ request -> task ) ; foreach ( $ request -> file ( 'image' ) as $ image ) { $ filename = $ image -> getClientOriginalName ( ) ; $ image -> storeAs ( 'tasks' , $ filename ) ; $ imgData = json_decode ( $ data -> image ) ; array_push ( $ imgData , $ filename ) ; $ data -> image = json_encode ( $ imgData ) ; $ data -> save ( ) ; } } $ data = Task :: find ( $ request -> task ) ; $ data -> title = $ request -> title ; $ data -> description = $ request -> description ; $ data -> department = $ request -> department ; $ data -> assigned_to = json_encode ( $ request -> assigned_to ) ; $ data -> contact_person = $ request -> contact_person ; $ data -> priority = $ request -> priority ; $ data -> company = $ request -> company ; $ data -> save ( ) ; session ( ) -> flash ( 'success' , 'Task updated successfully' ) ; $ completed = Task :: select ( '*' ) -> where ( 'completed' , '=' , 0 ) -> orderBy ( 'priority' , 'asc' ) -> orderBy ( 'updated_at' , 'DESC' ) -> get ( ) ; return redirect ( ) -> route ( 'tasks.show' , $ data -> id ) -> with ( 'companies' , Company :: all ( ) ) -> with ( 'users' , User :: all ( ) ) -> withTasks ( $ completed ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// if(!$data->image == '') // { //     foreach (json_decode($data->image) as $images)  //     {  //         Storage::delete("tasks/{$images}");    //     }    // } //flash message //redirect user