destino = [ 'caminho' => storage_path() . '/data/noticia/', 'resolucao' => [0 => [150,100], 1 => [400,300], 2 => [800,600]] ]; } public function index() { $this->verificaPermissao('noticia.visualizar'); $noticias = Noticia::orderBy('created_at', 'desc')->get(); return view('controle.noticia.index', compact('noticias')); } public function form(Noticia $noticia = null) { $data = []; if (isset($noticia->id)) { $this->verificaPermissao('noticia.alterar'); array_push($data, 'noticia'); } else { $this->verificaPermissao('noticia.cadastrar'); } return view('controle.noticia.form', compact($data)); } public function save(Request $request, Noticia $noticia = null) { $input = $request->except('_token'); $imagem = $request->file(); $input['ativo'] = (isset($input['ativo'])) ? 1 : 0; if(isset($imagem) && count($imagem)) { $input['imagem'] = Upload::salva($imagem, $this->destino); } if ($noticia->id) { if ($noticia->update($input)) { Cache::put('noticias', Noticia::orderBy('created_at', 'desc')->get(), 5); return redirect()->route('controle.noticia.index')->with('msg', 'Operação realizada com sucesso')->with('error', false); } } else { $noticia = Noticia::create($input); } if (!$noticia->id) { return redirect()->route('controle.noticia.form', $id)->with('msg', 'Não foi possível efetuar a operação')->with('error', true); } return redirect()->route('controle.noticia.index')->with('msg', 'Operação realizada com sucesso')->with('error', false); } public function excluir(Noticia $noticia) { $this->verificaPermissao('noticia.excluir'); if ($noticia and $noticia->delete()) { return redirect()->route('controle.noticia.index')->with('msg', 'Operação realizada com sucesso')->with('error', false); } return redirect()->route('controle.noticia.index')->with('msg', 'Não foi possível efetuar a operação')->with('error', true); } }