first change
This commit is contained in:
73
Modules/Template/app/Emails/SendMail.php
Normal file
73
Modules/Template/app/Emails/SendMail.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Template\Emails;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SendMail extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $data;
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*/
|
||||
// public function build(): self
|
||||
// {
|
||||
// return $this->view('mail.template');
|
||||
// }
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: $this->data['subject'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'mail.template'
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the attachments for the message.
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
public function attachments(): array
|
||||
{
|
||||
$attachments = [];
|
||||
if (isset($this->data['documentPaths'])) {
|
||||
foreach ($this->data['documentPaths'] as $path) {
|
||||
$attachments[] = Attachment::fromPath($path);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->data['mergePdf'])) {
|
||||
$attachments[] = Attachment::fromPath($this->data['mergePdf']);
|
||||
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
}
|
0
Modules/Template/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Template/app/Http/Controllers/.gitkeep
Normal file
174
Modules/Template/app/Http/Controllers/TemplateController.php
Normal file
174
Modules/Template/app/Http/Controllers/TemplateController.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Template\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Template\Models\Template;
|
||||
use Modules\Template\Repositories\TemplateInterface;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class TemplateController extends Controller
|
||||
{
|
||||
private $template;
|
||||
|
||||
public function __construct(
|
||||
TemplateInterface $template,
|
||||
) {
|
||||
$this->template = $template;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Template List';
|
||||
|
||||
$model = Template::query()->latest();
|
||||
|
||||
if (request()->ajax()) {
|
||||
return DataTables::eloquent($model)
|
||||
->addIndexColumn()
|
||||
->addColumn('action', 'template::template.partials.action')
|
||||
->rawColumns(['action'])
|
||||
->toJson();
|
||||
}
|
||||
|
||||
return view('template::template.index', $data);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create Template';
|
||||
$data['editable'] = false;
|
||||
$data['fields'] = Template::FIELDS;
|
||||
$data['type'] = Template::TYPE;
|
||||
|
||||
return view('template::template.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$inputData = $request->all();
|
||||
try {
|
||||
$this->template->create($inputData);
|
||||
flash()->success('Template has been created!');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('template.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
abort('404');
|
||||
$data['title'] = 'View Template';
|
||||
$data['template'] = $this->template->findById($id);
|
||||
return view('template::template.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit Template';
|
||||
$data['editable'] = true;
|
||||
$data['template'] = $this->template->findById($id);
|
||||
$data['fields'] = Template::FIELDS;
|
||||
$data['type'] = Template::TYPE;
|
||||
return view('template::template.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$inputData = $request->except(['_method', '_token']);
|
||||
try {
|
||||
|
||||
$this->template->update($id, $inputData);
|
||||
|
||||
flash()->success('Template has been updated!');
|
||||
|
||||
return redirect()->route('template.index')->withSuccess('Template has been updated!');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
return redirect()->back()->withErrors($th->getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$this->template->delete($id);
|
||||
flash()->success('Template has been deleted!');
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
return response()->json(['status' => true, 'message' => 'Template has been deleted!']);
|
||||
|
||||
}
|
||||
public function changeStatus(Request $request)
|
||||
{
|
||||
try {
|
||||
$taskModel = $this->template->findById($request->id);
|
||||
$taskModel->status = $request->status;
|
||||
$taskModel->save();
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'msg' => 'Status Changed',
|
||||
], 200);
|
||||
} catch (\Throwable $th) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'msg' => $th->getMessage(),
|
||||
], 400);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function findByAjax(Request $request)
|
||||
{
|
||||
try {
|
||||
$template = $this->template->findById($request->id);
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => $template,
|
||||
], 200);
|
||||
} catch (\Throwable $th) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'msg' => $th->getMessage(),
|
||||
], 400);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function fileUpload(Request $request)
|
||||
{
|
||||
|
||||
if ($request->hasFile('upload')) {
|
||||
$file = $request->file('upload');
|
||||
$path = 'uploads/ckeditor';
|
||||
$imagePath = uploadImage($file, $path);
|
||||
$CKEditorFuncNum = $request->input('CKEditorFuncNum');
|
||||
$url = asset('storage/' . $imagePath);
|
||||
$response = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url')</script>";
|
||||
echo $response;
|
||||
}
|
||||
}
|
||||
}
|
32
Modules/Template/app/Models/Template.php
Normal file
32
Modules/Template/app/Models/Template.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Template\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Template extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
const FIELDS = [
|
||||
'name', 'email', 'mobile',
|
||||
];
|
||||
|
||||
const TYPE = [
|
||||
'email' => 'Email',
|
||||
// 'sms' => 'SMS',
|
||||
// 'news_letter' => 'News Letter',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
$model->alias = \Str::slug($model->title);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
0
Modules/Template/app/Providers/.gitkeep
Normal file
0
Modules/Template/app/Providers/.gitkeep
Normal file
32
Modules/Template/app/Providers/EventServiceProvider.php
Normal file
32
Modules/Template/app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Template\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event handler mappings for the application.
|
||||
*
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
protected $listen = [];
|
||||
|
||||
/**
|
||||
* Indicates if events should be discovered.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $shouldDiscoverEvents = true;
|
||||
|
||||
/**
|
||||
* Configure the proper event listeners for email verification.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureEmailVerification(): void
|
||||
{
|
||||
|
||||
}
|
||||
}
|
49
Modules/Template/app/Providers/RouteServiceProvider.php
Normal file
49
Modules/Template/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Template\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* 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')->group(module_path('Template', '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Template', '/routes/api.php'));
|
||||
}
|
||||
}
|
123
Modules/Template/app/Providers/TemplateServiceProvider.php
Normal file
123
Modules/Template/app/Providers/TemplateServiceProvider.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Template\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Template\Repositories\TemplateInterface;
|
||||
use Modules\Template\Repositories\TemplateRepository;
|
||||
|
||||
class TemplateServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Template';
|
||||
|
||||
protected string $moduleNameLower = 'template';
|
||||
|
||||
/**
|
||||
* 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->bind(TemplateInterface::class, TemplateRepository::class);
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
$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 . '\\' . ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
|
||||
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
9
Modules/Template/app/Repositories/TemplateInterface.php
Normal file
9
Modules/Template/app/Repositories/TemplateInterface.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Modules\Template\Repositories;
|
||||
|
||||
use App\Interfaces\ModelInterface;
|
||||
|
||||
interface TemplateInterface extends ModelInterface
|
||||
{
|
||||
|
||||
}
|
56
Modules/Template/app/Repositories/TemplateRepository.php
Normal file
56
Modules/Template/app/Repositories/TemplateRepository.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Template\Repositories;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Template\Models\Template;
|
||||
|
||||
class TemplateRepository implements TemplateInterface
|
||||
{
|
||||
public function findAll($request, callable $query = null, bool $paginate = false, int $limit = 10)
|
||||
{
|
||||
return Template::get();
|
||||
}
|
||||
|
||||
public function findById($id, callable $query = null)
|
||||
{
|
||||
return Template::findOrFail($id);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
return Template::where('id', $id)->delete();
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
return Template::create($data);
|
||||
}
|
||||
|
||||
public function update($id, array $newDetails)
|
||||
{
|
||||
return Template::where('id', $id)->update($newDetails);
|
||||
}
|
||||
|
||||
public function pluck(callable $query = null)
|
||||
{
|
||||
return Template::where(['status' => 11])
|
||||
->select('id', 'title', 'alias', 'type')
|
||||
->get()
|
||||
->groupBy('type')
|
||||
->mapWithKeys(function ($templates, $type) {
|
||||
return [
|
||||
$type => $templates->mapWithKeys(function ($template) {
|
||||
return [$template->id => $template->title];
|
||||
}),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function where($filter)
|
||||
{
|
||||
return Template::where($filter);
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user