modified starterkit models

added helper
pull/44/head
A1Gard 8 months ago
parent ade533da84
commit 5bdd998c54

@ -60,6 +60,10 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
MEDIA_GALLEY_THUMB=500x500
MEDIA_POST_THUMB=500x500
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1

@ -0,0 +1,86 @@
<?php
namespace App\Helpers;
/**
* @param $lang code like fa
* @return string
*/
function getEmojiLanguagebyCode($lang) {
$languages = array(
"af" => "🇿🇦", // Afrikaans
"sq" => "🇦🇱", // Albanian
"am" => "🇪🇹", // Amharic
"ar" => "🇸🇦", // Arabic
"hy" => "🇦🇲", // Armenian
"az" => "🇦🇿", // Azerbaijani
"eu" => "🇪🇸", // Basque
"be" => "🇧🇾", // Belarusian
"bn" => "🇧🇩", // Bengali
"bs" => "🇧🇦", // Bosnian
"bg" => "🇧🇬", // Bulgarian
"ca" => "🇪🇸", // Catalan
"zh" => "🇨🇳", // Chinese
"hr" => "🇭🇷", // Croatian
"cs" => "🇨🇿", // Czech
"da" => "🇩🇰", // Danish
"nl" => "🇳🇱", // Dutch
"en" => "🇺🇸", // English
"et" => "🇪🇪", // Estonian
"fi" => "🇫🇮", // Finnish
"fr" => "🇫🇷", // French
"gl" => "🇪🇸", // Galician
"ka" => "🇬🇪", // Georgian
"de" => "🇩🇪", // German
"el" => "🇬🇷", // Greek
"gu" => "🇮🇳", // Gujarati
"ht" => "🇭🇹", // Haitian
"he" => "🇮🇱", // Hebrew
"hi" => "🇮🇳", // Hindi
"hu" => "🇭🇺", // Hungarian
"is" => "🇮🇸", // Icelandic
"id" => "🇮🇩", // Indonesian
"ga" => "🇮🇪", // Irish
"it" => "🇮🇹", // Italian
"ja" => "🇯🇵", // Japanese
"kk" => "🇰🇿", // Kazakh
"ko" => "🇰🇷", // Korean
"lv" => "🇱🇻", // Latvian
"lt" => "🇱🇹", // Lithuanian
"mk" => "🇲🇰", // Macedonian
"ms" => "🇲🇾", // Malay
"ml" => "🇮🇳", // Malayalam
"mt" => "🇲🇹", // Maltese
"mn" => "🇲🇳", // Mongolian
"no" => "🇳🇴", // Norwegian
"ps" => "🇦🇫", // Pashto
"fa" => "🇮🇷", // Persian
"pl" => "🇵🇱", // Polish
"pt" => "🇵🇹", // Portuguese
"ro" => "🇷🇴", // Romanian
"ru" => "🇷🇺", // Russian
"sr" => "🇷🇸", // Serbian
"sk" => "🇸🇰", // Slovak
"sl" => "🇸🇮", // Slovenian
"es" => "🇪🇸", // Spanish
"sw" => "🇰🇪", // Swahili
"sv" => "🇸🇪", // Swedish
"ta" => "🇮🇳", // Tamil
"te" => "🇮🇳", // Telugu
"th" => "🇹🇭", // Thai
"tr" => "🇹🇷", // Turkish
"uk" => "🇺🇦", // Ukrainian
"ur" => "🇵🇰", // Urdu
"uz" => "🇺🇿", // Uzbek
"vi" => "🇻🇳", // Vietnamese
"cy" => "🇬🇧" // Welsh
);
$lang = strtolower($lang);
if (array_key_exists($lang, $languages)) {
return $languages[$lang];
} else {
return "❓";
}
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class Acl
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
return $next($request);
}
}

@ -2,10 +2,13 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AdminLog extends Model
{
use HasFactory;
public function user()
{
return $this->belongsTo(User::class);
}
}

@ -2,10 +2,19 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Adv extends Model
{
use HasFactory;
use SoftDeletes;
public function imgUrl()
{
if ($this->image == null) {
return null;
}
return \Storage::url('advs/' . $this->image);
}
}

@ -4,8 +4,40 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Translatable\HasTranslations;
class Clip extends Model
{
use HasFactory;
use HasFactory, SoftDeletes, HasTranslations;
public $translatable = ['title','body'];
public function getRouteKeyName()
{
return 'slug';
}
public function coverUrl()
{
if ($this->cover == null) {
return null;
}
return \Storage::url('clips/' . $this->cover);
}
public function fileUrl()
{
if ($this->file == null) {
return null;
}
return \Storage::url('clips/' . $this->file);
}
public function author()
{
return $this->belongsTo(\App\Models\User::class);
}
}

@ -8,4 +8,19 @@ use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
use HasFactory;
public function commentable()
{
return $this->morphTo();
}
public function children()
{
return $this->hasMany(Comment::class, 'sub_comment_id');
}
public function approved_children()
{
return $this->hasMany(Comment::class, 'sub_comment_id')->where('status', 1);
}
}

@ -4,8 +4,58 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\Conversions\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\Translatable\HasTranslations;
class Gallery extends Model
class Gallery extends Model implements HasMedia
{
use HasFactory;
use HasFactory,InteractsWithMedia,HasTranslations;
public $translatable = ['title','description'];
public function images()
{
return $this->hasMany(Images::class, 'gallery_id', 'id')->orderBy('sort')->orderByDesc('id');
}
public function registerMediaConversions(Media $media = null): void
{
$this->addMediaConversion('gallery-image')->optimize();
$t = explode('x',config('app.media.gallery_thumb'));
if (config('starter-kit.gallery_thumb') == null || config('starter-kit.gallery_thumb') == ''){
$t[0] = 500 ;
$t[1] = 500 ;
}
$this->addMediaConversion('gthumb')->width($t[0])
->height($t[1])
->crop(Manipulations::CROP_CENTER, $t[0], $t[1])->optimize();
// ->watermark(public_path('images/logo.png'))->watermarkOpacity(50);
// ->withResponsiveImages();
}
public function getRouteKeyName()
{
return 'slug';
}
public function imgurl()
{
if ($this->getMedia()->count() > 0) {
return $this->getMedia()->first()->getUrl('gthumb');
} else {
return "no image";
}
}
public function author()
{
return $this->belongsTo(\App\Models\User::class);
}
}

@ -4,8 +4,39 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Translatable\HasTranslations;
use Xmen\StarterKit\Models\Category;
use Xmen\StarterKit\Models\Post;
class Group extends Model
{
use HasFactory;
use HasFactory, SoftDeletes,HasTranslations;
public $translatable = ['name','description'];
public function posts()
{
return $this->belongsToMany(Post::class);
}
//
public function parent()
{
return $this->belongsTo(Category::class, 'parent_id');
}
public function children()
{
return $this->hasMany(Category::class, 'parent_id');
}
public function getRouteKeyName()
{
return 'slug';
}
public function author()
{
return $this->belongsTo(\App\Models\User::class);
}
}

@ -4,8 +4,46 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\Translatable\HasTranslations;
class Images extends Model
class Images extends Model implements HasMedia
{
use HasFactory;
use HasFactory,InteractsWithMedia, HasTranslations;
public $translatable = ['title'];
public function gallery()
{
return $this->belongsTo(Gallery::class, 'gallery_id');
}
public function registerMediaConversions(Media $media = null): void
{
$t = explode('x', config('starter-kit.post_thumb'));
if (config('starter-kit.gallery_thumb') == null || config('starter-kit.gallery_thumb') == '') {
$t[0] = 500;
$t[1] = 500;
}
$this->addMediaConversion('image-image')->optimize();
$this->addMediaConversion('gthumb')->width($t[0])
->height($t[1])
->crop(Manipulations::CROP_CENTER, $t[0], $t[1])->optimize();
// ->watermark(public_path('images/logo.png'))->watermarkOpacity(50);
// ->withResponsiveImages();
}
public function imgurl()
{
if ($this->getMedia()->count() > 0) {
return $this->getMedia()->first()->getUrl('gthumb');
} else {
return "no image";
}
}
}

@ -4,8 +4,14 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Menu extends Model
{
use HasFactory;
use HasFactory,SoftDeletes;
public function menuItems()
{
return $this->hasMany(MenuItem::class, 'menu_id', 'id');
};
}

@ -4,8 +4,26 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class MenuItem extends Model
{
use HasFactory;
use HasFactory,HasTranslations;
public $translatable = ['title'];
public function menu()
{
return $this->belongsTo(Menu::class, 'menu_id', 'id');
}
public function parent()
{
return $this->belongsTo(MenuItem::class, 'parent');
}
public function children()
{
return $this->hasMany(MenuItem::class, 'parent');
}
}

@ -4,8 +4,101 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\Translatable\HasTranslations;
class Post extends Model
class Post extends Model implements HasMedia
{
use HasFactory;
use HasFactory,SoftDeletes, InteractsWithMedia,HasTranslations;
public $translatable = ['title','subtitle','body'];
public function categories()
{
return $this->belongsToMany(Category::class);
}
public function author()
{
return $this->belongsTo(\App\Models\User::class);
}
public function getRouteKeyName()
{
return 'slug';
}
public function registerMediaConversions(Media $media = null): void
{
$t = explode('x',config('app.media.post_thumb'));
if (config('app.media.post_thumb') == null || config('app.media.post_thumb') == ''){
$t[0] = 500 ;
$t[1] = 500 ;
}
$this->addMediaConversion('posts-image')
->width($t[0])
->height($t[1])
->crop(Manipulations::CROP_CENTER, $t[0], $t[1])
->optimize()
->sharpen(10);
}
public function imgurl()
{
if ($this->getMedia()->count() > 0) {
return $this->getMedia()->first()->getUrl('posts-image');
} else {
return "no image";
}
}
public function orgurl()
{
if ($this->getMedia()->count() > 0) {
return $this->getMedia()[$this->image_index]->getUrl();
} else {
return asset('/images/logo.png');
}
}
public function spendTime()
{
$word = strlen(strip_tags($this->body));
$m = ceil($word / 1350);
return $m . ' ' . __('minute');
}
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
public function approved_comments()
{
return $this->morphMany(Comment::class, 'commentable')->where('status', 1);
}
public function toArray()
{
return [
'id' => $this->id,
'title' => $this->title,
'subtitle' => $this->subtitle,
'body' => $this->body,
'categories' => $this->categories->implode(' ') ?? null,
'author' => $this->author->name ?? null,
'tags' => $this->tags->implode(' ') ?? null,
];
}
}

@ -4,8 +4,24 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class Slider extends Model
{
use HasFactory;
use HasFactory,HasTranslations;
public $translatable = ['body'];
public function imgUrl()
{
if ($this->image == null) {
return null;
}
return \Storage::url('sliders/' . $this->image);
}
public function author()
{
return $this->belongsTo(User::class);
}
}

@ -2,6 +2,10 @@
namespace App\Providers;
use App\Helpers\TDate;
use App\Http\Middleware\Acl;
use Carbon\Carbon;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@ -19,6 +23,14 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot(): void
{
//
/** @var Router $router */
$router = $this->app['router'];
$router->pushMiddlewareToGroup('web', Acl::class);
Paginator::useBootstrap();
Carbon::macro('jdate', function ($format, $tr_num = 'fa') {
$dt = TDate::GetInstance();
return $dt->PDate($format, self::this()->timestamp);
});
}
}

@ -34,6 +34,10 @@
"spatie/laravel-ignition": "^2.4"
},
"autoload": {
"files": [
"app/Helpers/Helper.php",
"app/Helpers/TDate.php"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",

@ -135,6 +135,17 @@ return [
'prefix' => env('PANEL_PREFIX','dashboard'),
'page_count' => env('PANEL_PAGE_COUNT',30),
],
/*
|--------------------------------------------------------------------------
| Media
|--------------------------------------------------------------------------
| These configuration options of medias
*/
'media' => [
'gallery_thumb' => env('MEDIA_GALLEY_THUMB','500x500'),
'post_thumb' => env('MEDIA_POST_THUMB','500x500'),
],
];

@ -1,23 +0,0 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Adv>
*/
class AdvFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

@ -1,23 +0,0 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Credit>
*/
class CreditFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}
Loading…
Cancel
Save