Commit 5e121a18 by Angel MAS

registra entradas

parent 3c8e9a36
......@@ -6,45 +6,191 @@ use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Yajra\Datatables\Datatables;
use Onestartup\Blog\Model\EntryCategory as Category;
use Onestartup\Blog\Model\EntryTag as TagCatalog;
use Onestartup\Blog\Model\Entry;
class AdminBlogController extends Controller
{
public function index()
{
return view('blog::entry.index');
}
public function list()
/**
* Show the form for creating a new resource.
* @return Response
*/
public function create()
{
return view('blog::list');
$categories = Category::pluck('name', 'id');
$tags = TagCatalog::pluck('description', 'description');
return view('blog::entry.create')
->with('categories', $categories)
->with('tags', $tags);
}
/*public function datatable()
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$interesteds = Interested::select(['id','name','email', 'phone','landing','origin','created_at'])->orderBy('id', 'desc');
$post = new Entry($request->all());
$post->tags = implode(",", $request->tags);
if (isset($request->cover)) {
$file = $request->file('cover');
$nombre = $file->getClientOriginalName();
$nombre_file = str_replace(' ', '_', $nombre);
$ubicacion_donde_guarda ='posts/'.$nombre_file;
\Storage::disk('local')->put($ubicacion_donde_guarda, \File::get($file));
$post->cover = $ubicacion_donde_guarda;
}
return Datatables::of($interesteds)
->addColumn('details_url', function ($interested) {
return "<a href='".route('crm.show',$interested->id)."'>Ver Detalle</a>";
})
->rawColumns(['details_url'])
->make();
}*/
\Auth::user()->entries()->save($post);
/*public function show($id)
return redirect()
->route('blog.admin.entry.edit', $post->id)
->with('message_success', "Entrada agregada correctamente");
}
/**
* Show the specified resource.
* @return Response
*/
public function show()
{
$interested = Interested::find($id);
return view('blog::show');
}
return view('crm::show')
->with('interested', $interested);
/**
* Show the form for editing the specified resource.
* @return Response
*/
public function edit($id)
{
$entry = Entry::find($id);
$categories = Category::pluck('name', 'id');
$tags = TagCatalog::pluck('description', 'description');
return view('blog::entry.edit')
->with('categories', $categories)
->with('post', $entry)
->with('tags', $tags);
}
public function storeTracing(Request $request, $id)
/**
* Update the specified resource in storage.
* @param Request $request
* @return Response
*/
public function update(Request $request, $id)
{
$interested = Interested::find($id);
$comment = new Tracing($request->all());
$comment->user_id = \Auth::user()->id;
$post = Entry::find($id);
$post->fill($request->all());
$post->tags = implode(",", $request->tags);
if (isset($request->cover) && $request->cover != '') {
$file = $request->file('cover');
$nombre = $file->getClientOriginalName();
$nombre_file = str_replace(' ', '_', $nombre); //reemplaza los eespacios en los archivos por guin bajo
$ubicacion_donde_guarda ='posts/'.$nombre_file;
\Storage::disk('local')->put($ubicacion_donde_guarda, \File::get($file));
$post->cover = $ubicacion_donde_guarda;
}
$post->save();
return redirect()
->back()
->with('message_info', 'Información actualizada correctamente');
}
$interested->tracings()->save($comment);
/**
* Remove the specified resource from storage.
* @return Response
*/
public function destroy($id)
{
$entry = Entry::find($id);
$entry->delete();
return redirect()
->back()
->with('message_success', 'Información agregada correctamente');
}*/
->with('message_danger', 'Entrada eliminada correctamente');
}
public function getEntries()
{
$entries = Entry::select(['id','title','slug', 'body','status', 'cover','tags','created_at', 'category_id', 'publication_date', 'views']);
return Datatables::of($entries)
->addColumn('preview', function ($entry) {
return "<p><b>$entry->title</b></p>".
"<img src='".asset('storage/'.$entry->cover)."' class='image-entry'/>";
})
->addColumn('content', function ($entry) {
return "<p>".strip_tags(substr($entry->body, 0, 250).'...', '')."</p>".
"<p class='mb0'>Etiquetas: <b>".str_replace(',', ', ',$entry->tags)."</b></p>".
"<p class='mb0'>Categoría: <b>".$entry->category->name."</b></p>".
"<p class='mb0'>Estatus: <b>".($entry->status==1 ? 'Activo':'Inactivo')."</b></p>".
"<p class='mb0'>Publicado: <b>".($entry->publication_date != null ? $entry->publication_date : 'No asignado')."</b></p>".
"<p class='mb0'>URL del artículo: <a target='_blank' class='link' href='".route('show.blog', $entry->slug)."'>".route('show.blog', $entry->slug)."</a></p>".
"<p class='mb0'>Visitas: <b>".$entry->views."</b></p>";
})
->addColumn('form', function ($entry) {
return "<form method='POST' action='".route('delete.entry',$entry->id)."'>".
csrf_field() .
"<button class='btn btn-danger btn-xs button-mb' onclick='return confirm();' type='submit'>".
"<i class='fas fa-trash-alt icon-special-size'></i>Eliminar</button>".
"</form>".
"<a href='".route('show.blog', $entry->slug)."' class='btn btn-xs info button-mb' target='new'>".
"<i class='fas fa-eye icon-special-size'></i>Ver</a>".
"<br><a href='".route('blog.admin.entry.edit', $entry->id)."' class='btn btn-xs accent mb0'>".
"<i class='fas fa-edit icon-special-size'></i>Editar</a>";
})
->filterColumn('preview', function($query, $keyword) {
$query->whereRaw("title like ?", ["%{$keyword}%"]);
})
->filterColumn('form', function($query, $keyword) {
$query->whereRaw("title like ?", ["%{$keyword}%"]);
})
->filterColumn('content', function($query, $keyword) {
$query->whereRaw("tags like ?", ["%{$keyword}%"]);
})
->order(function ($query) {
if (request()->has('preview')) {
$query->orderBy('title', 'asc');
}
if (request()->has('content')) {
$query->orderBy('title', 'desc');
}
if (request()->has('form')) {
$query->orderBy('title', 'asc');
}
})
->rawColumns(['preview', 'content', 'form'])
->make();
}
public function deleteCover($id)
{
$entry = Entry::find($id);
$entry->cover = null;
$entry->save();
return redirect()
->back()
->with('message_success', 'Imagen eliminada correctamente');
}
}
......@@ -2,12 +2,18 @@
Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
Route::get('admin/blog','Onestartup\Blog\Controller\AdminBlogController@list')
->name('blog.list');
Route::resource('admin/blog/category', 'Onestartup\Blog\Controller\CategoryController', ['as'=>'blog.admin']);
Route::delete('delete/cover/category/{id}', 'Onestartup\Blog\Controller\CategoryController@deleteCover')
->name('delete.cover.category');
Route::resource('admin/blog/tag', 'Onestartup\Blog\Controller\TagCatalogController', ['as'=>'blog.admin']);
Route::resource('admin/blog/entry', 'Onestartup\Blog\Controller\AdminBlogController', ['as'=>'blog.admin']);
Route::resource('admin/blog/category', 'Onestartup\Blog\Controller\CategoryController', ['as'=>'blog.admin']);
Route::get('admin/blog/datatable', 'Onestartup\Blog\Controller\AdminBlogController@getEntries')->name('blog.datatable');
Route::post('delete/entry/{id}', 'Onestartup\Blog\Controller\AdminBlogController@destroy')->name('delete.entry');
Route::delete('delete/cover/entry/{id}', 'Onestartup\Blog\Controller\AdminBlogController@deleteCover')->name('delete.cover.entry');
});
Route::group(['middleware' => ['web']], function(){
Route::get('blog/{slug}', 'Onestartup\Blog\Controller\AdminBlogController@getEntries')->name('show.blog');
});
@extends('layouts.admin.admin-layout')
@section('content')
<div class='row'>
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>Actualizar información</h2>
</div>
<div class='box-body'>
{!! Form::open(['route'=> 'blog.admin.entry.store','method'=>'POST', 'enctype'=>'multipart/form-data', "id"=>"target"]) !!}
@include('blog::entry.fields')
</div>
<div class='dker p-a text-right'>
<div class='col-md-12'>
<a class='btn danger' href="{{route('blog.admin.entry.index')}}" style='margin-right:10px'>Cancelar</a>
<button class='btn dark' type='submit'>
Registrar
</button>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
@endsection
@section('script_extras')
<script src='https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js'></script>
<script>
var options = {
filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images',
filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token=',
filebrowserBrowseUrl: '/laravel-filemanager?type=Files',
filebrowserUploadUrl: '/laravel-filemanager/upload?type=Files&_token='
};
</script>
<script>
CKEDITOR.replace('body', options);
$('#tags').select2();
$("#publication_date").datepicker({
dateFormat: "yy-mm-dd"
});
</script>
@endsection
@extends('layouts.admin.admin-layout')
@section('content')
<div class='row'>
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>Actualizar información</h2>
</div>
<div class='box-body'>
{!! Form::model($post,['route'=> ['blog.admin.entry.update',$post->id],"method"=>"PUT", 'enctype'=>'multipart/form-data']) !!}
@include('blog::entry.fields')
</div>
<div class='dker p-a text-right'>
<div class='col-md-12'>
<a class='btn danger' href="{{route('blog.admin.entry.index')}}" style='margin-right:10px'>Cancelar</a>
{!! Form::submit('Actualizar información', ['class'=>'btn dark']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
<!-- .modal nuevo contrato -->
<div class='modal fade' data-backdrop='true' id='ver'>
<div class='modal-dialog modal-lg'>
<div class='modal-content box-shadow-z3'>
<div class='modal-body text-center p-lg'>
@if ($post->cover == null)
<h4>No hay imagen asignada</h4>
@else
<img class='image-modal-preview' src="{{asset('storage/'.$post->cover)}}">
@endif
</div>
<div class='modal-footer'>
<button class='btn dark p-x-md' data-dismiss='modal' type='button'>Cerrar</button>
@if($post->cover != null)
{!! Form::open(['route'=> ['delete.cover.entry',$post->id],'method'=>'DELETE'])!!}
<button class='btn btn-danger button-mb' onclick="return confirm('¿Estás seguro de eliminar este elemento?');" type='submit'>
<i class='fas fa-trash-alt icon-special-size'></i>
Eliminar
</button>
{!! Form::close()!!}
@endif
</div>
</div>
<!-- /.modal-content -->
</div>
</div>
@endsection
@section('script_extras')
<script src='https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js'></script>
<script>
var options = {
filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images',
filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token=',
filebrowserBrowseUrl: '/laravel-filemanager?type=Files',
filebrowserUploadUrl: '/laravel-filemanager/upload?type=Files&_token='
};
</script>
<script>
CKEDITOR.replace('body', options);
$('#tags').select2();
$("#publication_date").datepicker({
dateFormat: "yy-mm-dd"
});
</script>
@endsection
<div class="row">
<div class="col-md-6">
<div class="form-group">
{!! Form::label('title', 'Titúlo', ['class'=>'control-label'])!!}
{!! Form::text('title', null, ["class"=>"form-control", "required"=>"required", "id"=>"first"]) !!}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{!! Form::label('slug', 'URL Slug', ['class'=>'control-label'])!!}
{!! Form::text('slug', null, ["class"=>"form-control", "required"=>"required", "id"=>"second"]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
{!! Form::label('cover', 'Portada', ['class'=>'control-label'])!!}
@if (isset($post))
<span>
<a class="btn btn-xs accent" data-target="#ver" data-toggle="modal" href="#" ui-toggle-class="fade-up-big">
Ver actual
<i class="fa fa-eye"></i>
</a>
</span>
@endif
<br>
{!! Form::file('cover', null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
<div class="form-group">
{!! Form::label('tags', 'Etiquetas', ['class'=>'control-label'])!!}
{!! Form::select('tags[]', $tags, isset($post->tags) ? explode(",",$post->tags) : null, ["class"=>"form-control", "required"=>"required", "id"=>"tags", "multiple"=>"multiple"]) !!}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{!! Form::label('publication_date', 'Fecha de publicación', ['class'=>'control-label'])!!}
{!! Form::text('publication_date', null, ["class"=>"form-control", "required"=>"required", "id"=>"publication_date"]) !!}
</div>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<div class="form-group" >
{!! Form::label('status', 'Estado', ['class'=>'control-label'])!!}
{!! Form::select('status', [1=>'Activo', 2=>'Inactivo'], null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
<div class='col-md-6'>
<div class="form-group" >
{!! Form::label('category_id', 'Categoria', ['class'=>'control-label'])!!}
{!! Form::select('category_id', $categories, null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
{!! Form::label('body', 'Contenido', ['class'=>'control-label'])!!}
{!! Form::textarea('body', null, ["class"=>"form-control", "required"=>"required", 'id'=>'body', 'rows'=>"30", 'cols'=>"80"]) !!}
</div>
</div>
@extends('layouts.admin.admin-layout')
@section('content')
<div class='row'>
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>
Listado de entradas
<span>
<a class='btn btn-xs btn-info button-ml' href="{{route('blog.admin.entry.create')}}">
<i class='fas fa-plus'></i>
Agregar Entrada
</a>
</span>
</h2>
</div>
<div class='box-body'>
<table class='table' id='posts'>
<thead>
<tr>
<th>#</th>
<th>Publicación</th>
<th>Contenido</th>
<th></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script>
$(function() {
$('#posts').DataTable({
processing: true,
serverSide: true,
pageLength: 25,
ajax: '{{ route("blog.datatable") }}',
columns: [
{data: 'id', name: 'id'},
{data: 'preview', name: 'preview'},
{data: 'content', name: 'content'},
{data: 'form', name: 'form'},
]
});
});
</script>
@endpush
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment