<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Medium;
use Illuminate\Http\Request;

class MediaController extends Controller
{
    public function edit(Medium $medium)
    {
        return view('backend.media.form', [
            'medium' => $medium,
        ]);
    }

    public function update(Request $request, Medium $medium)
    {
        try {
            $medium->fill($request->only('url'))->save();
            $medium->post->fill($request->post)->save();

            return back()->with('status', 'La imagen ha sido editada');
        } catch(\Exception $e) {
            return back()->withInput()->withErrors($e->getMessage());
        }
    }


    public function destroy(Medium $medium)
    {
        $medium->delete();

        return redirect()->back()->with('status', 'La imagen ha sido eliminada');
    }
}
