added simple post list theme part

fixed some bugs
pull/49/head
A1Gard 4 months ago
parent 76212ee579
commit c25e17d6f5

@ -887,6 +887,13 @@ function success($data = null, $message = null, $meta = [], $og = [], $twitter =
]); ]);
} }
/**
* @param $errors
* @param $status
* @param $message
* @param $data
* @return \Illuminate\Http\JsonResponse
*/
function errors($errors, $status = 422, $message = null, $data = null) function errors($errors, $status = 422, $message = null, $data = null)
{ {
return response()->json([ return response()->json([
@ -896,3 +903,8 @@ function errors($errors, $status = 422, $message = null, $data = null)
"data" => $data, "data" => $data,
], $status); ], $status);
} }
function readable($text)
{
return ucfirst(trim(str_replace(['-','_'],' ',$text)));
}

@ -57,7 +57,7 @@ class PostController extends XController
$post->status = $request->input('status'); $post->status = $request->input('status');
$post->group_id = $request->input('group_id'); $post->group_id = $request->input('group_id');
$post->user_id = auth()->id(); $post->user_id = auth()->id();
$post->is_pinned = $request->has('is_pinned'); $post->is_pinned = $request->has('is_pin');
$post->icon = $request->input('icon'); $post->icon = $request->input('icon');
if ($post->hash == null) { if ($post->hash == null) {

@ -11,15 +11,20 @@ use Spatie\Tags\Tag;
class ClientController extends Controller class ClientController extends Controller
{ {
public $paginate = 10;
// //
public function welcome(){ public function welcome()
{
$area = 'index'; $area = 'index';
$title = config('app.name'); $title = config('app.name');
$subtitle = getSetting('subtitle'); $subtitle = getSetting('subtitle');
return view('client.welcome', compact('area', 'title', 'subtitle')); return view('client.welcome', compact('area', 'title', 'subtitle'));
} }
public function post(Post $post){ public function post(Post $post)
{
$area = 'post'; $area = 'post';
$title = $post->title; $title = $post->title;
$subtitle = $post->subtitle; $subtitle = $post->subtitle;
@ -27,14 +32,25 @@ class ClientController extends Controller
return view('client.post', compact('area', 'post', 'title', 'subtitle')); return view('client.post', compact('area', 'post', 'title', 'subtitle'));
} }
public function tag($slug){ public function posts()
{
$area = 'posts-list';
$title = __("Posts list");
$subtitle = '';
$posts = Post::where('status', 1)->orderByDesc('id')->paginate($this->paginate);
return view('client.posts', compact('area', 'posts', 'title', 'subtitle'));
}
public function tag($slug)
{
$tag = Tag::where('slug->' . config('app.locale'), 'like', $slug)->first(); $tag = Tag::where('slug->' . config('app.locale'), 'like', $slug)->first();
return $tag; return $tag;
} }
public function submitComment(Request $request){ public function submitComment(Request $request)
{
$request->validate([ $request->validate([
'commentable_type' => ['required', 'string', 'min:5'], 'commentable_type' => ['required', 'string', 'min:5'],
'commentable_id' => ['required', 'integer'], 'commentable_id' => ['required', 'integer'],
@ -73,7 +89,8 @@ class ClientController extends Controller
return redirect()->back()->with(['message' => __('Your comment has been submitted')]); return redirect()->back()->with(['message' => __('Your comment has been submitted')]);
} }
public function search(Request $request){ public function search(Request $request)
{
} }
} }

@ -25,8 +25,8 @@ class PostSaveRequest extends FormRequest
'title' => ['required', 'string', 'max:255', 'min:2'], 'title' => ['required', 'string', 'max:255', 'min:2'],
'subtitle' => ['nullable', 'string', 'max:2048'], 'subtitle' => ['nullable', 'string', 'max:2048'],
'body' => ['required', 'string', 'min:5'], 'body' => ['required', 'string', 'min:5'],
'status' => ['required', 'boolean'], 'status' => ['required'],
'is_pin' => ['nullable', 'boolean'], 'is_pin' => ['nullable'],
'image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'], 'image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
'icon' => ['nullable', 'string', 'min:3'], 'icon' => ['nullable', 'string', 'min:3'],
'group_id' => ['required', 'exists:groups,id'], 'group_id' => ['required', 'exists:groups,id'],

@ -102,7 +102,7 @@ class Post extends Model implements HasMedia
} }
public function mainGroup(){ public function mainGroup(){
return $this->belongsTo(Group::class); return $this->belongsTo(Group::class,'group_id');
} }
public function attachs(){ public function attachs(){

@ -1,3 +1,4 @@
@extends('layouts.app') @extends('layouts.app')
@section('title') @section('title')
@ -9,7 +10,7 @@
<div class="col-md-4"> <div class="col-md-4">
<a class="area-list-item" href="{{route('admin.area.design',$area->name)}}"> <a class="area-list-item" href="{{route('admin.area.design',$area->name)}}">
<i class="{{$area->icon}}"></i> <i class="{{$area->icon}}"></i>
{{__(ucfirst($area->name))}} {{__(readable($area->name))}}
</a> </a>
</div> </div>
@endforeach @endforeach

@ -175,9 +175,8 @@
</div> </div>
<div class="col-md-3 mt-3 pt-2"> <div class="col-md-3 mt-3 pt-2">
<div class="form-group mt-4"> <div class="form-group mt-4">
<div class="form-check form-switch"> <div class="form-check form-switch">
<input class="form-check-input" name="is_pin" @if (old('is_pin',$item->is_pin??0) != 0) <input class="form-check-input" name="is_pin" @if (old('is_pin',$item->is_pinned??0) != 0)
checked checked
@endif type="checkbox" id="ispin"> @endif type="checkbox" id="ispin">
<label class="form-check-label" for="ispin">{{__('Pin')}}</label> <label class="form-check-label" for="ispin">{{__('Pin')}}</label>

@ -0,0 +1,13 @@
@extends('website.inc.website-layout')
@section('title')
{{$title}} - {{config('app.name')}}
@endsection
@section('content')
<main>
@foreach(getParts($area) as $part)
@php($p = $part->getBladeWithData())
@include($p['blade'],['data' => $p['data']])
@endforeach
</main>
@endsection

@ -0,0 +1,47 @@
<section class='SimplePostList'>
<div class="{{gfx()['container']}}">
<div class="row pinned-posts">
@foreach(\App\Models\Post::where('status',1)->where('is_pinned',1)->limit(2)->get() as $post)
<div class="col-md-6 p-1">
<div class="post-item">
<div class="corner">
{{$post->mainGroup->name}}
</div>
<a href="{{$post->webUrl()}}">
<img src="{{$post->orgUrl()}}" alt="{{$post->title}}"
title="{{implode(',',$post->tags->pluck('name')->toArray()??'')}}">
</a>
<div class="detail">
<h4>
{{$post->title}}
</h4>
<span>
{{$post->created_at->ldate('Y/m/d l')}}
</span>
</div>
</div>
</div>
@endforeach
</div>
<hr>
@foreach($posts as $post)
<div class="post-list-item">
<img src="{{$post->imgUrl()}}" class="float-start me-4" alt="{{$post->title}}">
<h4>
{{$post->title}}
</h4>
<div class="text-muted py-2">
{{$post->created_at->ldate('Y/m/d l')}}
</div>
<p>
{{$post->subtitle}}
<br>
<a href="{{$post->webUrl()}}" class="btn btn-outline-primary my-2 btn-sm">
{{__("Read more")}}
</a>
</p>
</div>
@endforeach
{{$posts->links()}}
</div>
</section>

@ -0,0 +1,10 @@
{
"name": "SimplePostList",
"version": "1.0",
"author": "xStack",
"email": "xshop@xstack.ir",
"license": "GPL-3.0-or-later",
"url": "https:\/\/xstack.ir",
"author_url": "https:\/\/4xmen.ir",
"packages": []
}

@ -0,0 +1,21 @@
<?php
namespace Resources\Views\Segments;
use App\Models\Part;
class SimplePostList
{
public static function onAdd(Part $part = null)
{
}
public static function onRemove(Part $part = null)
{
}
public static function onMount(Part $part = null)
{
return $part;
}
}

@ -0,0 +1,71 @@
.SimplePostList {
// scss
.pinned-posts{
padding: 2rem 0;
//column-gap: 2px;
//row-gap: 2px;
.post-item{
position: relative;
height: 350px;
border-radius: var(--xshop-border-radius) ;
overflow: hidden;
background: #333;
img{
border-radius: var(--xshop-border-radius) ;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
object-fit: cover;
transition: 400ms;
opacity: .7;
}
.detail{
position: absolute;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
padding: 1rem;
color: white;
span{
opacity: .5;
}
}
.corner{
border-radius: var(--xshop-border-radius) ;
position: absolute;
inset-inline-start: 0;
top: 0;
background: var(--xshop-primary);
color: var(--xshop-diff);
z-index: 2;
padding: 4px 1rem;
font-size: 17px;
}
&:hover{
img{
transform: scale(1.6);
}
}
}
}
.post-list-item{
border-bottom: #44444433 1px solid;
margin-bottom: 1rem;
min-height: 200px;
img{
height: 175px;
border-radius: var(--xshop-border-radius);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

@ -357,9 +357,10 @@ Route::get('theme/variable.css',[\App\Http\Controllers\ThemeController::class,'c
Route::name('client.')->group(function (){ Route::name('client.')->group(function (){
// index // index
Route::get('/', [\App\Http\Controllers\ClientController::class,'welcome'])->name('welcome'); Route::get('/', [\App\Http\Controllers\ClientController::class,'welcome'])->name('welcome');
Route::get('/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post'); Route::get('/posts', [\App\Http\Controllers\ClientController::class,'posts'])->name('posts');
Route::get('/tag/{post}', [\App\Http\Controllers\ClientController::class,'tag'])->name('tag'); Route::get('/tag/{post}', [\App\Http\Controllers\ClientController::class,'tag'])->name('tag');
Route::get('/search', [\App\Http\Controllers\ClientController::class,'search'])->name('search'); Route::get('/search', [\App\Http\Controllers\ClientController::class,'search'])->name('search');
Route::get('/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post');
Route::post('/comment/submit', [\App\Http\Controllers\ClientController::class,'submitComment'])->name('comment.submit'); Route::post('/comment/submit', [\App\Http\Controllers\ClientController::class,'submitComment'])->name('comment.submit');

Loading…
Cancel
Save