Commit 2681c8fb by Angel MAS

vistas modificables

parent 97cd72cc
...@@ -27,6 +27,7 @@ class BlogServiceProvider extends ServiceProvider ...@@ -27,6 +27,7 @@ class BlogServiceProvider extends ServiceProvider
$this->app->make('Onestartup\Blog\Controller\AdminBlogController'); $this->app->make('Onestartup\Blog\Controller\AdminBlogController');
$this->app->make('Onestartup\Blog\Controller\CategoryController'); $this->app->make('Onestartup\Blog\Controller\CategoryController');
$this->app->make('Onestartup\Blog\Controller\TagCatalogController'); $this->app->make('Onestartup\Blog\Controller\TagCatalogController');
$this->app->make('Onestartup\Blog\Controller\BlogController');
$this->loadViewsFrom(__DIR__.'/views', 'blog'); $this->loadViewsFrom(__DIR__.'/views', 'blog');
} }
} }
<?php
namespace Onestartup\Blog\Controller;
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 BlogController extends Controller
{
public function index(Request $request)
{
if(isset($request->category)){
$category = Category::where('slug', $request->category)->first();
$posts = $category->entries()->where('status',1)->orderBy('publication_date', 'asc')->paginate(15);
} elseif (isset($request->tags)) {
$tags = explode(",", $request->tags);
$posts = Entry::where('status',1)->where(function ($query) use($tags) {
for ($i = 0; $i < count($tags); $i++){
$query->orwhere('tags', 'like', '%' . $tags[$i] .'%');
}
})->orderBy('publication_date', 'asc')->paginate(15);
} else {
$posts = Entry::where('status',1)->orderBy('publication_date', 'asc')->paginate(3);
}
$otros = Entry::where('status',1)->inRandomOrder()->take(3)->get();
$categories = Category::where('active', 1)->get();
return view('blog::post.list')
->with('categories', $categories)
->with('otros', $otros)
->with('posts', $posts);
}
public function show($slug)
{
$post = Entry::where('slug',$slug)->first();
$post->increment('views');
$tags = explode(",", $post->tags);
$otros = Entry::where('id', '!=', $post->id)->where('status',1)->where(function ($query) use($tags) {
for ($i = 0; $i < count($tags); $i++){
$query->orwhere('tags', 'like', '%' . $tags[$i] .'%');
}
})->take(3)->get();
$categories = Category::all();
if ($post != null) {
if ($post->status == 2) {
return redirect('inactivo');
}
} else {
return redirect('no_existe');
}
return view('blog::post.single')
->with('post', $post)
->with('categories', $categories)
->with('otros', $otros);
}
}
...@@ -15,5 +15,6 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){ ...@@ -15,5 +15,6 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
}); });
Route::group(['middleware' => ['web']], function(){ Route::group(['middleware' => ['web']], function(){
Route::get('blog/{slug}', 'Onestartup\Blog\Controller\AdminBlogController@getEntries')->name('show.blog'); Route::get('blog/{slug}', 'Onestartup\Blog\Controller\BlogController@show')->name('show.blog');
Route::get('blog', 'Onestartup\Blog\Controller\BlogController@index')->name('main.blog');
}); });
<!DOCTYPE html>
<html>
<head>
<title>
{{$post->title or "Titulo general"}}
</title>
@include('blog::post.metatags')
</head>
<body>
{{-- Aqui toda la estructura del blog--}}
@yield('content')
{{-- Aqui el footer --}}
</body>
</html>
\ No newline at end of file
@extends('blog::post.layout')
@section('content')
Listado de entradas
<p>
Categorias:
{{$categories}}
</p>
<p>
Entradas todas
{{$posts}}
</p>
<p>
Entradas al azar
{{$otros}}
</p>
<p>
Paginacion:
{!! $posts->links() !!}
</p>
@endsection
\ No newline at end of file
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
<meta charset='utf-8'>
<meta content='ie=edge' http-equiv='x-ua-compatible'>
<meta content='' name='description'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content="{{isset($post) ? strip_tags(substr($post->body, 0, 120), '') :'Descripcion general del blog'}}" name='description'>
<link href="{{isset($post) ? route('show.blog', $post->slug) : route('main.blog')}}" rel='canonical'>
<meta content='es_MX' property='og:locale'>
<meta content='website' property='og:type'>
<meta content="{{$post->title or 'Titulo general del blog'}}" property='og:title'>
<meta content="{{isset($post) ? strip_tags(substr($post->body, 0, 120), '') :'Descripcion general del blog'}}" property='og:description'>
<meta content="{{isset($post) ? route('show.blog', $post->slug) : route('main.blog')}}" property='og:url'>
<meta content='ODESSA' property='og:site_name'>
<meta content="{{isset($post) ? asset('storage').'/'.$post->cover : asset('assets/img/Odessa-Seguros-alta-2.png')}}" property='og:image'>
<meta content="{{isset($post) ? asset('storage').'/'.$post->cover : asset('assets/img/Odessa-Seguros-alta-2.png')}}" property='og:image:secure_url'>
<meta content='summary' name='twitter:card'>
<meta content="{{isset($post) ? strip_tags(substr($post->body, 0, 120), '') :'Descripcion general del blog'}}" name='twitter:description'>
<meta content="{{$post->title or 'titulo general del blog'}}" name='twitter:title'>
<meta content='@odessa_seguros' name='twitter:site'>
<meta content="{{isset($post) ? asset('storage').'/'.$post->cover : asset('assets/img/Odessa-Seguros-alta-2.png')}}" name='twitter:image'>
<meta content='@odessa_seguros' name='twitter:creator'>
@extends('blog::post.layout')
@section('content')
<h1>
Titulo: {{$post->title}}
</h1>
<p>Portada:</p>
<img width="150" src="{{asset('storage/'.$post->cover)}}">
<p>
Publicacion: {{$post->publication_date}}
</p>
<p>
Tags: {{$post->tags}}
</p>
<p>
Categoria: {{$post->category->name}}
</p>
<p>
Contenido: {!! $post->body !!}
</p>
<p>
Categorias: Listado de categorias:
</p>
<ul>
@foreach($categories as $category)
<li>
{{$category->name}}
</li>
@endforeach
</ul>
<p>
Listado de post relacionados con sus tags:
</p>
<ul>
@foreach($otros as $entry)
<li>
<img width="100" src="{{asset('storage/'.$entry->cover)}}">
<a href="{{route('show.blog', $entry->slug)}}">
{{$entry->title}}
</a>
</li>
@endforeach
</ul>
@endsection
\ No newline at end of file
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