Last active
August 16, 2018 18:52
-
-
Save betinho37/ccfce2f5000f7c500f8ae7341820af73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Publicacao; | |
use App\User; | |
use App\Categoria; | |
use Illuminate\Support\Facades\DB; | |
use Storage; | |
use File; | |
class PublicacaoController extends Controller | |
{ | |
private $publicacao, $user, $categoria; | |
public function __construct(Publicacao $publicacao, User $user, Categoria $categoria) | |
{ | |
$this->publicacao = $publicacao; | |
$this->user = $user; | |
$this->categoria = $categoria; | |
} | |
public function index() | |
{ | |
/*$publicacao = $this->publicacao->all(); | |
return view('publicacoes.index', compact('publicacao'));*/ | |
$publicacao = Publicacao::where('situacao', '=', 1)->get(); | |
return view('publicacoes.index', ['publicacao' => $publicacao]); | |
} | |
public function home() | |
{ | |
$tipousuario = auth()->user()->tipousuario; | |
$publicacao = $this->publicacao; | |
if($tipousuario != 0) { | |
$publicacao = $publicacao->where('publicacoes.userid', '=', auth()->user()->id) | |
->orderBy('situacao', 'asc') | |
->simplePaginate(100); | |
return view('publicacoes.controle', compact('publicacao')); | |
} | |
$publicacao = $publicacao->orderBy('situacao', 'asc')->get(); | |
return view('admin.home', compact('publicacao')); | |
} | |
public function show() | |
{ | |
$publicacao = Publicacao::find($id); | |
return view('publicacoes.carrousel', compact('publicacao')); | |
} | |
public function create() | |
{ | |
$publicacao = Publicacao::get(); | |
$list_user = $this->user->listUser(); | |
$list_categoria = $this->categoria->listCategoria(); | |
return view('publicacoes.create', compact('publicacao','list_user', 'list_categoria')); | |
} | |
public function store(Request $request) | |
{ | |
$files = $request->file('arquivo'); | |
$file = $request->arquivo; | |
$files = $request->file('pdf'); | |
$file = $request->pdf; | |
if (!is_null($files)) { | |
foreach($files as $file) { | |
$destinationPath = public_path().DIRECTORY_SEPARATOR.'uploads'; | |
$extension = $file->getClientOriginalExtension(); | |
$name['arquivo'] = $file->getClientOriginalName(); | |
$pdf['$pdf'] = $file->getClientOriginalName(); | |
$inputs = $request->all(); | |
$this->publicacao->create($inputs); | |
$file->move( $destinationPath, $name['arquivo'], $extension, $pdf['$pdf'] ); | |
} | |
$inputs = $request->all(); | |
$this->publicacao->create($inputs); | |
return redirect()->action('PublicacaoController@controle'); | |
} | |
$inputs = $request->all(); | |
$this->publicacao->create($inputs); | |
return redirect()->action('PublicacaoController@controle'); | |
} | |
public function edit($id) | |
{ | |
$list_user = $this->user->listUser(); | |
$list_categoria = $this->categoria->listCategoria(); | |
$publicacao = Publicacao::find($id); | |
return view('publicacoes.edit', compact('publicacao','list_user','list_categoria')); | |
} | |
public function update(Request $request, $id) | |
{ | |
$publicacao = Publicacao::find($id); | |
//var_dump(\Input::file('arquivo')); die(); | |
if ($file = \Input::file('arquivo')) | |
{ | |
$destinationPath = public_path().DIRECTORY_SEPARATOR.'uploads'; | |
$extension = $file->getClientOriginalExtension(); | |
$arquivo['arquivo'] = str_random (30).'.'.$extension; | |
$name['arquivo'] = $file->getClientOriginalName(); | |
$file->move( $destinationPath, $name['arquivo'] ); | |
$publicacao->arquivo = $name['arquivo']; | |
$publicacao->save(); | |
} | |
$publicacao->situacao = $request->situacao; | |
$publicacao->categoriaid= $request->categoriaid; | |
$publicacao->posicaoimagem= $request->posicaoimagem; | |
$publicacao->descricao= $request->descricao; | |
$publicacao->titulo= $request->titulo; | |
$publicacao->nome= $request->nome; | |
$publicacao->save(); | |
return redirect()->action('PublicacaoController@controle'); | |
} | |
public function controle() | |
{ | |
$tipousuario = auth()->user()->tipousuario; | |
$publicacao = $this->publicacao; | |
if($tipousuario != 0) { | |
$publicacao = $publicacao->where('publicacoes.userid', '=', auth()->user()->id) | |
->orderBy('situacao', 'asc') | |
->orderBy('created_at', 'desc'); | |
} | |
$publicacao = $publicacao->orderBy('situacao', 'asc') | |
->orderBy('created_at', 'desc') | |
->simplePaginate(10); | |
return view('publicacoes.controle', compact('publicacao')); | |
} | |
public function categorias() | |
{ | |
$publicacao = $this->categoria->all(); | |
return view('publicacoes.categorias.index', compact('publicacao')); | |
} | |
public function pinturas() | |
{ | |
//$publicacao = DB::table('publicacoes')->simplePaginate(6); | |
$publicacao = Publicacao::where('categoriaid', '=', 2)->Simplepaginate(6); | |
return view('publicacoes.categorias.pinturas.index', ['publicacao' => $publicacao]); | |
} | |
public function livros() | |
{ | |
$publicacao = Publicacao::where('categoriaid', '=', 1)->simplePaginate(6); | |
return view('publicacoes.categorias.livros.index', ['publicacao' => $publicacao]); | |
} | |
public function gravuras() | |
{ | |
$publicacao = Publicacao::where('categoriaid', '=', 3)->simplePaginate(6); | |
return view('publicacoes.categorias.gravuras.index', ['publicacao' => $publicacao]); | |
} | |
public function deletfile($name) | |
{ | |
$publicacao = Publicacao::where('arquivo', $name)->first(); | |
$publicacao->arquivo = null; | |
unlink(public_path('uploads/'. $name)); | |
$publicacao->save(); | |
return redirect()->back(); | |
} | |
public function download($id) | |
{ | |
$publicacao = Publicacao::find($id); | |
$filename = $publicacao->arquivo; | |
return response()->download(public_path("uploads/{$filename}")); | |
} | |
public function destroy($id) | |
{ | |
$publicacao = Publicacao::find($id); | |
if ($publicacao->arquivo) { | |
unlink(public_path('uploads/' . $publicacao->arquivo)); | |
$publicacao->delete(); | |
} | |
$publicacao->delete(); | |
return redirect()->back(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('layouts.app') | |
@section('content') | |
<style type="text/css"> | |
select.form-control:not([size]):not([multiple]) { height:calc(2.25rem + 9px); } | |
</style> | |
<div style="padding:70px" > | |
{!! Form::open(array('url' => 'publicacao/store','files'=>'true', 'enctype'=>'multipart/form-data' ,'multiple'=>true,)); !!} | |
{!! csrf_field() !!} | |
<div class="form-group" style="display:none;"> | |
{!!Form::text('userid', Auth::user()->id , ['class'=>'form-control'])!!} | |
</div> | |
<div class="form-group"><p></p> | |
<strong>Nome:</strong><p></p> | |
{!!Form::text('nome', Auth::user()->name , ['class'=>'form-control'])!!} | |
</div> | |
<div class="form-group"><p></p> | |
<strong>Titulo:</strong><p></p> | |
{!!Form::text('titulo', null, ['class'=>'form-control'])!!} | |
</div> | |
@if (Auth::user()->tipousuario == 0 ) | |
<div class="form-group"> | |
<strong id="cat">Categoria:</strong> | |
{!!Form::select('categoriaid', $list_categoria, null, ['class'=>'form-control'])!!} | |
</div> | |
@else | |
@endif | |
<div class="form-group" > | |
<strong>Descrição</strong><p></p> | |
<textarea id="descricao" name="descricao" value="{{ old('descricao') }}" class="form-control" rows="3"></textarea> | |
</div> | |
<div> | |
<img id="uploadPreview" style="width:300px; height: 300;" /><p></p> | |
<input id="arquivo[]" type="file" name="arquivo[]" onchange="PreviewImage();" multiple /> | |
<script type="text/javascript"> | |
function PreviewImage() { | |
var oFReader = new FileReader(); | |
oFReader.readAsDataURL(document.getElementById("arquivo[]").files[0]); | |
oFReader.onload = function (oFREvent) { | |
document.getElementById("uploadPreview").src = oFREvent.target.result; | |
}; | |
}; | |
</script> | |
</div><br /> | |
{!! Form::label('pdf', 'Select file 3', ['class' => 'control-label']) !!} | |
{!! Form::file('pdf', ['id'=>'pdf']) !!} | |
<div align="center"> | |
<button type="submit" class="btn btn-primary" id='btn-salvar'> Salvar </button> | |
<a href="/home" class="btn btn-primary">Cancelar</a> | |
</div> | |
{!! Form::close() !!} | |
</div> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$("#btn-salvar").click( function(event) { | |
var salvar = confirm('Sua publicação será avaliada e em breve estará disponível na Galeria'); | |
if (salvar){ | |
}else{ | |
event.preventDefault(); | |
} | |
}); | |
}); | |
</script> | |
@endsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment