Skip to content

Commit

Permalink
Fix save existing post
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozach committed Apr 22, 2018
1 parent 1c1eaeb commit f879318
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Http/Controllers/Kiosk/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests;
use App\Http\Controllers\Controller;
use UrbanAnalog\Gazette\Models\Post;
use UrbanAnalog\Gazette\Models\Media;
use Illuminate\Validation\Rule;

class PostsController extends Controller
Expand Down Expand Up @@ -102,15 +103,19 @@ public function update(Request $request, $id)
'slug' => Rule::unique('posts')->ignore($id)
]);

$post = Post::find($id)->with('featured_image');
$post = Post::with('featured_image')->find($id);

$post->title = $request->title;
$post->slug = $request->slug;
$post->content = $request->content ?: null;
$post->meta_title = $request->meta_title ?: null;
$post->meta_description = $request->meta_description ?: null;
$post->robots = $request->robots ?: null;
$post->media_id = $request->media_id ?: null;

if (isset($request->media_id)) {
$media = Media::find($request->media_id);
$post->featured_image()->associate($media);
}

$post->save();

Expand Down

0 comments on commit f879318

Please sign in to comment.