app/Http/Controllers/Admin/AdminPostController.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(PostEditRequest $request, $id)
    {
      $post = Post::findOrFail($id);
      if($file = $request->file('first_photo')){
        $name = time() . $file->getClientOriginalName() ;
        $file->move('images', $name);
        $photo = new Photo();
        $photo->name = $file->getClientOriginalName();
        $photo->path = $name;
        $photo->user_id = Auth::id();
        $photo->save();
        $post->photo_id = $photo->id;
      }
      $post->title = $request->input('title');
      if($request->input('slug')){
        $post->slug = make_slug($request->input('slug'));
      }else{
        $post->slug = make_slug($request->input('title'));
      }
      $post->description = $request->input('description');
      $post->category_id = $request->input('category');
      $post->meta_description = $request->input('meta_description');
      $post->meta_keywords = $request->input('meta_keywords');
      $post->status = $request->input('status');
      $post->save();
      Session::flash('update_post', 'مطلب جدید با موفقیت ویرایش شد');
      return redirect('/admin/posts');
    }
public function update ( PostEditRequest $ request , $ id ) { $ post = Post :: findOrFail ( $ id ) ; if ( $ file = $ request -> file ( 'first_photo' ) ) { $ name = time ( ) . $ file -> getClientOriginalName ( ) ; $ file -> move ( 'images' , $ name ) ; $ photo = new Photo ( ) ; $ photo -> name = $ file -> getClientOriginalName ( ) ; $ photo -> path = $ name ; $ photo -> user_id = Auth :: id ( ) ; $ photo -> save ( ) ; $ post -> photo_id = $ photo -> id ; } $ post -> title = $ request -> input ( 'title' ) ; if ( $ request -> input ( 'slug' ) ) { $ post -> slug = make_slug ( $ request -> input ( 'slug' ) ) ; } else { $ post -> slug = make_slug ( $ request -> input ( 'title' ) ) ; } $ post -> description = $ request -> input ( 'description' ) ; $ post -> category_id = $ request -> input ( 'category' ) ; $ post -> meta_description = $ request -> input ( 'meta_description' ) ; $ post -> meta_keywords = $ request -> input ( 'meta_keywords' ) ; $ post -> status = $ request -> input ( 'status' ) ; $ post -> save ( ) ; Session :: flash ( 'update_post' , 'مطلب جدید با موفقیت ویرایش شد'); return redirect ( '/admin/posts' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .