feat: ✨ add CRUD News
This commit is contained in:
parent
0991a3941c
commit
a82dcf4204
35 changed files with 1720 additions and 4 deletions
202
app/Http/Controllers/Bo/NewsController.php
Normal file
202
app/Http/Controllers/Bo/NewsController.php
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\News\StoreNewsRequest;
|
||||
use App\Http\Requests\Bo\News\UpdateNewsRequest;
|
||||
use App\Models\News;
|
||||
use App\Models\NewsCategory;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
use ChangesModelOrder;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(News::class);
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $newsModels */
|
||||
$newsModels = News::query()->with('newsCategory');
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$newsModels,
|
||||
$search,
|
||||
null,
|
||||
'title',
|
||||
'content',
|
||||
'news_category_id'
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
trans('validation.attributes.title'),
|
||||
trans('validation.attributes.content'),
|
||||
trans('validation.custom.category'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($newsModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$newsModels = $this->paginate($newsModels);
|
||||
|
||||
return view('bo.pages.news.index', compact('newsModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$newsCategoryModels = NewsCategory::query()->where('published', true)->orderBy('order')->get();
|
||||
return view('bo.pages.news.create', ['newsModel' => $news, 'newsCategoryModels' => $newsCategoryModels]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\News\StoreNewsRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreNewsRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$news = new News();
|
||||
$news->fill($request->validated());
|
||||
$oldestNewsWithHighlight = News::query()->where('highlight', true)->orderBy('created_at')->get();
|
||||
if ($news->saveOrFail()) {
|
||||
if ($news->highlight === true) {
|
||||
if ($oldestNewsWithHighlight->count() >= 2) {
|
||||
/** @var \App\Models\News $firstNews */
|
||||
$firstNews = $oldestNewsWithHighlight->first();
|
||||
$firstNews->highlight = false;
|
||||
$firstNews->save();
|
||||
}
|
||||
}
|
||||
return redirect()->route('bo.news.edit', $news)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(__('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(__('models.classes.news'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.news.show', ['newsModel' => $news]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$newsCategoryModels = NewsCategory::query()->where('published', true)->orderBy('order')->get();
|
||||
return view('bo.pages.news.edit', ['newsModel' => $news, 'newsCategoryModels' => $newsCategoryModels]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\News\UpdateNewsRequest $request
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(
|
||||
UpdateNewsRequest $request,
|
||||
News $news
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
return DB::transaction(function () use ($request, $news) {
|
||||
$news->fill($request->validated());
|
||||
$oldestNewsWithHighlight = News::query()->where('highlight', true)->orderBy('created_at')->get();
|
||||
if ($news->saveOrFail()) {
|
||||
if ($news->highlight === true) {
|
||||
if ($oldestNewsWithHighlight->count() >= 2) {
|
||||
/** @var \App\Models\News $firstNews */
|
||||
$firstNews = $oldestNewsWithHighlight->first();
|
||||
$firstNews->highlight = false;
|
||||
$firstNews->save();
|
||||
}
|
||||
}
|
||||
return redirect()->route('bo.news.edit', $news)
|
||||
->with('success', trans('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.news.edit', $news)
|
||||
->with('error', trans('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(News $news): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
/** @var array<string,string> */
|
||||
$previousQueries = [];
|
||||
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
|
||||
if ($news->deleteOrFail()) {
|
||||
return redirect()->route('bo.news.index', $previousQueries)
|
||||
->with('success', trans('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', trans('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(trans('models.classes.news'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(News $news): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($news->replicate());
|
||||
}
|
||||
}
|
||||
30
app/Http/Controllers/Bo/UploadController.php
Normal file
30
app/Http/Controllers/Bo/UploadController.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\UploadFileRequest;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Models\HistoricalMilestone;
|
||||
|
||||
class UploadController extends Controller
|
||||
{
|
||||
/**
|
||||
* Upload a file sent in a request.
|
||||
* Used for picture upload in CKEditor.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\UploadFileRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function uploadFile(UploadFileRequest $request)
|
||||
{
|
||||
/** @var \Illuminate\Http\UploadedFile $image */
|
||||
$image = $request->upload;
|
||||
|
||||
$path = FileStorageHelper::storeFile(new HistoricalMilestone(), $image, true);
|
||||
|
||||
return response()->json([
|
||||
'url' => "/{$path}"
|
||||
]);
|
||||
}
|
||||
}
|
||||
95
app/Http/Requests/Bo/News/StoreNewsRequest.php
Normal file
95
app/Http/Requests/Bo/News/StoreNewsRequest.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\News;
|
||||
|
||||
use App\Models\News;
|
||||
use App\Rules\WysiwygLength;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class StoreNewsRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Gate::check('create', News::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->mergePicture('picture');
|
||||
$this->mergePicture('thumbnail');
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published'),
|
||||
'highlight' => $this->boolean('highlight'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'seo_title' => 'required|string|between:45,70',
|
||||
'seo_description' => 'required|string|between:50,160',
|
||||
'title' => 'required|string|between:3,255',
|
||||
'subtitle' => 'sometimes|nullable|string|between:3,255',
|
||||
'picture_alt' => 'required|string|between:3,255',
|
||||
'picture_title' => 'required|string|between:3,255',
|
||||
'thumbnail_alt' => 'required|string|between:3,255',
|
||||
'thumbnail_title' => 'required|string|between:3,255',
|
||||
'news_category_id' => 'required|integer',
|
||||
'content' => ['required', 'string', new WysiwygLength()],
|
||||
'highlight' => 'required|boolean',
|
||||
'published' => 'required|boolean',
|
||||
'publish_at' => 'sometimes|nullable|date',
|
||||
'unpublish_at' => 'sometimes|nullable|date|after:publish_at',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 700, 400, 700, 400),
|
||||
$this->pictureRules('thumbnail', 360, 250, 360, 250),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'seo_title' => trans('validation.attributes.title'),
|
||||
'seo_description' => trans('validation.attributes.title'),
|
||||
'title' => trans('validation.attributes.title'),
|
||||
'subtitle' => trans('validation.attributes.subtitle'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
'news_category_id' => trans('validation.custom.category'),
|
||||
'picture' => trans('validation.attributes.image'),
|
||||
'picture_alt' => trans('validation.custom.attribute_alt'),
|
||||
'picture_title' => trans('validation.custom.attribute_title'),
|
||||
'thumbnail_alt' => trans('validation.custom.attribute_alt'),
|
||||
'thumbnail_title' => trans('validation.custom.attribute_title'),
|
||||
'published' => trans('validation.attributes.published'),
|
||||
'highlight' => trans('validation.attributes.highlight'),
|
||||
'publish_at' => trans('validation.custom.publish_at'),
|
||||
'unpublish_at' => trans('validation.custom.unpublish_at'),
|
||||
];
|
||||
}
|
||||
}
|
||||
18
app/Http/Requests/Bo/News/UpdateNewsRequest.php
Normal file
18
app/Http/Requests/Bo/News/UpdateNewsRequest.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\News;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class UpdateNewsRequest extends StoreNewsRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Gate::check('update', $this->route('news'));
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/Bo/UploadFileRequest.php
Normal file
30
app/Http/Requests/Bo/UploadFileRequest.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UploadFileRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check() and $this->ajax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'upload' => 'required|image|mimes:jpeg,png,jpg|max:2048'
|
||||
];
|
||||
}
|
||||
}
|
||||
241
app/Models/News.php
Normal file
241
app/Models/News.php
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Detection\MobileDetect;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* @property string $title The title of the news.
|
||||
* @property string $content The content of the news.
|
||||
* @property string $url The linkedin url of the news.
|
||||
* @property string $picture Picture path.
|
||||
* @property string $picture_title Picture title attribute.
|
||||
* @property string $picture_alt Picture alt attribute.
|
||||
* @property boolean $published News publish status.
|
||||
* @property-read \Illuminate\Support\Carbon $published_at News published_at.
|
||||
* @property-read \Illuminate\Support\Carbon $unpublished_at News unpublished_at.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||
*/
|
||||
class News extends Model
|
||||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
'title',
|
||||
'subtitle',
|
||||
'slug',
|
||||
'picture',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
'thumbnail',
|
||||
'thumbnail_alt',
|
||||
'thumbnail_title',
|
||||
'news_category_id',
|
||||
'content',
|
||||
'highlight',
|
||||
'published',
|
||||
'publish_at',
|
||||
'unpublish_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'publish_at' => 'datetime',
|
||||
'unpublish_at' => 'datetime',
|
||||
'published' => 'boolean',
|
||||
'highlight' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $news) {
|
||||
self::makeStatusSense($news);
|
||||
self::assertTitleIsUnique($news->title);
|
||||
self::manageFields($news);
|
||||
});
|
||||
static::updating(function (self $news) {
|
||||
self::makeStatusSense($news);
|
||||
self::assertTitleIsUnique($news->title, $news->getKey());
|
||||
self::manageFields($news);
|
||||
});
|
||||
static::updated(function (self $news) {
|
||||
FileStorageHelper::removeOldFile($news, 'picture');
|
||||
FileStorageHelper::removeOldFile($news, 'thumbnail');
|
||||
});
|
||||
static::deleted(function (self $news) {
|
||||
FileStorageHelper::removeFile($news, 'picture');
|
||||
FileStorageHelper::removeFile($news, 'thumbnail');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Adjusts news status using current status and publish dates
|
||||
*
|
||||
* @param self $news
|
||||
* @return void
|
||||
*/
|
||||
private static function makeStatusSense(self $news): void
|
||||
{
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$publish_at = $news->publish_at;
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$unpublish_at = $news->unpublish_at;
|
||||
$wantedStatus = $news->published;
|
||||
if ($publish_at or $unpublish_at) {
|
||||
$news->published = $news->planificated_status;
|
||||
}
|
||||
if ($wantedStatus !== $news->published) {
|
||||
session()->flash('bo.info', \trans(
|
||||
'La publication est modifiée en concordance avec les dates enregistrées.
|
||||
Pour modifier l\'état de publication, veuillez modifier ou enlever les dates correspondantes.'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter the current status following planification dates planificated_status
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getPlanificatedStatusAttribute(): bool
|
||||
{
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$publish_at = $this->publish_at;
|
||||
/** @var \Carbon\Carbon|null */
|
||||
$unpublish_at = $this->unpublish_at;
|
||||
if ($publish_at and $unpublish_at) {
|
||||
return $unpublish_at->greaterThanOrEqualTo(now()) and $publish_at->lessThan(now());
|
||||
}
|
||||
if ($publish_at) {
|
||||
return $publish_at->lessThan(now());
|
||||
}
|
||||
if ($unpublish_at) {
|
||||
return $unpublish_at->greaterThanOrEqualTo(now());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage model fields.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
$model->slug = str($model->title)->slug();
|
||||
$model->thumbnail = FileStorageHelper::storeFile($model, $model->thumbnail, true);
|
||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts using validation that the title is unique
|
||||
*
|
||||
* @param string|null $title
|
||||
* @param integer|null $id
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException If an actu title already exists.
|
||||
*/
|
||||
private static function assertTitleIsUnique(string|null $title, ?int $id = null): void
|
||||
{
|
||||
$table = (new self())->getTable();
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'slug', str($title)->slug(), $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get News views by News category.
|
||||
*
|
||||
* @param string|null $slug
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public static function getNewsViewsByNewsCategory(string|null $slug = null): \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
{
|
||||
/**
|
||||
* @var Detection\MobileDetect
|
||||
*/
|
||||
$detect = new MobileDetect();
|
||||
/** @var \App\Models\NewsCategory|null */
|
||||
$newsCategoryModel = !is_null($slug) && !empty($slug) ? NewsCategory::query()->where('slug', $slug)->first() : null;
|
||||
return News::query()
|
||||
->with('newsCategory')
|
||||
->when(!is_null($newsCategoryModel), function (Builder $q) use ($newsCategoryModel) {
|
||||
$q->whereHas('newsCategory', function (Builder $q) use ($newsCategoryModel) {
|
||||
$q->where('id', $newsCategoryModel->getKey());
|
||||
});
|
||||
})
|
||||
->where('published', true)
|
||||
->orderByDesc('created_at')
|
||||
->paginate($detect->isMobile() ? 3 : 6)
|
||||
->through(function ($newsModel) {
|
||||
return view('fo.partials.news-card', ['newsModel' => $newsModel])->render();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Social news views by filter social category.
|
||||
*
|
||||
* @param string|null $slug
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public static function getSocialViewsByFilter(string|null $slug = null): \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
{
|
||||
/**
|
||||
* @var Detection\MobileDetect
|
||||
*/
|
||||
$detect = new MobileDetect();
|
||||
/** @var \App\Models\NewsCategory|null */
|
||||
$socialCategory = !is_null($slug) && !empty($slug) ? NewsCategory::query()->where('slug', $slug)->first() : null;
|
||||
return News::query()
|
||||
->with('newsCategory')
|
||||
->when(!is_null($socialCategory), function (Builder $q) use ($socialCategory) {
|
||||
$q->whereHas('newsCategory', function (Builder $q) use ($socialCategory) {
|
||||
$q->where('id', $socialCategory->getKey());
|
||||
});
|
||||
})
|
||||
->where('published', true)
|
||||
->orderByDesc('created_at')
|
||||
->paginate($detect->isMobile() ? 4 : 12)
|
||||
->through(function ($socialModel) {
|
||||
return view('fo.partials.news-card', ['newsModel' => $socialModel])->render();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Get the category that owns the news.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function newsCategory(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(NewsCategory::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ class Product extends Model implements SeoInterface
|
|||
{
|
||||
$rangeModel = !is_null($slug) ?
|
||||
Range::query()->where('slug', $slug)->first() :
|
||||
Range::query()->orderBy('slug', 'ASC')->first();
|
||||
Range::query()->orderBy('slug', 'ASC')->where('published', true)->first();
|
||||
return Product::query()->whereHas('range', function (Builder $q) use ($rangeModel) {
|
||||
$q->where('id', $rangeModel->getKey());
|
||||
})->inRandomOrder()
|
||||
|
|
|
|||
97
app/Policies/NewsPolicy.php
Normal file
97
app/Policies/NewsPolicy.php
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class NewsPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
{
|
||||
return UserStaticRules::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create a new model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can duplicate the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function duplicate(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can publish/unpublish the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function changePublished(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can change the order of the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function changeOrder(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ use App\Models\ConsumptionMoment;
|
|||
use App\Models\HistoricalMilestone;
|
||||
use App\Models\MainSlide;
|
||||
use App\Models\Meat;
|
||||
use App\Models\News;
|
||||
use App\Models\NewsCategory;
|
||||
use App\Models\NewsCorporate;
|
||||
use App\Models\Offer;
|
||||
|
|
@ -87,6 +88,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
Route::model('news_corporate', NewsCorporate::class);
|
||||
Route::model('testimonial', Testimonial::class);
|
||||
Route::model('historical_milestone', HistoricalMilestone::class);
|
||||
Route::model('news', News::class);
|
||||
Route::model('news_category', NewsCategory::class);
|
||||
}
|
||||
|
||||
|
|
|
|||
42
database/factories/NewsFactory.php
Normal file
42
database/factories/NewsFactory.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\News>
|
||||
*/
|
||||
class NewsFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$publishedStatus = fake()->boolean(75);
|
||||
$publish_at = Carbon::now()->addMonth();
|
||||
$title = fake()->unique()->words(rand(1, 2), true);
|
||||
return [
|
||||
'seo_title' => fake()->sentence(),
|
||||
'seo_description' => fake()->sentence(),
|
||||
'title' => $title,
|
||||
'subtitle' => fake()->sentence(),
|
||||
'content' => fake()->text(),
|
||||
'slug' => Str::slug($title),
|
||||
'picture_alt' => fake()->sentence(),
|
||||
'picture_title' => fake()->sentence(),
|
||||
'thumbnail_alt' => fake()->sentence(),
|
||||
'thumbnail_title' => fake()->sentence(),
|
||||
'highlight' => false,
|
||||
'news_category_id' => 1,
|
||||
'published' => $publishedStatus,
|
||||
'publish_at' => !$publishedStatus ? $publish_at : null,
|
||||
'unpublish_at' => !$publishedStatus ? $publish_at->copy()->addDays(rand(10, 20)) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
BIN
database/factories/assets/news/default-700x400.png
Normal file
BIN
database/factories/assets/news/default-700x400.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
database/factories/assets/news/thumbnail-360x250.png
Normal file
BIN
database/factories/assets/news/thumbnail-360x250.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
44
database/migrations/2024_08_10_153246_create_news_table.php
Normal file
44
database/migrations/2024_08_10_153246_create_news_table.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('news', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('seo_title')->comment('The seo title of the news.');
|
||||
$table->string('seo_description')->comment('The seo description of the news.');
|
||||
$table->string('title')->comment('The title of the news.');
|
||||
$table->string('subtitle')->nullable()->comment('The title of the news.');
|
||||
$table->string('picture')->comment('Picture path.');
|
||||
$table->string('picture_alt')->comment('Picture alt attribute.');
|
||||
$table->string('picture_title')->comment('Picture title attribute.');
|
||||
$table->string('thumbnail')->comment('Thumbnail path.');
|
||||
$table->string('thumbnail_alt')->comment('Thumbnail alt attribute.');
|
||||
$table->string('thumbnail_title')->comment('Thumbnail title attribute.');
|
||||
$table->string('slug')->unique()->comment('Unique title slug');
|
||||
$table->text('content')->comment('The content of the news.');
|
||||
$table->foreignId('news_category_id')->constrained('news_categories')->restrictOnDelete()->comment('News category id');
|
||||
$table->boolean('highlight')->comment('Highlight status.');
|
||||
$table->boolean('published')->comment('News publish status.');
|
||||
$table->timestamp('publish_at')->nullable()->comment('News publishment date.');
|
||||
$table->timestamp('unpublish_at')->nullable()->comment('News unpublishment date.');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('news');
|
||||
}
|
||||
};
|
||||
41
database/seeders/Development/NewsSeeder.php
Normal file
41
database/seeders/Development/NewsSeeder.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders\Development;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Models\News;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class NewsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = News::class;
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
News::factory(10)->make()->each(function (News $news) {
|
||||
$news->picture = FileStorageHelper::storeFile(
|
||||
$news,
|
||||
new \SplFileInfo(\resource_path(
|
||||
'../database/factories/assets/news/default-700x400.png'
|
||||
))
|
||||
);
|
||||
$news->thumbnail = FileStorageHelper::storeFile(
|
||||
$news,
|
||||
new \SplFileInfo(\resource_path(
|
||||
'../database/factories/assets/news/thumbnail-360x250.png'
|
||||
))
|
||||
);
|
||||
$news->saveQuietly();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ use Database\Seeders\Development\SubrangeSeeder;
|
|||
use Database\Seeders\Development\TestimonialSeeder;
|
||||
use Database\Seeders\Development\UserSeeder;
|
||||
use Database\Seeders\Development\NewsCorporateSeeder;
|
||||
use Database\Seeders\Development\NewsSeeder;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DevelopmentSeeder extends Seeder
|
||||
|
|
@ -56,6 +57,7 @@ class DevelopmentSeeder extends Seeder
|
|||
NewsCorporateSeeder::class,
|
||||
TestimonialSeeder::class,
|
||||
NewsCategorySeeder::class,
|
||||
NewsSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
67
resources/js/ckUploadAdapter.js
Normal file
67
resources/js/ckUploadAdapter.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import axios from "axios";
|
||||
import route from "../ts/modules/route";
|
||||
|
||||
class ckUploadAdapter {
|
||||
constructor(loader) {
|
||||
// The file loader instance to use during the upload.
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
// Starts the upload process.
|
||||
upload() {
|
||||
return this.loader.file.then(
|
||||
(file) =>
|
||||
new Promise((resolve, reject) => {
|
||||
this._initRequest();
|
||||
this._sendRequest(file, resolve, reject);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// Aborts the upload process.
|
||||
abort() {
|
||||
if (this.cancel) {
|
||||
this.cancel.abort();
|
||||
}
|
||||
}
|
||||
|
||||
// Initializes the XMLHttpRequest object using the URL passed to the constructor.
|
||||
_initRequest() {
|
||||
this.cancel = axios.CancelToken.source();
|
||||
this.route = route.methods.route("bo.upload");
|
||||
}
|
||||
|
||||
// Prepares the data and sends the request.
|
||||
_sendRequest(file, resolve, reject) {
|
||||
// Prepare the form data.
|
||||
const data = new FormData();
|
||||
data.append("upload", file);
|
||||
axios
|
||||
.post(this.route, data, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
onUploadProgress: (evt) => {
|
||||
this.loader.uploadTotal = evt.total;
|
||||
this.loader.uploaded = evt.loaded;
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
resolve({
|
||||
default: response.data.url,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
reject("Le fichier à été marbré");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function CkUploadAdapterPlugin(editor) {
|
||||
editor.plugins.get("FileRepository").createUploadAdapter = (loader) => {
|
||||
return new ckUploadAdapter(loader);
|
||||
};
|
||||
}
|
||||
|
||||
export default CkUploadAdapterPlugin;
|
||||
|
|
@ -62,7 +62,9 @@ return [
|
|||
|
||||
'minicrud' => [
|
||||
'visibility_label' => 'Visibility',
|
||||
'highlight_label' => 'Highlight',
|
||||
'visibility_helper' => 'Check to make it visible.',
|
||||
'highlight_helper' => 'Check to make it highlight.',
|
||||
'select_entity' => 'Select :entity from the list.',
|
||||
'associated_entity' => 'Associated :entity',
|
||||
'dimensions_must_be' => 'Must be :widthpx (width) by :heightpx (height).',
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ return [
|
|||
'claim' => 'claim',
|
||||
'historical_milestone' => 'historical milestone|historical milestones',
|
||||
'offer' => 'offer',
|
||||
'news' => 'news',
|
||||
'news_corporate' => 'news of the compagny',
|
||||
'news_category' => 'category of the news',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -289,6 +289,7 @@ return [
|
|||
'sustitle' => 'sustitle',
|
||||
'target' => 'target',
|
||||
'tips' => 'tips',
|
||||
'thumbnail' => 'thumbnail',
|
||||
'type' => 'type',
|
||||
'unit' => 'unit',
|
||||
'unpublish_at' => 'unpublish at',
|
||||
|
|
|
|||
|
|
@ -63,7 +63,11 @@ return [
|
|||
|
||||
'minicrud' => [
|
||||
'visibility_label' => 'Visibilité',
|
||||
'highlight_label' => 'Mise en avant',
|
||||
'category_label' => 'Catégorie de l\'article',
|
||||
'visibility_helper' => 'Cocher pour rendre visible.',
|
||||
'highlight_helper' => 'Cocher pour mettre en avant.',
|
||||
'category_helper' => 'Séléctionner la categorie.',
|
||||
'select_entity' => 'Sélectionnez :entity dans la liste.',
|
||||
'associated_entity' => ':entity associé(e)',
|
||||
'dimensions_must_be' => 'Doit être :widthpx (largeur) par :heightpx (hauteur).',
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ return [
|
|||
'claim' => 'allégations',
|
||||
'historical_milestone' => 'jalon historique|jalons historique',
|
||||
'offer' => 'offre',
|
||||
'news' => 'actualités',
|
||||
'news_corporate' => 'actualités de l\'entreprise',
|
||||
'news_category' => 'catégorie d\'une actualité',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -291,6 +291,7 @@ return [
|
|||
'sustitle' => 'sous-titre',
|
||||
'target' => 'cible',
|
||||
'tips' => 'astuce',
|
||||
'thumbnail' => 'vignette',
|
||||
'type' => 'type',
|
||||
'unit' => 'unité',
|
||||
'unpublish_at' => 'date de fin de publication',
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
import { computed, defineOptions, onMounted, ref, useAttrs, type PropType } from "vue";
|
||||
import parseLaravelErrorMessages from "../../modules/parseLaravelErrorMessages";
|
||||
import "./../../../js/vendor/ckeditor";
|
||||
// @ts-ignore
|
||||
import CkUploadAdapterPlugin from "./../../../js/ckUploadAdapter";
|
||||
|
||||
defineOptions({
|
||||
name: "CkEditorComponent"
|
||||
|
|
@ -184,6 +186,7 @@ onMounted(() => {
|
|||
|
||||
// * Differents CkEditor configs.
|
||||
const minimalConfig = {
|
||||
extraPlugins: [],
|
||||
wordCount: ckEditorGlobals.wordCount,
|
||||
ui: ckEditorGlobals.ui,
|
||||
placeholder: placeholder.value,
|
||||
|
|
@ -227,6 +230,9 @@ onMounted(() => {
|
|||
};
|
||||
|
||||
const basicConfig = {
|
||||
extraPlugins: [
|
||||
CkUploadAdapterPlugin,
|
||||
],
|
||||
wordCount: ckEditorGlobals.wordCount,
|
||||
ui: ckEditorGlobals.ui,
|
||||
placeholder: placeholder.value,
|
||||
|
|
@ -277,6 +283,8 @@ onMounted(() => {
|
|||
"removeFormat",
|
||||
"|",
|
||||
"sourceEditing",
|
||||
"|",
|
||||
"imageUpload",
|
||||
],
|
||||
},
|
||||
image: {
|
||||
|
|
|
|||
|
|
@ -821,7 +821,8 @@
|
|||
<div class="dropdown">
|
||||
<button data-bs-toggle="dropdown" type="button" aria-expanded="false" @class([
|
||||
'btn btn-primary text-start w-100 dropdown-toggle mt-1',
|
||||
'fw-bold active' => request()->routeIs('bo.news_categories.*')
|
||||
'fw-bold active' => request()->routeIs('bo.news.*')
|
||||
|| request()->routeIs('bo.news_categories.*')
|
||||
])>
|
||||
<i @class([
|
||||
'fa-solid fa-newspaper fa-fw',
|
||||
|
|
@ -829,6 +830,19 @@
|
|||
{{ __('Actualités') }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{{-- ACTUS LE GAULOIS --}}
|
||||
<li>
|
||||
<a @class([
|
||||
'dropdown-item px-3 py-2',
|
||||
'fw-bold text-bg-secondary' => request()->routeIs('bo.news.*')
|
||||
]) href="{{ route('bo.news.index') }}">
|
||||
<i @class([
|
||||
'fa-solid fa-newspaper fa-fw',
|
||||
'fa-lg' => request()->routeIs('bo.news.*')
|
||||
])></i>
|
||||
{{ str(__('Actus le Gaulois'))->ucFirst() }}
|
||||
</a>
|
||||
</li>
|
||||
{{-- ACTUS CATEGORY --}}
|
||||
<li>
|
||||
<a @class([
|
||||
|
|
|
|||
36
resources/views/bo/pages/news/create.blade.php
Normal file
36
resources/views/bo/pages/news/create.blade.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
@extends('bo.layout', ['brParam' => $newsModel])
|
||||
|
||||
@section('title', __('Création d\'une :model', ['model' => __('models.classes.news')]))
|
||||
@section('description', __('Création d\'une tout nouveau :model', ['model' => __('models.classes.news')]))
|
||||
@section('breadcrumb', request()->route()->getName())
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap pb-3">
|
||||
<div class="d-flex align-items-start flex-row">
|
||||
<a class="btn btn-primary text-decoration-none m-0 me-2" data-bs-toggle="tooltip" href="{{ route('bo.news.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => __('models.classes.news')]) }}">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</a>
|
||||
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $newsModel])
|
||||
</div>
|
||||
<div class="mb-md-0 mb-2">
|
||||
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.news')]) }}">
|
||||
{{ str(__('crud.actions.save'))->ucfirst() }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{ route('bo.news.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@include('bo.pages.news.form')
|
||||
@include('bo.partials.script-button-clone')
|
||||
<div class="row mt-3">
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-primary" id="formSubmit" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.news')]) }}">
|
||||
{{ str(__('crud.actions.save'))->ucfirst() }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
58
resources/views/bo/pages/news/edit.blade.php
Normal file
58
resources/views/bo/pages/news/edit.blade.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
@extends('bo.layout', ['brParam' => $newsModel])
|
||||
|
||||
@section('title', __('Édition d\'une :model', ['model' => __('models.classes.news')]))
|
||||
@section('description', __('Édition d\'une :model déjà existant', ['model' => __('models.classes.news')]))
|
||||
@section('breadcrumb', request()->route()->getName())
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap pb-3">
|
||||
<div class="d-flex align-items-start flex-row">
|
||||
<a class="btn btn-primary text-decoration-none m-0 me-2" data-bs-toggle="tooltip" href="{{ route('bo.news.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => str(__('models.classes.news'))->plural()]) }}">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</a>
|
||||
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $newsModel])
|
||||
</div>
|
||||
<div class="mb-md-0 mb-2">
|
||||
<form class="btn-group confirmDeleteTS" action="{{ route('bo.news.destroy', $newsModel) }}" method="POST" novalidate>
|
||||
@can('view', $newsModel)
|
||||
<a class="btn btn-warning" data-bs-toggle="tooltip" href="{{ route('bo.news.show', $newsModel) }}"
|
||||
title="{{ str(__('crud.actions.show'))->ucfirst() }}">
|
||||
<i class="fa-solid fa-eye"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('duplicate', $newsModel)
|
||||
<a class="btn btn-secondary" data-bs-toggle="tooltip" href="{{ route('bo.news.duplicate', $newsModel) }}"
|
||||
title="{{ str(__('crud.actions.duplicate'))->ucfirst() }}">
|
||||
<i class="fa-solid fa-copy"></i>
|
||||
</a>
|
||||
@endcan
|
||||
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.news')]) }}">
|
||||
{{ str(__('crud.actions.save'))->ucfirst() }}
|
||||
</button>
|
||||
@can('delete', $newsModel)
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button class="btn btn-danger" data-bs-toggle="tooltip" type="submit" title="{{ str(__('crud.actions.delete'))->ucfirst() }}">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
@endcan
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{ route('bo.news.update', $newsModel) }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
@include('bo.pages.news.form')
|
||||
@include('bo.partials.script-button-clone')
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-primary" id="formSubmit" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.news')]) }}">
|
||||
{{ str(__('crud.actions.save'))->ucfirst() }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
403
resources/views/bo/pages/news/form.blade.php
Normal file
403
resources/views/bo/pages/news/form.blade.php
Normal file
|
|
@ -0,0 +1,403 @@
|
|||
<div class="row">
|
||||
{{-- SEO_TITLE --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.custom.seo_title'))->ucfirst() }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'newsSeoTitle',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.custom.seo_title'))->ucfirst(),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => trans('models.classes.news'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'seo_title',
|
||||
'required' => true,
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => sprintf(
|
||||
'%s %s',
|
||||
__('crud.helpers.seo_title'),
|
||||
__('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.custom.seo_title'),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => trans('models.classes.news'),
|
||||
]),
|
||||
'min' => 45,
|
||||
'max' => 70,
|
||||
])),
|
||||
'placeholder' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.custom.seo_title'))->ucfirst(),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => trans('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- SEO_DESCRIPTION --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.custom.seo_description'))->ucfirst() }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar-multiline', [
|
||||
'id' => 'newsSeoDescription',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.custom.seo_description'))->ucfirst(),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => trans('models.classes.news'),
|
||||
]),
|
||||
'name' => 'seo_description',
|
||||
'model' => $newsModel ?? null,
|
||||
'required' => true,
|
||||
'helper' => sprintf(
|
||||
'%s %s',
|
||||
__('crud.helpers.seo_description'),
|
||||
__('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.custom.seo_description'),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => trans('models.classes.news'),
|
||||
]),
|
||||
'min' => 50,
|
||||
'max' => 160,
|
||||
])),
|
||||
'placeholder' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.custom.seo_description'))->ucfirst(),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => trans('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- TITLE --}}
|
||||
<div class="col-12 col-lg-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.attributes.title'))->ucFirst() }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'newsTitle',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.attributes.title'))->ucFirst(),
|
||||
'inter' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'title',
|
||||
'required' => true,
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.attributes.title'),
|
||||
'inter' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'min' => 3,
|
||||
'max' => 255,
|
||||
]),
|
||||
'placeholder' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.attributes.title'))->ucFirst(),
|
||||
'inter' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- SUBTITLE --}}
|
||||
<div class="col-12 col-lg-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.custom.subtitle'))->ucFirst() }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'newsSubtitle',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.custom.subtitle'))->ucFirst(),
|
||||
'inter' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'subtitle',
|
||||
'required' => false,
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.custom.subtitle'),
|
||||
'inter' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'min' => 3,
|
||||
'max' => 255,
|
||||
]),
|
||||
'placeholder' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.custom.subtitle'))->ucFirst(),
|
||||
'inter' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- PICTURE --}}
|
||||
<div class="col-12 pb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.attributes.image'))->ucFirst() }}</legend>
|
||||
<div class="row mb-3">
|
||||
{{-- PICTURE_ALT --}}
|
||||
<div class="col-12 col-lg-6 m-md-0 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'newsPictureAlt',
|
||||
'label' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_alt'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.vowel'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'picture_alt',
|
||||
'required' => true,
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('crud.minicrud.picture_alt_helper'),
|
||||
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_alt'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.vowel'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- PICTURE_TITLE --}}
|
||||
<div class="col-12 col-lg-6 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'newsPictureTitle',
|
||||
'label' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_title'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.vowel'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'picture_title',
|
||||
'required' => true,
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('crud.minicrud.picture_title_helper'),
|
||||
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_title'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.vowel'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- PICTURE --}}
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar-picture', [
|
||||
'id' => 'newsPicture',
|
||||
'name' => 'picture',
|
||||
'width' => 700,
|
||||
'height' => 400,
|
||||
'model' => $newsModel ?? null,
|
||||
'required' => true,
|
||||
'preview' => true,
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- THUMBNAIL --}}
|
||||
<div class="col-12 pb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.custom.thumbnail'))->ucFirst() }}</legend>
|
||||
<div class="row mb-3">
|
||||
{{-- THUMBNAIL_ALT --}}
|
||||
<div class="col-12 col-lg-6 m-md-0 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'newsThumbnailAlt',
|
||||
'label' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_alt'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.female'),
|
||||
'field2' => __('validation.custom.thumbnail'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'thumbnail_alt',
|
||||
'required' => true,
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('crud.minicrud.picture_alt_helper'),
|
||||
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_alt'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.female'),
|
||||
'field2' => __('validation.custom.thumbnail'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- THUMBNAIL_TITLE --}}
|
||||
<div class="col-12 col-lg-6 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'newsThumbnailTitle',
|
||||
'label' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_title'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.female'),
|
||||
'field2' => __('validation.custom.thumbnail'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'thumbnail_title',
|
||||
'required' => true,
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('crud.minicrud.picture_title_helper'),
|
||||
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => str(__('validation.custom.attribute_title'))->ucFirst(),
|
||||
'inter1' => __('validation.custom.of_the.female'),
|
||||
'field2' => __('validation.custom.thumbnail'),
|
||||
'inter2' => __('validation.custom.of_the.vowel'),
|
||||
'model' => __('models.classes.news'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- THUMBNAIL --}}
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar-picture', [
|
||||
'id' => 'newsThumbnail',
|
||||
'name' => 'thumbnail',
|
||||
'width' => 360,
|
||||
'height' => 250,
|
||||
'model' => $newsModel ?? null,
|
||||
'required' => true,
|
||||
'preview' => true,
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- CONTENT --}}
|
||||
<div class="col-12 mb-3">
|
||||
<fieldset class="border p-3">
|
||||
<legend>{{ str(__('validation.attributes.content'))->ucfirst() }}</legend>
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.text-html', [
|
||||
'id' => 'newsContent',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => str(__('validation.attributes.content'))->ucfirst(),
|
||||
'inter' => __('validation.custom.of_the.vowel'),
|
||||
'model' => trans('models.classes.news'),
|
||||
]),
|
||||
'name' => 'content',
|
||||
'model' => $newsModel ?? null,
|
||||
'required' => true,
|
||||
'helper' => __('crud.minicrud.text_warning'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- HIGHLIGHT --}}
|
||||
<div class="col-12 col-lg-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.custom.highlight'))->ucFirst() }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
@include('bo.partials.inputs.tinyint-boolean', [
|
||||
'id' => 'newsHighlight ',
|
||||
'name' => 'highlight',
|
||||
'model' => $newsModel ?? null,
|
||||
'label' => __('crud.minicrud.highlight_label'),
|
||||
'helper' => __('crud.minicrud.highlight_helper'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- CATEGORY --}}
|
||||
<div class="col-12 col-lg-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('validation.custom.category'))->ucFirst() }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
@include('bo.partials.inputs.bigint-foreign-id', [
|
||||
'id' => 'newsCategoryId',
|
||||
'name' => 'news_category_id',
|
||||
'model' => $newsModel ?? null,
|
||||
'associatedModels' => $newsCategoryModels,
|
||||
'foreignLabel' => 'title',
|
||||
'label' => __('crud.minicrud.category_label'),
|
||||
'helper' => __('crud.minicrud.category_helper'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- PUBLICATION --}}
|
||||
<div class="col-12 pb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ str(__('crud.minicrud.visibility_label'))->ucFirst() }}</legend>
|
||||
<div class="row mb-3">
|
||||
{{-- PUBLISHED --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
@include('bo.partials.inputs.tinyint-boolean', [
|
||||
'id' => 'newsPublished',
|
||||
'name' => 'published',
|
||||
'model' => $newsModel ?? null,
|
||||
'label' => __('crud.minicrud.visibility_label'),
|
||||
'helper' => sprintf('%s %s', __('crud.minicrud.visibility_helper'), __('crud.helpers.visibility_with_dates')),
|
||||
])
|
||||
</div>
|
||||
{{-- PUBLICATION DATES --}}
|
||||
<div class="col-12 mb-3">
|
||||
<div class="row mb-3">
|
||||
{{-- PUBLISH_AT --}}
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
@include('bo.partials.inputs.timestamp-datetime', [
|
||||
'label' => str(__('validation.custom.publish_at'))->ucFirst() . __(' (Europe/Paris)'),
|
||||
'id' => 'newsPublishedAt',
|
||||
'name' => 'publish_at',
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('crud.helpers.publish_at', [
|
||||
'model' => str(__('models.classes.news'))->ucFirst(),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
{{-- UNPUBLISH_AT --}}
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
@include('bo.partials.inputs.timestamp-datetime', [
|
||||
'label' => str(__('validation.custom.unpublish_at'))->ucfirst() . __(' (Europe/Paris)'),
|
||||
'id' => 'newsUnPublishedAt',
|
||||
'name' => 'unpublish_at',
|
||||
'model' => $newsModel ?? null,
|
||||
'helper' => __('crud.helpers.unpublish_at', [
|
||||
'model' => str(__('models.classes.news'))->ucFirst(),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-12 text-center">
|
||||
<p><b>{{ __('* Champs obligatoires') }}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
80
resources/views/bo/pages/news/index-list.blade.php
Normal file
80
resources/views/bo/pages/news/index-list.blade.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<table class="table-hover table-fix-action m-0 table">
|
||||
@if (count($newsModels) > 0)
|
||||
<thead>
|
||||
@include('bo.modules.table-col-sorter', [
|
||||
'cols' => [
|
||||
'title' => str(__('validation.attributes.title'))->ucfirst(),
|
||||
'news_category_id' => str(__('validation.custom.category'))->ucfirst(),
|
||||
'picture' => str(__('validation.attributes.image'))->ucfirst(),
|
||||
'published' => str(__('validation.custom.publication'))->ucfirst(),
|
||||
'updated_at' => str(__('validation.attributes.updated_at'))->ucfirst(),
|
||||
],
|
||||
])
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($newsModels as $newsModel)
|
||||
<tr class="border-bottom">
|
||||
<td class="text-center align-middle">{{ $newsModel->title }}</td>
|
||||
<td class="text-center align-middle">{{ $newsModel->newsCategory->title }}</td>
|
||||
<td class="text-center align-middle">
|
||||
<img class="image-preview" src="{{ asset($newsModel->picture) }}" title="{{ $newsModel->picture_title }}"
|
||||
alt="{{ $newsModel->picture_alt }}">
|
||||
</td>
|
||||
@include('bo.modules.change-published-status', [
|
||||
'routeName' => 'news',
|
||||
'model' => $newsModel,
|
||||
])
|
||||
<td class="text-center align-middle">
|
||||
<span class="badge text-bg-secondary">{{ $newsModel->updated_at->isoFormat('LLLL') }}</span>
|
||||
</td>
|
||||
<td class="text-end align-middle">
|
||||
@canAny(['show', 'duplicate', 'update', 'delete'], $newsModel)
|
||||
<form class="btn-group confirmDeleteTS" action="{{ route('bo.news.destroy', $newsModel) }}"
|
||||
method="POST" novalidate>
|
||||
@can('view', $newsModel)
|
||||
<a class="btn btn-sm btn-warning" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.news.show', $newsModel) }}"
|
||||
title="{{ str(__('crud.actions.show'))->ucfirst() }}">
|
||||
<i class="fa-solid fa-eye"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('duplicate', $newsModel)
|
||||
<a class="btn btn-sm btn-secondary" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.news.duplicate', $newsModel) }}"
|
||||
title="{{ str(__('crud.actions.duplicate'))->ucfirst() }}">
|
||||
<i class="fa-solid fa-copy"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('update', $newsModel)
|
||||
<a class="btn btn-sm btn-primary" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.news.edit', $newsModel) }}"
|
||||
title="{{ str(__('crud.actions.update'))->ucfirst() }}">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('delete', $newsModel)
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button class="btn btn-sm btn-danger" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ str(__('crud.actions.delete'))->ucfirst() }}">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
@endcan
|
||||
</form>
|
||||
@else
|
||||
<span class="text-danger" data-bs-toggle="tooltip" title="{{ __('list.right') }}">
|
||||
<i class="fa-solid fa-ban"></i>
|
||||
</span>
|
||||
@endcan
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@else
|
||||
<tr>
|
||||
<td class="border-0">
|
||||
{{ trans_choice('crud.other.no_model_found', 1, ['model' => __('models.classes.news')]) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</table>
|
||||
21
resources/views/bo/pages/news/index.blade.php
Normal file
21
resources/views/bo/pages/news/index.blade.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
@extends('bo.layout')
|
||||
|
||||
@section('title', str(__('models.classes.news'))->ucfirst()->plural())
|
||||
@section('description', __('Liste de tous les :model', ['model' => str(__('models.classes.news'))->plural()]))
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap">
|
||||
@include('modules.breadcrumbs.breadcrumb-body')
|
||||
@can('create', \App\Models\News::class)
|
||||
<a class="btn btn-primary float-right" data-bs-toggle="tooltip" href="{{ route('bo.news.create') }}"
|
||||
title="{{ __('crud.helpers.create_model', ['model' => __('models.classes.news')]) }}">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</a>
|
||||
@endcan
|
||||
</div>
|
||||
@include('bo.modules.search-bar')
|
||||
<div class="table-responsive mb-3">
|
||||
@include('bo.pages.news.index-list')
|
||||
</div>
|
||||
{{ $newsModels->links() }}
|
||||
@endsection
|
||||
131
resources/views/bo/pages/news/show.blade.php
Normal file
131
resources/views/bo/pages/news/show.blade.php
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
@extends('bo.layout', ['brParam' => $newsModel])
|
||||
|
||||
@section('title', __('Aperçu d\'un :model', ['model' => __('models.classes.news')]))
|
||||
@section('description', __('Aperçu d\'un :model déjà existante', ['model' => __('models.classes.news')]))
|
||||
@section('breadcrumb', request()->route()->getName())
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center border-bottom flex-wrap pb-3">
|
||||
<div class="d-flex align-items-start flex-row">
|
||||
<a class="btn btn-primary text-decoration-none m-0 me-2" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
href="{{ route('bo.news.index', ['sort_col' => 'created_at', 'sort_way' => 'desc']) }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => str(__('models.classes.news'))->plural()]) }}">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</a>
|
||||
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $newsModel])
|
||||
</div>
|
||||
@canAny(['duplicate', 'update', 'delete'], $newsModel)
|
||||
<form class="btn-group confirmDeleteTS" data-message="{{ __('crud.sweetalert.data_lost') }}"
|
||||
action="{{ route('bo.news.destroy', $newsModel) }}" method="POST" novalidate>
|
||||
@can('duplicate', $newsModel)
|
||||
<a class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
href="{{ route('bo.news.duplicate', $newsModel) }}"
|
||||
title="{{ __('crud.helpers.duplicate_model', ['model' => __('models.classes.news')]) }}">
|
||||
<i class="fa-solid fa-copy"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('update', $newsModel)
|
||||
<a class="btn btn-primary" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
href="{{ route('bo.news.edit', $newsModel) }}"
|
||||
title="{{ __('crud.helpers.edit_model', ['model' => __('models.classes.news')]) }}">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('delete', $newsModel)
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button class="btn btn-danger" data-bs-toggle="tooltip" data-bs-placement="top" type="submit"
|
||||
title="{{ __('crud.helpers.delete_model', ['model' => __('models.classes.news')]) }}">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
@endcan
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="table-responsive mb-3">
|
||||
<table class="table-hover m-0 table">
|
||||
<tbody>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.title'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ $newsModel->title }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.seo_title'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ $newsModel->seo_title }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.seo_description'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ $newsModel->seo_description }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.image'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
<img class="img-fluid" src="{{ asset($newsModel->picture) }}" title="{{ $newsModel->picture_title }}"
|
||||
alt="{{ $newsModel->picture_alt }}">
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.thumbnail'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
<img class="img-fluid" src="{{ asset($newsModel->thumbnail) }}" title="{{ $newsModel->thumbnail_title }}"
|
||||
alt="{{ $newsModel->thumbnail_alt }}">
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.content'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ $newsModel->content }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">
|
||||
{{ str(__('validation.custom.publication'))->ucFirst() }}
|
||||
</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ $newsModel->published
|
||||
? str($newsModel->created_at->isoFormat('LLLL'))->ucFirst()
|
||||
: __('crud.other.model_not_published') }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.publish_at'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ $newsModel->publish_at
|
||||
? str($newsModel->publish_at->isoFormat('LLLL'))->ucFirst()
|
||||
: __('crud.other.model_not_published') }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.unpublish_at'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ $newsModel->unpublish_at
|
||||
? str($newsModel->unpublish_at->isoFormat('LLLL'))->ucFirst()
|
||||
: __('crud.other.model_not_published') }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.created_at'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ str($newsModel->created_at->isoFormat('LLLL'))->ucFirst() }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="border-bottom">
|
||||
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.updated_at'))->ucFirst() }}</td>
|
||||
<td class="w-50 text-center align-middle">
|
||||
{{ str($newsModel->updated_at->isoFormat('LLLL'))->ucFirst() }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -77,8 +77,8 @@
|
|||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
@endif
|
||||
@if (!$staticPageModel->type->equals(StaticPageType::recipe) &&
|
||||
!$staticPageModel->type->equals(StaticPageType::product) &&
|
||||
|
|
@ -179,6 +179,7 @@
|
|||
'model' => trans_choice('models.classes.static_page', 1),
|
||||
]),
|
||||
'name' => 'content',
|
||||
'editorConfig' => \App\Enums\CkEditorConfigName::basic->label(),
|
||||
'model' => $staticPageModel ?? null,
|
||||
'required' => false,
|
||||
'helper' => __('crud.minicrud.text_warning'),
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
'editorConfig' => $editorConfig ?? \App\Enums\CkEditorConfigName::basic->label(),
|
||||
'placeholder' => $placeholder ?? __('Un text riche'),
|
||||
'errors' => $errors->getBag('default')->getMessages() ?? [],
|
||||
'editorConfig' => $editorConfig ?? \App\Enums\CkEditorConfigName::basic->label(),
|
||||
];
|
||||
@endphp
|
||||
<div class="ck-editor" data-json='@json($data)'></div>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
// FIXME: Add missing routes for MenuNodeTypeEnum usage in settings vue component
|
||||
// FIXME: Add missing routes for RangesSliderComponent.vue
|
||||
// BO
|
||||
window.__SYSTEM._routes['bo.upload'] = '{{ route('bo.upload') }}';
|
||||
window.__SYSTEM._routes['bo.menu_node_data.index'] = '{{ route('bo.menu_node_data.index') }}';
|
||||
window.__SYSTEM._routes['bo.menu_node_data.update'] = '{{ route('bo.menu_node_data.update', ['menu_node_data' => 'MENU_NODE_DATA']) }}';
|
||||
window.__SYSTEM._routes['bo.approaches.json-paginate'] = '{{ route('bo.approaches.json-paginate') }}';
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use App\Models\MainSlide;
|
|||
use App\Models\GeneralSetting;
|
||||
use App\Models\HistoricalMilestone;
|
||||
use App\Models\Meat;
|
||||
use App\Models\News;
|
||||
use App\Models\NewsCategory;
|
||||
use App\Models\NewsCorporate;
|
||||
use App\Models\Offer;
|
||||
|
|
@ -582,6 +583,30 @@ Breadcrumbs::for('bo.historical_milestones.duplicate', function (Generator $trai
|
|||
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
|
||||
});
|
||||
|
||||
// * NEWS
|
||||
Breadcrumbs::for('bo.news.index', function (Generator $trail) {
|
||||
$trail->push(
|
||||
Str::of(trans('models.classes.news'))->plural()->ucfirst(),
|
||||
route('bo.news.index')
|
||||
);
|
||||
});
|
||||
Breadcrumbs::for('bo.news.show', function (Generator $trail, News $news) {
|
||||
$trail->parent('bo.news.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.view')), route('bo.news.show', $news));
|
||||
});
|
||||
Breadcrumbs::for('bo.news.create', function (Generator $trail) {
|
||||
$trail->parent('bo.news.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.create')), route('bo.news.create'));
|
||||
});
|
||||
Breadcrumbs::for('bo.news.edit', function (Generator $trail, News $news) {
|
||||
$trail->parent('bo.news.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.news.edit', $news));
|
||||
});
|
||||
Breadcrumbs::for('bo.news.duplicate', function (Generator $trail) {
|
||||
$trail->parent('bo.news.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
|
||||
});
|
||||
|
||||
// * NEWS CORPORATE
|
||||
Breadcrumbs::for('bo.news_corporates.index', function (Generator $trail) {
|
||||
$trail->push(
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use App\Http\Controllers\Bo\MainSlideController;
|
|||
use App\Http\Controllers\Bo\MenuNodeDataController;
|
||||
use App\Http\Controllers\Bo\MeatController;
|
||||
use App\Http\Controllers\Bo\NewsCategoryController;
|
||||
use App\Http\Controllers\Bo\NewsController;
|
||||
use App\Http\Controllers\Bo\NewsCorporateController;
|
||||
use App\Http\Controllers\Bo\OfferController;
|
||||
use App\Http\Controllers\Bo\ProductController;
|
||||
|
|
@ -25,6 +26,7 @@ use App\Http\Controllers\Bo\StaticPageController;
|
|||
use App\Http\Controllers\Bo\SubmeatController;
|
||||
use App\Http\Controllers\Bo\SubrangeController;
|
||||
use App\Http\Controllers\Bo\TestimonialController;
|
||||
use App\Http\Controllers\Bo\UploadController;
|
||||
use App\Http\Controllers\Bo\UserController;
|
||||
use App\Http\Controllers\Bo\VideoController;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
|
@ -431,6 +433,17 @@ Route::middleware(['throttle:web', 'admin-secure'])->prefix('bo')->name('bo.')->
|
|||
'duplicate'
|
||||
])->name('news_corporates.duplicate');
|
||||
|
||||
// * NEWS.
|
||||
Route::resource('news', NewsController::class)
|
||||
->withoutMiddleware('htmlsanitize')
|
||||
->middleware('htmlsanitize:content');
|
||||
Route::patch('/news/{news}/change-published', [
|
||||
NewsController::class, 'changePublished'
|
||||
])->name('news.change-published');
|
||||
Route::get('/news/{news}/duplicate', [
|
||||
NewsController::class, 'duplicate'
|
||||
])->name('news.duplicate');
|
||||
|
||||
// * NEWS CATEGORIES.
|
||||
Route::resource('news_categories', NewsCategoryController::class);
|
||||
Route::patch('/news_categories/{news_category}/change-published', [
|
||||
|
|
@ -452,4 +465,7 @@ Route::middleware(['throttle:web', 'admin-secure'])->prefix('bo')->name('bo.')->
|
|||
});
|
||||
// * Others routes
|
||||
Route::post('theme/set', [Controller::class, 'setTheme'])->name('theme.set');
|
||||
|
||||
// * UPLOAD (USED FOR CKEDITOR)
|
||||
Route::post('/upload', [UploadController::class, 'uploadFile'])->name('upload');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue