firstcommit
This commit is contained in:
0
Modules/Page/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Page/app/Http/Controllers/.gitkeep
Normal file
132
Modules/Page/app/Http/Controllers/PageController.php
Normal file
132
Modules/Page/app/Http/Controllers/PageController.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Page\app\Models\Page;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Modules\Page\app\Models\PageMeta;
|
||||
use Modules\Page\app\Repositories\PageRepository;
|
||||
use Modules\Page\app\Services\FileManagementService;
|
||||
use Modules\Page\app\Http\Requests\CreatePageRequest;
|
||||
use Modules\Page\app\Http\Requests\UpdatePageRequest;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
protected $pageRepository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pageRepository = new PageRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pages = $this->pageRepository->allPages();
|
||||
return view('page::index', compact('pages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('page::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(CreatePageRequest $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
$this->pageRepository->storePage($validated);
|
||||
|
||||
toastr()->success('Page created successfully.');
|
||||
|
||||
return redirect()->route('cms.pages.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('page::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($uuid)
|
||||
{
|
||||
$page = $this->pageRepository->findPageByUuid($uuid);
|
||||
|
||||
if (! $page) {
|
||||
toastr()->error('Page not found.');
|
||||
return back();
|
||||
}
|
||||
return view('page::edit', compact('page'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdatePageRequest $request, $uuid): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
$page = $this->pageRepository->updatePage($validated, $uuid);
|
||||
|
||||
if (! $page) {
|
||||
toastr()->error('Page not found !');
|
||||
return back();
|
||||
}
|
||||
|
||||
toastr()->success('Page updated successfully.');
|
||||
|
||||
return redirect()->route('cms.pages.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($uuid)
|
||||
{
|
||||
try {
|
||||
$page = $this->pageRepository->deletePage($uuid);
|
||||
|
||||
if (! $page) {
|
||||
toastr()->error('Page not found.');
|
||||
return back();
|
||||
}
|
||||
DB::commit();
|
||||
toastr()->success('Page deleted successfully.');
|
||||
|
||||
return redirect()->route('cms.pages.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Page/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Page/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Page/app/Http/Requests/.gitkeep
Normal file
0
Modules/Page/app/Http/Requests/.gitkeep
Normal file
36
Modules/Page/app/Http/Requests/CreatePageRequest.php
Normal file
36
Modules/Page/app/Http/Requests/CreatePageRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreatePageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'slug' => 'required|string|unique:pages,slug|max:255',
|
||||
'summary' => 'required|string',
|
||||
'description' => 'sometimes|nullable|string',
|
||||
'display_order' => 'sometimes|nullable|integer',
|
||||
'status' => 'required|in:active,inactive',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif|max:2048', // Adjust the image rules as needed
|
||||
'meta_title' => 'sometimes|nullable|string|max:255',
|
||||
'meta_description' => 'sometimes|nullable|string|max:255',
|
||||
'meta_keywords' => 'sometimes|nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
// return auth()->user()->can('users.create');
|
||||
}
|
||||
}
|
47
Modules/Page/app/Http/Requests/UpdatePageRequest.php
Normal file
47
Modules/Page/app/Http/Requests/UpdatePageRequest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Http\Requests;
|
||||
|
||||
use Modules\Page\app\Models\Page;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdatePageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'slug' => 'sometimes|required|string|max:255|unique:pages,slug,' . Page::where('uuid', request('uuid'))->first()->id,
|
||||
// Exclude the current page by ID
|
||||
'summary' => 'sometimes|nullable|string',
|
||||
'description' => 'sometimes|nullable|string',
|
||||
'display_order' => 'sometimes|nullable|integer',
|
||||
'code' => 'sometimes|nullable|string',
|
||||
'status' => 'sometimes|required|in:active,inactive',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif|max:2048', // Adjust the image rules as needed
|
||||
'meta_title' => 'sometimes|nullable|string|max:255',
|
||||
'meta_description' => 'sometimes|nullable|string|max:255',
|
||||
'meta_keywords' => 'sometimes|nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
// return auth()->user()->can('users.create');
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'slug.unique' => 'The slug is already in use by another page.',
|
||||
// Add custom error messages for other rules as needed
|
||||
];
|
||||
}
|
||||
}
|
0
Modules/Page/app/Models/.gitkeep
Normal file
0
Modules/Page/app/Models/.gitkeep
Normal file
55
Modules/Page/app/Models/Page.php
Normal file
55
Modules/Page/app/Models/Page.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Models;
|
||||
|
||||
use Modules\Post\app\Models\Post;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Page extends Model
|
||||
{
|
||||
// use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'slug',
|
||||
'summary',
|
||||
'description',
|
||||
'display_order',
|
||||
'code',
|
||||
'status',
|
||||
'image',
|
||||
'image_path',
|
||||
];
|
||||
|
||||
public function pageMeta()
|
||||
{
|
||||
return $this->hasOne(PageMeta::class, 'page_id');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function posts()
|
||||
{
|
||||
return $this->hasMany(Post::class);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getFullImageAttribute()
|
||||
{
|
||||
$result = null;
|
||||
|
||||
if($this->image_path) {
|
||||
$result = asset('storage/uploads/' . $this->image_path);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
36
Modules/Page/app/Models/PageMeta.php
Normal file
36
Modules/Page/app/Models/PageMeta.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\Page\Database\factories\PageMetaFactory;
|
||||
|
||||
class PageMeta extends Model
|
||||
{
|
||||
// use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'page_id',
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
'meta_keywords',
|
||||
];
|
||||
|
||||
|
||||
public function page()
|
||||
{
|
||||
return $this->belongsTo(Page::class, 'page_id');
|
||||
}
|
||||
|
||||
protected static function newFactory(): PageMetaFactory
|
||||
{
|
||||
//return PageMetaFactory::new();
|
||||
}
|
||||
}
|
0
Modules/Page/app/Providers/.gitkeep
Normal file
0
Modules/Page/app/Providers/.gitkeep
Normal file
114
Modules/Page/app/Providers/PageServiceProvider.php
Normal file
114
Modules/Page/app/Providers/PageServiceProvider.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class PageServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Page';
|
||||
|
||||
protected string $moduleNameLower = 'page';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
|
||||
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
|
||||
$sourcePath = module_path($this->moduleName, 'resources/views');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
|
||||
|
||||
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.config('modules.paths.generator.component-class.path'));
|
||||
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
|
||||
$paths[] = $path.'/modules/'.$this->moduleNameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
59
Modules/Page/app/Providers/RouteServiceProvider.php
Normal file
59
Modules/Page/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The module namespace to assume when generating URLs to actions.
|
||||
*/
|
||||
protected string $moduleNamespace = 'Modules\Page\app\Http\Controllers';
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')
|
||||
->namespace($this->moduleNamespace)
|
||||
->group(module_path('Page', '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->moduleNamespace)
|
||||
->group(module_path('Page', '/routes/api.php'));
|
||||
}
|
||||
}
|
138
Modules/Page/app/Repositories/PageRepository.php
Normal file
138
Modules/Page/app/Repositories/PageRepository.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Repositories;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Page\app\Models\Page;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Page\app\Models\PageMeta;
|
||||
use Modules\Page\app\Services\FileManagementService;
|
||||
|
||||
class PageRepository
|
||||
{
|
||||
public function allPages($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'ASC'])
|
||||
{
|
||||
return Page::with('pageMeta')->when(array_keys($filter, true), function ($query) use ($filter) {
|
||||
})
|
||||
->orderBy($sort['by'], $sort['sort'])
|
||||
->paginate($perPage ?: env('PAGE_LIMIT', 999));
|
||||
}
|
||||
|
||||
public function findPageByUuid($uuid)
|
||||
{
|
||||
return Page::where('uuid', $uuid)->first();
|
||||
}
|
||||
|
||||
public function storePage(array $validated)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$page = new Page();
|
||||
$page->uuid = Str::uuid();
|
||||
$page->title = $validated['title'];
|
||||
$page->slug = Str::slug($validated['slug']);
|
||||
$page->summary = $validated['summary'];
|
||||
$page->description = $validated['description'];
|
||||
$page->display_order = $validated['display_order'];
|
||||
$page->status = $validated['status'];
|
||||
$page->code = 'normal';
|
||||
$page->save();
|
||||
|
||||
if (isset($validated['image']) && $validated['image']->isValid()) {
|
||||
FileManagementService::storeFile(
|
||||
file: $validated['image'],
|
||||
uploadedFolderName: 'pages',
|
||||
model: $page
|
||||
);
|
||||
}
|
||||
$pageMeta = new PageMeta();
|
||||
$pageMeta->uuid = Str::uuid();
|
||||
$pageMeta->meta_title = $validated['meta_title'];
|
||||
$pageMeta->meta_description = $validated['meta_description'];
|
||||
$pageMeta->meta_keywords = $validated['meta_keywords'];
|
||||
$page->pageMeta()->save($pageMeta);
|
||||
DB::commit();
|
||||
|
||||
return $page;
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollback();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePage($validated, $uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$page = $this->findPageByUuid($uuid);
|
||||
|
||||
|
||||
if (!$page) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//-- Update page
|
||||
$page->title = $validated['title'];
|
||||
$page->slug = Str::slug($validated['slug']);
|
||||
$page->summary = $validated['summary'];
|
||||
$page->description = $validated['description'];
|
||||
$page->display_order = $validated['display_order'];
|
||||
$page->status = $validated['status'];
|
||||
$page->save();
|
||||
|
||||
if (isset($validated['image']) && $validated['image']->isValid()) {
|
||||
FileManagementService::uploadFile(
|
||||
file: $validated['image'],
|
||||
uploadedFolderName: 'pages',
|
||||
filePath: $page->image_path,
|
||||
model: $page
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//-- Create or update page meta
|
||||
$pageMeta = $page->pageMeta()->firstOrNew([]);
|
||||
if (!$pageMeta->exists) {
|
||||
$pageMeta->uuid = Str::uuid();
|
||||
}
|
||||
$pageMeta->meta_title = $validated['meta_title'];
|
||||
$pageMeta->meta_description = $validated['meta_description'];
|
||||
$pageMeta->meta_keywords = $validated['meta_keywords'];
|
||||
$pageMeta->save();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $page;
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollBack();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function deletePage(string $uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$page = $this->findPageByUuid($uuid);
|
||||
if (!$page) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($page->image_path !== null) {
|
||||
FileManagementService::deleteFile($page->image_path);
|
||||
}
|
||||
$page->pageMeta()->delete();
|
||||
$page->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $page;
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
66
Modules/Page/app/Services/FileManagementService.php
Normal file
66
Modules/Page/app/Services/FileManagementService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Page\app\Services;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FileManagementService
|
||||
{
|
||||
//-- store file
|
||||
public static function storeFile($file, $uploadedFolderName, $model)
|
||||
{
|
||||
try {
|
||||
$originalFileName = $file->getClientOriginalName();
|
||||
$modifiedFileName = date('YmdHis') . "_" . uniqid() . "." . $originalFileName;
|
||||
|
||||
$file->storeAs($uploadedFolderName, $modifiedFileName, 'public_uploads'); // This line uses 'public_uploads' disk
|
||||
|
||||
$model->image = $modifiedFileName;
|
||||
$model->image_path = $uploadedFolderName . '/' . $modifiedFileName;
|
||||
$model->save();
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
//-- update file
|
||||
public static function uploadFile($file, $uploadedFolderName ,$filePath, $model)
|
||||
{
|
||||
try {
|
||||
if ($filePath && Storage::disk('public_uploads')->exists($filePath)) {
|
||||
Storage::disk('public_uploads')->delete($filePath);
|
||||
}
|
||||
|
||||
$originalFileName = $file->getClientOriginalName();
|
||||
$modifiedFileName = date('YmdHis') . "_" . uniqid() . "." . $originalFileName;
|
||||
|
||||
$file->storeAs($uploadedFolderName, $modifiedFileName, 'public_uploads'); // This line uses 'public_uploads' disk
|
||||
|
||||
$model->image = $modifiedFileName;
|
||||
$model->image_path = $uploadedFolderName . '/' . $modifiedFileName;
|
||||
|
||||
$model->save();
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-- delete file
|
||||
public static function deleteFile($filePath)
|
||||
{
|
||||
try {
|
||||
if ($filePath && Storage::disk('public_uploads')->exists($filePath)) {
|
||||
Storage::disk('public_uploads')->delete($filePath);
|
||||
} else {
|
||||
toastr()->error('File Not wrong.');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong while deleting the file.');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user