Add (post manage)
Add (post country viewing)
This commit is contained in:
@@ -46,18 +46,16 @@ function get_country_name_by_iso($country_iso)
|
||||
$country_iso = strtoupper($country_iso);
|
||||
|
||||
try {
|
||||
return config("platform.country_codes.{$country_iso}")['name'];
|
||||
return config("platform.country_codes.{$country_iso}")['name'];
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
catch (\Exception $e) {}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 'International';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (! function_exists('get_country_emoji_by_iso')) {
|
||||
function get_country_emoji_by_iso($country_iso)
|
||||
{
|
||||
@@ -66,11 +64,10 @@ function get_country_emoji_by_iso($country_iso)
|
||||
$country_iso = strtoupper($country_iso);
|
||||
|
||||
try {
|
||||
return config("platform.country_codes.{$country_iso}")['emoji'];
|
||||
return config("platform.country_codes.{$country_iso}")['emoji'];
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
catch (\Exception $e) {}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return '🌎';
|
||||
@@ -82,4 +79,4 @@ function str_random($length = 10)
|
||||
{
|
||||
return Str::random($length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public function __construct()
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('admin.home');
|
||||
return redirect()->route('posts.manage');
|
||||
//return view('admin.home');
|
||||
}
|
||||
}
|
||||
|
||||
27
app/Http/Controllers/Admin/PostController.php
Normal file
27
app/Http/Controllers/Admin/PostController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Post;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PostController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$posts = Post::with('post_categories.category.country_locale')->orderBy('created_at', 'desc')->paginate();
|
||||
|
||||
return view('admin.posts.manage', compact('posts'));
|
||||
}
|
||||
|
||||
public function new(Request $request)
|
||||
{
|
||||
return 'PostController@new';
|
||||
}
|
||||
|
||||
public function edit(Request $request, $post_id)
|
||||
{
|
||||
return 'PostController@edit : '.$post_id;
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,6 @@
|
||||
use App\Models\Post;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Stevebauman\Location\Facades\Location;
|
||||
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
@@ -25,37 +22,35 @@ public function country(Request $request, $country)
|
||||
$country_locale = CountryLocale::where('slug', $country)->first();
|
||||
|
||||
if (! is_null($country_locale)) {
|
||||
|
||||
|
||||
$request->session()->put('view_country_locale', $country_locale);
|
||||
|
||||
$featured_posts = Post::select('posts.*')
|
||||
->join('post_categories','posts.id','=', 'post_categories.post_id')
|
||||
->join('categories','post_categories.category_id','=', 'categories.id')
|
||||
->whereNotNull('post_categories.id')
|
||||
->whereNotNull('categories.id')
|
||||
->where('categories.country_locale_slug', $country_locale->slug)
|
||||
->where('posts.featured', true)
|
||||
->where('posts.status', 'publish')
|
||||
->orderBy('posts.updated_at', 'desc')
|
||||
->take(3)
|
||||
->get();
|
||||
->join('post_categories', 'posts.id', '=', 'post_categories.post_id')
|
||||
->join('categories', 'post_categories.category_id', '=', 'categories.id')
|
||||
->whereNotNull('post_categories.id')
|
||||
->whereNotNull('categories.id')
|
||||
->where('categories.country_locale_slug', $country_locale->slug)
|
||||
->where('posts.featured', true)
|
||||
->where('posts.status', 'publish')
|
||||
->orderBy('posts.updated_at', 'desc')
|
||||
->take(3)
|
||||
->get();
|
||||
|
||||
|
||||
$latest_posts = Post::select('posts.*')
|
||||
->join('post_categories','posts.id','=', 'post_categories.post_id')
|
||||
->join('categories','post_categories.category_id','=', 'categories.id')
|
||||
->whereNotNull('post_categories.id')
|
||||
->whereNotNull('categories.id')
|
||||
->where('categories.country_locale_slug', $country_locale->slug)
|
||||
->where('posts.featured', true)
|
||||
->whereNotIn('posts.id', $featured_posts->pluck('id')->toArray())
|
||||
->where('posts.status', 'publish')
|
||||
->orderBy('posts.updated_at', 'desc')
|
||||
->distinct()
|
||||
->take(20)
|
||||
->get();
|
||||
->join('post_categories', 'posts.id', '=', 'post_categories.post_id')
|
||||
->join('categories', 'post_categories.category_id', '=', 'categories.id')
|
||||
->whereNotNull('post_categories.id')
|
||||
->whereNotNull('categories.id')
|
||||
->where('categories.country_locale_slug', $country_locale->slug)
|
||||
->whereNotIn('posts.id', $featured_posts->pluck('id')->toArray())
|
||||
->where('posts.status', 'publish')
|
||||
->orderBy('posts.updated_at', 'desc')
|
||||
->distinct()
|
||||
->take(10)
|
||||
->get();
|
||||
|
||||
return view('front.country', compact('country_locale','featured_posts','latest_posts')
|
||||
return view('front.country', compact('country_locale', 'featured_posts', 'latest_posts')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,32 +62,57 @@ public function countryCategory(Request $request, $country, $category)
|
||||
$country_locale = CountryLocale::where('slug', $country)->first();
|
||||
|
||||
if (is_null($country_locale)) {
|
||||
abort(404);
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$category = Category::where('slug', $category)->where('enabled', true)->first();
|
||||
$category = Category::where('slug', $category)->where('enabled', true)->first();
|
||||
|
||||
if (is_null($category))
|
||||
{
|
||||
abort(404);
|
||||
}
|
||||
return view('front.country_category', ['country_locale' => $country_locale, 'category' => $category]);
|
||||
if (is_null($category)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$latest_posts = Post::with('post_categories')->select('posts.*')
|
||||
->join('post_categories', 'posts.id', '=', 'post_categories.post_id')
|
||||
->join('categories', 'post_categories.category_id', '=', 'categories.id')
|
||||
->whereNotNull('post_categories.id')
|
||||
->whereNotNull('categories.id')
|
||||
->where('categories.country_locale_slug', $country_locale->slug)
|
||||
->where('categories.id', $category->id)
|
||||
->where('posts.status', 'publish')
|
||||
->orderBy('posts.updated_at', 'desc')
|
||||
->distinct()
|
||||
->paginate(15);
|
||||
|
||||
return view('front.country_category', compact('country_locale', 'category', 'latest_posts'));
|
||||
}
|
||||
|
||||
public function all(Request $request, $country)
|
||||
{
|
||||
$country_locale = CountryLocale::where('slug', $country)->first();
|
||||
$country_locale = CountryLocale::where('slug', $country)->first();
|
||||
|
||||
return view('front.country_all', ['country_locale' => $country_locale]);
|
||||
$latest_posts = Post::with('post_categories')->select('posts.*')
|
||||
->join('post_categories', 'posts.id', '=', 'post_categories.post_id')
|
||||
->join('categories', 'post_categories.category_id', '=', 'categories.id')
|
||||
->whereNotNull('post_categories.id')
|
||||
->whereNotNull('categories.id')
|
||||
->where('categories.country_locale_slug', $country_locale->slug)
|
||||
->where('posts.status', 'publish')
|
||||
->orderBy('posts.updated_at', 'desc')
|
||||
->distinct()
|
||||
->paginate(15);
|
||||
|
||||
return view('front.country_all', compact('country_locale', 'latest_posts'));
|
||||
}
|
||||
|
||||
public function posts(Request $request, $country)
|
||||
public function post(Request $request, $country, $post_slug)
|
||||
{
|
||||
return "{$country} : all posts";
|
||||
}
|
||||
$post = Post::where('slug', $post_slug)->where('status', 'publish')->first();
|
||||
|
||||
if (! is_null($post)) {
|
||||
|
||||
return view('front.post', compact('post'));
|
||||
}
|
||||
abort(404);
|
||||
|
||||
public function post(Request $request, $country, $post)
|
||||
{
|
||||
return "{$country} : {$post}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
use Stevebauman\Location\Facades\Location;
|
||||
|
||||
use Galahad\TimezoneMapper\Facades\TimezoneMapper;
|
||||
use Stevebauman\Location\Facades\Location;
|
||||
|
||||
class StoreGeoSession
|
||||
{
|
||||
@@ -14,7 +12,6 @@ class StoreGeoSession
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
@@ -34,28 +31,23 @@ public function handle($request, Closure $next)
|
||||
$needs_update = true;
|
||||
}
|
||||
|
||||
if (!$request->session()->has('timezone')) {
|
||||
$needs_update = true;
|
||||
if (! $request->session()->has('timezone')) {
|
||||
$needs_update = true;
|
||||
}
|
||||
|
||||
if ($needs_update)
|
||||
{
|
||||
if ($needs_update) {
|
||||
|
||||
if ($payload = Location::get($ip))
|
||||
{
|
||||
$request->session()->put('geodata', base64_encode(json_encode($payload)));
|
||||
$isocode = $payload->isoCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
$isocode = '*';
|
||||
if ($payload = Location::get($ip)) {
|
||||
$request->session()->put('geodata', base64_encode(json_encode($payload)));
|
||||
$isocode = $payload->isoCode;
|
||||
} else {
|
||||
$isocode = '*';
|
||||
}
|
||||
|
||||
$request->session()->put('country', $isocode);
|
||||
$request->session()->put('country', $isocode);
|
||||
|
||||
if (isset($payload->latitude) && isset($payload->longitude))
|
||||
{
|
||||
$request->session()->put('timezone', TimezoneMapper::mapCoordinates($payload->latitude, $payload->longitude));
|
||||
if (isset($payload->latitude) && isset($payload->longitude)) {
|
||||
$request->session()->put('timezone', TimezoneMapper::mapCoordinates($payload->latitude, $payload->longitude));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/**
|
||||
* Class Author
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $avatar
|
||||
@@ -21,30 +21,27 @@
|
||||
* @property bool $public
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property Collection|Post[] $posts
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Author extends Model
|
||||
{
|
||||
protected $table = 'authors';
|
||||
protected $table = 'authors';
|
||||
|
||||
protected $casts = [
|
||||
'enabled' => 'bool',
|
||||
'public' => 'bool'
|
||||
];
|
||||
protected $casts = [
|
||||
'enabled' => 'bool',
|
||||
'public' => 'bool',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'avatar',
|
||||
'bio',
|
||||
'enabled',
|
||||
'public'
|
||||
];
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'avatar',
|
||||
'bio',
|
||||
'enabled',
|
||||
'public',
|
||||
];
|
||||
|
||||
public function posts()
|
||||
{
|
||||
return $this->hasMany(Post::class);
|
||||
}
|
||||
public function posts()
|
||||
{
|
||||
return $this->hasMany(Post::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
|
||||
/**
|
||||
* Class Category
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
|
||||
/**
|
||||
* Class CountryLocale
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use AlAminFirdows\LaravelEditorJs\Facades\LaravelEditorJs;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Post
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $title
|
||||
* @property string|null $slug
|
||||
@@ -27,44 +28,60 @@
|
||||
* @property string $status
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property Author|null $author
|
||||
* @property Collection|PostCategory[] $post_categories
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Post extends Model
|
||||
{
|
||||
protected $table = 'posts';
|
||||
protected $table = 'posts';
|
||||
|
||||
protected $casts = [
|
||||
'author_id' => 'int',
|
||||
'body' => 'json',
|
||||
'comment_count' => 'int',
|
||||
'likes_count' => 'int'
|
||||
];
|
||||
protected $casts = [
|
||||
'author_id' => 'int',
|
||||
'body' => 'json',
|
||||
'comment_count' => 'int',
|
||||
'likes_count' => 'int',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'slug',
|
||||
'excerpt',
|
||||
'author_id',
|
||||
'featured_image',
|
||||
'editor',
|
||||
'body',
|
||||
'post_format',
|
||||
'comment_count',
|
||||
'likes_count',
|
||||
'status'
|
||||
];
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'slug',
|
||||
'excerpt',
|
||||
'author_id',
|
||||
'featured_image',
|
||||
'editor',
|
||||
'body',
|
||||
'post_format',
|
||||
'comment_count',
|
||||
'likes_count',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(Author::class);
|
||||
}
|
||||
protected $appends = [
|
||||
'html_body',
|
||||
];
|
||||
|
||||
public function post_categories()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class);
|
||||
}
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(Author::class);
|
||||
}
|
||||
|
||||
public function post_categories()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class);
|
||||
}
|
||||
|
||||
public function post_category()
|
||||
{
|
||||
return $this->hasOne(PostCategory::class);
|
||||
}
|
||||
|
||||
public function getHtmlBodyAttribute()
|
||||
{
|
||||
if (! is_empty($this->body)) {
|
||||
return LaravelEditorJs::render($this->body);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,39 +11,36 @@
|
||||
|
||||
/**
|
||||
* Class PostCategory
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $post_id
|
||||
* @property int $category_id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property Category $category
|
||||
* @property Post $post
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class PostCategory extends Model
|
||||
{
|
||||
protected $table = 'post_categories';
|
||||
protected $table = 'post_categories';
|
||||
|
||||
protected $casts = [
|
||||
'post_id' => 'int',
|
||||
'category_id' => 'int'
|
||||
];
|
||||
protected $casts = [
|
||||
'post_id' => 'int',
|
||||
'category_id' => 'int',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'post_id',
|
||||
'category_id'
|
||||
];
|
||||
protected $fillable = [
|
||||
'post_id',
|
||||
'category_id',
|
||||
];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function post()
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
public function post()
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ public function register()
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Paginator::useBootstrap();
|
||||
Paginator::useBootstrapFive();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
use App\View\Composers\CategoryComposer;
|
||||
use App\View\Composers\CountryLocaleComposer;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
@@ -35,12 +33,9 @@ public function boot()
|
||||
View::composer('layouts.front.footer', CategoryComposer::class);
|
||||
View::composer('layouts.front.footer', CountryLocaleComposer::class);
|
||||
|
||||
if (auth()->check())
|
||||
{
|
||||
if (auth()->check()) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
use Illuminate\Support\Str;
|
||||
use PharData;
|
||||
use PharFileInfo;
|
||||
use Stevebauman\Location\Position;
|
||||
use Stevebauman\Location\Request;
|
||||
use Stevebauman\Location\Drivers\Driver;
|
||||
use Stevebauman\Location\Drivers\Updatable;
|
||||
use Stevebauman\Location\Position;
|
||||
use Stevebauman\Location\Request;
|
||||
|
||||
class MaxMindDriver extends Driver implements Updatable
|
||||
{
|
||||
|
||||
@@ -2,25 +2,23 @@
|
||||
|
||||
namespace App\View\Composers;
|
||||
|
||||
use App\Models\CountryLocale;
|
||||
use App\Models\Category;
|
||||
|
||||
use App\Models\CountryLocale;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CategoryComposer
|
||||
{
|
||||
public function compose(View $view)
|
||||
{
|
||||
$current_country_locale = request()->session()->get('view_country_locale');
|
||||
$current_country_locale = request()->session()->get('view_country_locale');
|
||||
|
||||
if (is_null($current_country_locale))
|
||||
{
|
||||
$current_country_locale = CountryLocale::where('slug', config('platform.general.fallback_country_slug'))->first();
|
||||
}
|
||||
if (is_null($current_country_locale)) {
|
||||
$current_country_locale = CountryLocale::where('slug', config('platform.general.fallback_country_slug'))->first();
|
||||
}
|
||||
|
||||
$categories = Category::where('country_locale_id', $current_country_locale->id)->get();
|
||||
$categories = Category::where('country_locale_id', $current_country_locale->id)->get();
|
||||
|
||||
$view->with('categories', $categories);
|
||||
$view->with('categories', $categories);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,23 @@
|
||||
namespace App\View\Composers;
|
||||
|
||||
use App\Models\CountryLocale;
|
||||
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CountryLocaleComposer
|
||||
{
|
||||
public function compose(View $view)
|
||||
{
|
||||
$country_locales = CountryLocale::all();
|
||||
$country_locales = CountryLocale::all();
|
||||
|
||||
$current_country_locale = null;
|
||||
$current_country_locale = null;
|
||||
|
||||
if (!is_null(request()->session()->get('view_country_locale')))
|
||||
{
|
||||
$current_country_locale = request()->session()->get('view_country_locale');
|
||||
}
|
||||
else
|
||||
{
|
||||
$current_country_locale = CountryLocale::where('slug', config('platform.general.fallback_country_slug'))->first();
|
||||
}
|
||||
if (! is_null(request()->session()->get('view_country_locale'))) {
|
||||
$current_country_locale = request()->session()->get('view_country_locale');
|
||||
} else {
|
||||
$current_country_locale = CountryLocale::where('slug', config('platform.general.fallback_country_slug'))->first();
|
||||
}
|
||||
|
||||
$view->with('country_locales', $country_locales)
|
||||
$view->with('country_locales', $country_locales)
|
||||
->with('current_country_locale', $current_country_locale);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user