app/Http/Controllers/EventController.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, $id)
    {
        $image_name = $request->hidden_image;
        $image = $request->file('image');
        if($image != ''){
          $request->validate([
            'title' => 'required',
            'venue' => 'required',
            'date' => 'required',
            'description' => 'required',
            'image' => 'image|max:2048'
          ]);
          $image_name = rand() . '.' . $image->getClientOriginalExtension();
          $image->move(public_path('images'), $image_name);
        }else{
          $request->validate([
            'title' => 'required',
            'venue' => 'required',
            'date' => 'required',
            'description' => 'required',
          ]);
        }
        $form_data = array(
          'title' => $request->title,
          'venue' => $request->venue,
          'date' => $request->date,
          'description' => $request->description,
          'image' => $image_name
        );
        Event::whereId($id)->update($form_data);
        return redirect('events.index')->with('success', 'Data is successfully updated');
    }
public function update ( Request $ request , $ id ) { $ image_name = $ request -> hidden_image ; $ image = $ request -> file ( 'image' ) ; if ( $ image != '' ) { $ request -> validate ( [ 'title' => 'required' , 'venue' => 'required' , 'date' => 'required' , 'description' => 'required' , 'image' => 'image|max:2048' ] ) ; $ image_name = rand ( ) . '.' . $ image -> getClientOriginalExtension ( ) ; $ image -> move ( public_path ( 'images' ) , $ image_name ) ; } else { $ request -> validate ( [ 'title' => 'required' , 'venue' => 'required' , 'date' => 'required' , 'description' => 'required' , ] ) ; } $ form_data = array ( 'title' => $ request -> title , 'venue' => $ request -> venue , 'date' => $ request -> date , 'description' => $ request -> description , 'image' => $ image_name ) ; Event :: whereId ( $ id ) -> update ( $ form_data ) ; return redirect ( 'events.index' ) -> with ( 'success' , 'Data is successfully updated' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .