repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 7 values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Email/src/Repositories/EmailRepository.php | packages/Webkul/Email/src/Repositories/EmailRepository.php | <?php
namespace Webkul\Email\Repositories;
use Illuminate\Container\Container;
use Webkul\Core\Eloquent\Repository;
use Webkul\Email\Contracts\Email;
class EmailRepository extends Repository
{
public function __construct(
protected AttachmentRepository $attachmentRepository,
Container $container
) {
parent::__construct($container);
}
/**
* Specify model class name.
*
* @return mixed
*/
public function model()
{
return Email::class;
}
/**
* Create.
*
* @return \Webkul\Email\Contracts\Email
*/
public function create(array $data)
{
$uniqueId = time().'@'.config('mail.domain');
$referenceIds = [];
if (isset($data['parent_id'])) {
$parent = parent::findOrFail($data['parent_id']);
$referenceIds = $parent->reference_ids ?? [];
}
$data = $this->sanitizeEmails(array_merge([
'source' => 'web',
'from' => config('mail.from.address'),
'user_type' => 'admin',
'folders' => isset($data['is_draft']) ? ['draft'] : ['outbox'],
'unique_id' => $uniqueId,
'message_id' => $uniqueId,
'reference_ids' => array_merge($referenceIds, [$uniqueId]),
], $data));
$email = parent::create($data);
$this->attachmentRepository->uploadAttachments($email, $data);
return $email;
}
/**
* Update.
*
* @param int $id
* @param string $attribute
* @return \Webkul\Email\Contracts\Email
*/
public function update(array $data, $id, $attribute = 'id')
{
return parent::update($this->sanitizeEmails($data), $id);
}
/**
* Sanitize emails.
*
* @return array
*/
public function sanitizeEmails(array $data)
{
if (isset($data['reply_to'])) {
$data['reply_to'] = array_values(array_filter($data['reply_to']));
}
if (isset($data['cc'])) {
$data['cc'] = array_values(array_filter($data['cc']));
}
if (isset($data['bcc'])) {
$data['bcc'] = array_values(array_filter($data['bcc']));
}
return $data;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Email/src/Repositories/AttachmentRepository.php | packages/Webkul/Email/src/Repositories/AttachmentRepository.php | <?php
namespace Webkul\Email\Repositories;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Webklex\PHPIMAP\Attachment as ImapAttachment;
use Webkul\Core\Eloquent\Repository;
use Webkul\Email\Contracts\Attachment;
use Webkul\Email\Contracts\Email;
class AttachmentRepository extends Repository
{
/**
* Specify model class name.
*/
public function model(): string
{
return Attachment::class;
}
/**
* Upload attachments.
*/
public function uploadAttachments(Email $email, array $data): void
{
if (
empty($data['attachments'])
|| empty($data['source'])
) {
return;
}
foreach ($data['attachments'] as $attachment) {
$attributes = $this->prepareData($email, $attachment);
if (
! empty($attachment->contentId)
&& $data['source'] === 'email'
) {
$attributes['content_id'] = $attachment->contentId;
}
$this->create($attributes);
}
}
/**
* Get the path for the attachment.
*/
private function prepareData(Email $email, UploadedFile|ImapAttachment $attachment): array
{
if ($attachment instanceof UploadedFile) {
$name = $attachment->getClientOriginalName();
$content = file_get_contents($attachment->getRealPath());
$mimeType = $attachment->getMimeType();
} else {
$name = $attachment->name;
$content = $attachment->content;
$mimeType = $attachment->mime;
}
$path = 'emails/'.$email->id.'/'.$name;
Storage::put($path, $content);
$attributes = [
'path' => $path,
'name' => $name,
'content_type' => $mimeType,
'size' => Storage::size($path),
'email_id' => $email->id,
];
return $attributes;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Email/src/Providers/EmailServiceProvider.php | packages/Webkul/Email/src/Providers/EmailServiceProvider.php | <?php
namespace Webkul\Email\Providers;
use Illuminate\Support\ServiceProvider;
use Webkul\Email\Console\Commands\ProcessInboundEmails;
use Webkul\Email\InboundEmailProcessor\Contracts\InboundEmailProcessor;
use Webkul\Email\InboundEmailProcessor\SendgridEmailProcessor;
use Webkul\Email\InboundEmailProcessor\WebklexImapEmailProcessor;
class EmailServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->loadMigrationsFrom(__DIR__.'/../Database/Migrations');
$this->app->bind(InboundEmailProcessor::class, function ($app) {
$driver = config('mail-receiver.default');
if ($driver === 'sendgrid') {
return $app->make(SendgridEmailProcessor::class);
}
if ($driver === 'webklex-imap') {
return $app->make(WebklexImapEmailProcessor::class);
}
throw new \Exception("Unsupported mail receiver driver [{$driver}].");
});
}
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->registerCommands();
}
/**
* Register the console commands of this package.
*/
protected function registerCommands(): void
{
if ($this->app->runningInConsole()) {
$this->commands([
ProcessInboundEmails::class,
]);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Email/src/Providers/ModuleServiceProvider.php | packages/Webkul/Email/src/Providers/ModuleServiceProvider.php | <?php
namespace Webkul\Email\Providers;
use Webkul\Core\Providers\BaseModuleServiceProvider;
class ModuleServiceProvider extends BaseModuleServiceProvider
{
protected $models = [
\Webkul\Email\Models\Email::class,
\Webkul\Email\Models\Attachment::class,
];
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Traits/LogsActivity.php | packages/Webkul/Activity/src/Traits/LogsActivity.php | <?php
namespace Webkul\Activity\Traits;
use Webkul\Activity\Repositories\ActivityRepository;
use Webkul\Attribute\Contracts\AttributeValue;
use Webkul\Attribute\Repositories\AttributeValueRepository;
trait LogsActivity
{
/**
* The "booted" method of the model.
*/
protected static function booted(): void
{
static::created(function ($model) {
if (! method_exists($model->entity ?? $model, 'activities')) {
return;
}
if (! $model instanceof AttributeValue) {
$activity = app(ActivityRepository::class)->create([
'type' => 'system',
'title' => trans('admin::app.activities.created'),
'is_done' => 1,
'user_id' => auth()->check()
? auth()->id()
: null,
]);
$model->activities()->attach($activity->id);
return;
}
static::logActivity($model);
});
static::updated(function ($model) {
if (! method_exists($model->entity ?? $model, 'activities')) {
return;
}
static::logActivity($model);
});
static::deleting(function ($model) {
if (! method_exists($model->entity ?? $model, 'activities')) {
return;
}
$model->activities()->delete();
});
}
/**
* Create activity.
*/
protected static function logActivity($model)
{
$customAttributes = [];
if (method_exists($model, 'getCustomAttributes')) {
$customAttributes = $model->getCustomAttributes()->pluck('code')->toArray();
}
$updatedAttributes = static::getUpdatedAttributes($model);
foreach ($updatedAttributes as $attributeCode => $attributeData) {
if (in_array($attributeCode, $customAttributes)) {
continue;
}
$attributeCode = $model->attribute?->name ?: $attributeCode;
$activity = app(ActivityRepository::class)->create([
'type' => 'system',
'title' => trans('admin::app.activities.updated', ['attribute' => $attributeCode]),
'is_done' => 1,
'additional' => json_encode([
'attribute' => $attributeCode,
'new' => [
'value' => $attributeData['new'],
'label' => static::getAttributeLabel($attributeData['new'], $model->attribute),
],
'old' => [
'value' => $attributeData['old'],
'label' => static::getAttributeLabel($attributeData['old'], $model->attribute),
],
]),
'user_id' => auth()->id(),
]);
if ($model instanceof AttributeValue) {
$model->entity->activities()->attach($activity->id);
} else {
$model->activities()->attach($activity->id);
}
}
}
/**
* Get attribute label.
*/
protected static function getAttributeLabel($value, $attribute)
{
return app(AttributeValueRepository::class)->getAttributeLabel($value, $attribute);
}
/**
* Create activity.
*/
protected static function getUpdatedAttributes($model)
{
$updatedAttributes = [];
foreach ($model->getDirty() as $key => $value) {
if (in_array($key, [
'id',
'attribute_id',
'entity_id',
'entity_type',
'updated_at',
])) {
continue;
}
$newValue = static::decodeValueIfJson($value);
$oldValue = static::decodeValueIfJson($model->getOriginal($key));
if ($newValue != $oldValue) {
$updatedAttributes[$key] = [
'new' => $newValue,
'old' => $oldValue,
];
}
}
return $updatedAttributes;
}
/**
* Convert value if json.
*/
protected static function decodeValueIfJson($value)
{
if (
! is_array($value)
&& json_decode($value, true)
) {
$value = json_decode($value, true);
}
if (! is_array($value)) {
return $value;
}
static::ksortRecursive($value);
return $value;
}
/**
* Sort array recursively.
*/
protected static function ksortRecursive(&$array)
{
if (! is_array($array)) {
return;
}
ksort($array);
foreach ($array as &$value) {
if (! is_array($value)) {
continue;
}
static::ksortRecursive($value);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Contracts/File.php | packages/Webkul/Activity/src/Contracts/File.php | <?php
namespace Webkul\Activity\Contracts;
interface File {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Contracts/Participant.php | packages/Webkul/Activity/src/Contracts/Participant.php | <?php
namespace Webkul\Activity\Contracts;
interface Participant {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Contracts/Activity.php | packages/Webkul/Activity/src/Contracts/Activity.php | <?php
namespace Webkul\Activity\Contracts;
interface Activity {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Database/Migrations/2021_07_28_142453_create_activity_participants_table.php | packages/Webkul/Activity/src/Database/Migrations/2021_07_28_142453_create_activity_participants_table.php | <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('activity_participants', function (Blueprint $table) {
$table->increments('id');
$table->integer('activity_id')->unsigned();
$table->foreign('activity_id')->references('id')->on('activities')->onDelete('cascade');
$table->integer('user_id')->nullable()->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('person_id')->nullable()->unsigned();
$table->foreign('person_id')->references('id')->on('persons')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('activity_participants');
}
};
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Database/Migrations/2021_05_15_151855_create_activity_files_table.php | packages/Webkul/Activity/src/Database/Migrations/2021_05_15_151855_create_activity_files_table.php | <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('activity_files', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('path');
$table->integer('activity_id')->unsigned();
$table->foreign('activity_id')->references('id')->on('activities')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('activity_files');
}
};
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Database/Migrations/2021_05_12_150329_create_activities_table.php | packages/Webkul/Activity/src/Database/Migrations/2021_05_12_150329_create_activities_table.php | <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('activities', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable();
$table->string('type');
$table->text('comment')->nullable();
$table->json('additional')->nullable();
$table->datetime('schedule_from')->nullable();
$table->datetime('schedule_to')->nullable();
$table->boolean('is_done')->default(0);
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('activities');
}
};
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Database/Migrations/2025_01_17_151632_alter_activities_table.php | packages/Webkul/Activity/src/Database/Migrations/2025_01_17_151632_alter_activities_table.php | <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activities', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->unsignedInteger('user_id')->nullable()->change();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('activities', function (Blueprint $table) {
$tablePrefix = DB::getTablePrefix();
// Disable foreign key checks temporarily.
DB::statement('SET FOREIGN_KEY_CHECKS=0');
// Drop the foreign key constraint using raw SQL.
DB::statement('ALTER TABLE '.$tablePrefix.'activities DROP FOREIGN KEY activities_user_id_foreign');
// Drop the index.
DB::statement('ALTER TABLE '.$tablePrefix.'activities DROP INDEX activities_user_id_foreign');
// Change the column to be non-nullable.
$table->unsignedInteger('user_id')->nullable(false)->change();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
// Re-enable foreign key checks.
DB::statement('SET FOREIGN_KEY_CHECKS=1');
});
}
};
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Database/Migrations/2021_11_17_190943_add_location_column_in_activities_table.php | packages/Webkul/Activity/src/Database/Migrations/2021_11_17_190943_add_location_column_in_activities_table.php | <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activities', function (Blueprint $table) {
$table->string('location')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('activities', function (Blueprint $table) {
$table->dropColumn('location');
});
}
};
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Models/ActivityProxy.php | packages/Webkul/Activity/src/Models/ActivityProxy.php | <?php
namespace Webkul\Activity\Models;
use Konekt\Concord\Proxies\ModelProxy;
class ActivityProxy extends ModelProxy {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Models/File.php | packages/Webkul/Activity/src/Models/File.php | <?php
namespace Webkul\Activity\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Webkul\Activity\Contracts\File as FileContract;
class File extends Model implements FileContract
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'activity_files';
/**
* The attributes that should be appended to the model.
*
* @var array
*/
protected $appends = ['url'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'path',
'activity_id',
];
/**
* Get image url for the product image.
*/
public function url()
{
return Storage::url($this->path);
}
/**
* Get image url for the product image.
*/
public function getUrlAttribute()
{
return $this->url();
}
/**
* Get the activity that owns the file.
*/
public function activity()
{
return $this->belongsTo(ActivityProxy::modelClass());
}
/**
* @return array
*/
public function toArray()
{
$array = parent::toArray();
$array['url'] = $this->url;
return $array;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Models/Participant.php | packages/Webkul/Activity/src/Models/Participant.php | <?php
namespace Webkul\Activity\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Activity\Contracts\Participant as ParticipantContract;
use Webkul\Contact\Models\PersonProxy;
use Webkul\User\Models\UserProxy;
class Participant extends Model implements ParticipantContract
{
public $timestamps = false;
protected $table = 'activity_participants';
protected $with = ['user', 'person'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'activity_id',
'user_id',
'person_id',
];
/**
* Get the activity that owns the participant.
*/
public function activity()
{
return $this->belongsTo(ActivityProxy::modelClass());
}
/**
* Get the user that owns the participant.
*/
public function user()
{
return $this->belongsTo(UserProxy::modelClass());
}
/**
* Get the person that owns the participant.
*/
public function person()
{
return $this->belongsTo(PersonProxy::modelClass());
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Models/Activity.php | packages/Webkul/Activity/src/Models/Activity.php | <?php
namespace Webkul\Activity\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Activity\Contracts\Activity as ActivityContract;
use Webkul\Contact\Models\PersonProxy;
use Webkul\Lead\Models\LeadProxy;
use Webkul\Product\Models\ProductProxy;
use Webkul\User\Models\UserProxy;
use Webkul\Warehouse\Models\WarehouseProxy;
class Activity extends Model implements ActivityContract
{
/**
* Define table name of property
*
* @var string
*/
protected $table = 'activities';
/**
* Define relationships that should be touched on save
*
* @var array
*/
protected $with = ['user'];
/**
* Cast attributes to date time
*
* @var array
*/
protected $casts = [
'schedule_from' => 'datetime',
'schedule_to' => 'datetime',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'type',
'location',
'comment',
'additional',
'schedule_from',
'schedule_to',
'is_done',
'user_id',
];
/**
* Get the user that owns the activity.
*/
public function user()
{
return $this->belongsTo(UserProxy::modelClass());
}
/**
* The participants that belong to the activity.
*/
public function participants()
{
return $this->hasMany(ParticipantProxy::modelClass());
}
/**
* Get the file associated with the activity.
*/
public function files()
{
return $this->hasMany(FileProxy::modelClass(), 'activity_id');
}
/**
* The leads that belong to the activity.
*/
public function leads()
{
return $this->belongsToMany(LeadProxy::modelClass(), 'lead_activities');
}
/**
* The Person that belong to the activity.
*/
public function persons()
{
return $this->belongsToMany(PersonProxy::modelClass(), 'person_activities');
}
/**
* The leads that belong to the activity.
*/
public function products()
{
return $this->belongsToMany(ProductProxy::modelClass(), 'product_activities');
}
/**
* The Warehouse that belong to the activity.
*/
public function warehouses()
{
return $this->belongsToMany(WarehouseProxy::modelClass(), 'warehouse_activities');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Models/FileProxy.php | packages/Webkul/Activity/src/Models/FileProxy.php | <?php
namespace Webkul\Activity\Models;
use Konekt\Concord\Proxies\ModelProxy;
class FileProxy extends ModelProxy {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Models/ParticipantProxy.php | packages/Webkul/Activity/src/Models/ParticipantProxy.php | <?php
namespace Webkul\Activity\Models;
use Konekt\Concord\Proxies\ModelProxy;
class ParticipantProxy extends ModelProxy {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Repositories/FileRepository.php | packages/Webkul/Activity/src/Repositories/FileRepository.php | <?php
namespace Webkul\Activity\Repositories;
use Webkul\Core\Eloquent\Repository;
class FileRepository extends Repository
{
/**
* Specify model class name.
*
* @return mixed
*/
public function model()
{
return \Webkul\Activity\Contracts\File::class;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Repositories/ParticipantRepository.php | packages/Webkul/Activity/src/Repositories/ParticipantRepository.php | <?php
namespace Webkul\Activity\Repositories;
use Webkul\Core\Eloquent\Repository;
class ParticipantRepository extends Repository
{
/**
* Specify Model class name
*
* @return mixed
*/
public function model()
{
return 'Webkul\Activity\Contracts\Participant';
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Repositories/ActivityRepository.php | packages/Webkul/Activity/src/Repositories/ActivityRepository.php | <?php
namespace Webkul\Activity\Repositories;
use Illuminate\Container\Container;
use Webkul\Core\Eloquent\Repository;
class ActivityRepository extends Repository
{
/**
* Create a new repository instance.
*
* @return void
*/
public function __construct(
protected FileRepository $fileRepository,
Container $container
) {
parent::__construct($container);
}
/**
* Specify Model class name
*
* @return mixed
*/
public function model()
{
return 'Webkul\Activity\Contracts\Activity';
}
/**
* Create pipeline.
*
* @return \Webkul\Activity\Contracts\Activity
*/
public function create(array $data)
{
$activity = parent::create($data);
if (isset($data['file'])) {
$this->fileRepository->create([
'name' => $data['name'] ?? $data['file']->getClientOriginalName(),
'path' => $data['file']->store('activities/'.$activity->id),
'activity_id' => $activity->id,
]);
}
if (! isset($data['participants'])) {
return $activity;
}
foreach ($data['participants']['users'] ?? [] as $userId) {
$activity->participants()->create([
'user_id' => $userId,
]);
}
foreach ($data['participants']['persons'] ?? [] as $personId) {
$activity->participants()->create([
'person_id' => $personId,
]);
}
return $activity;
}
/**
* Update pipeline.
*
* @param int $id
* @param string $attribute
* @return \Webkul\Activity\Contracts\Activity
*/
public function update(array $data, $id, $attribute = 'id')
{
$activity = parent::update($data, $id);
if (isset($data['participants'])) {
$activity->participants()->delete();
foreach ($data['participants']['users'] ?? [] as $userId) {
/**
* In some cases, the component exists in an HTML form, and traditional HTML does not send an empty array.
* Therefore, we need to check for an empty string.
* This scenario occurs only when all participants are removed.
*/
if (empty($userId)) {
break;
}
$activity->participants()->create([
'user_id' => $userId,
]);
}
foreach ($data['participants']['persons'] ?? [] as $personId) {
/**
* In some cases, the component exists in an HTML form, and traditional HTML does not send an empty array.
* Therefore, we need to check for an empty string.
* This scenario occurs only when all participants are removed.
*/
if (empty($personId)) {
break;
}
$activity->participants()->create([
'person_id' => $personId,
]);
}
}
return $activity;
}
/**
* @param string $dateRange
* @return mixed
*/
public function getActivities($dateRange)
{
$tablePrefix = \DB::getTablePrefix();
return $this->select(
'activities.id',
'activities.created_at',
'activities.title',
'activities.schedule_from as start',
'activities.schedule_to as end',
'users.name as user_name',
)
->addSelect(\DB::raw('IF('.$tablePrefix.'activities.is_done, "done", "") as class'))
->leftJoin('activity_participants', 'activities.id', '=', 'activity_participants.activity_id')
->leftJoin('users', 'activities.user_id', '=', 'users.id')
->whereIn('type', ['call', 'meeting', 'lunch'])
->whereBetween('activities.schedule_from', $dateRange)
->where(function ($query) {
if ($userIds = bouncer()->getAuthorizedUserIds()) {
$query->whereIn('activities.user_id', $userIds)
->orWhereIn('activity_participants.user_id', $userIds);
}
})
->distinct()
->get();
}
/**
* @param string $startFrom
* @param string $endFrom
* @param array $participants
* @param int $id
* @return bool
*/
public function isDurationOverlapping($startFrom, $endFrom, $participants, $id)
{
$queryBuilder = $this->leftJoin('activity_participants', 'activities.id', '=', 'activity_participants.activity_id')
->where(function ($query) use ($startFrom, $endFrom) {
$query->where([
['activities.schedule_from', '<=', $startFrom],
['activities.schedule_to', '>=', $startFrom],
])->orWhere([
['activities.schedule_from', '>=', $startFrom],
['activities.schedule_from', '<=', $endFrom],
]);
})
->where(function ($query) use ($participants) {
if (is_null($participants)) {
return;
}
if (isset($participants['users'])) {
$query->orWhereIn('activity_participants.user_id', $participants['users']);
}
if (isset($participants['persons'])) {
$query->orWhereIn('activity_participants.person_id', $participants['persons']);
}
})
->groupBy('activities.id');
if (! is_null($id)) {
$queryBuilder->where('activities.id', '!=', $id);
}
return $queryBuilder->count() ? true : false;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Providers/ModuleServiceProvider.php | packages/Webkul/Activity/src/Providers/ModuleServiceProvider.php | <?php
namespace Webkul\Activity\Providers;
use Webkul\Core\Providers\BaseModuleServiceProvider;
class ModuleServiceProvider extends BaseModuleServiceProvider
{
protected $models = [
\Webkul\Activity\Models\Activity::class,
\Webkul\Activity\Models\File::class,
\Webkul\Activity\Models\Participant::class,
];
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Activity/src/Providers/ActivityServiceProvider.php | packages/Webkul/Activity/src/Providers/ActivityServiceProvider.php | <?php
namespace Webkul\Activity\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
class ActivityServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot(Router $router)
{
$this->loadMigrationsFrom(__DIR__.'/../Database/Migrations');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Tag/src/Contracts/Tag.php | packages/Webkul/Tag/src/Contracts/Tag.php | <?php
namespace Webkul\Tag\Contracts;
interface Tag {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Tag/src/Database/Migrations/2021_05_20_141230_create_tags_table.php | packages/Webkul/Tag/src/Database/Migrations/2021_05_20_141230_create_tags_table.php | <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('color')->nullable();
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tags');
}
};
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Tag/src/Models/Tag.php | packages/Webkul/Tag/src/Models/Tag.php | <?php
namespace Webkul\Tag\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Tag\Contracts\Tag as TagContract;
use Webkul\User\Models\UserProxy;
class Tag extends Model implements TagContract
{
protected $table = 'tags';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'color',
'user_id',
];
/**
* Get the user that owns the tag.
*/
public function user()
{
return $this->belongsTo(UserProxy::modelClass());
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Tag/src/Models/TagProxy.php | packages/Webkul/Tag/src/Models/TagProxy.php | <?php
namespace Webkul\Tag\Models;
use Konekt\Concord\Proxies\ModelProxy;
class TagProxy extends ModelProxy {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Tag/src/Repositories/TagRepository.php | packages/Webkul/Tag/src/Repositories/TagRepository.php | <?php
namespace Webkul\Tag\Repositories;
use Webkul\Core\Eloquent\Repository;
class TagRepository extends Repository
{
/**
* Searchable fields
*/
protected $fieldSearchable = [
'name',
'color',
'user_id',
];
/**
* Specify Model class name
*
* @return mixed
*/
public function model()
{
return 'Webkul\Tag\Contracts\Tag';
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Tag/src/Providers/TagServiceProvider.php | packages/Webkul/Tag/src/Providers/TagServiceProvider.php | <?php
namespace Webkul\Tag\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
class TagServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot(Router $router)
{
$this->loadMigrationsFrom(__DIR__.'/../Database/Migrations');
}
/**
* Register services.
*
* @return void
*/
public function register() {}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Tag/src/Providers/ModuleServiceProvider.php | packages/Webkul/Tag/src/Providers/ModuleServiceProvider.php | <?php
namespace Webkul\Tag\Providers;
use Webkul\Core\Providers\BaseModuleServiceProvider;
class ModuleServiceProvider extends BaseModuleServiceProvider
{
protected $models = [
\Webkul\Tag\Models\Tag::class,
];
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Bouncer.php | packages/Webkul/Admin/src/Bouncer.php | <?php
namespace Webkul\Admin;
use Webkul\User\Repositories\UserRepository;
class Bouncer
{
/**
* Checks if user allowed or not for certain action
*
* @param string $permission
* @return void
*/
public function hasPermission($permission)
{
if (auth()->guard('user')->check() && auth()->guard('user')->user()->role->permission_type == 'all') {
return true;
} else {
if (! auth()->guard('user')->check() || ! auth()->guard('user')->user()->hasPermission($permission)) {
return false;
}
}
return true;
}
/**
* Checks if user allowed or not for certain action
*
* @param string $permission
* @return void
*/
public static function allow($permission)
{
if (! auth()->guard('user')->check() || ! auth()->guard('user')->user()->hasPermission($permission)) {
abort(401, 'This action is unauthorized');
}
}
/**
* This function will return user ids of current user's groups
*
* @return array|null
*/
public function getAuthorizedUserIds()
{
$user = auth()->guard('user')->user();
if ($user->view_permission == 'global') {
return null;
}
if ($user->view_permission == 'group') {
return app(UserRepository::class)->getCurrentUserGroupsUserIds();
} else {
return [$user->id];
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Requests/WebhookRequest.php | packages/Webkul/Admin/src/Requests/WebhookRequest.php | <?php
namespace Webkul\Admin\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class WebhookRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules()
{
return [
'name' => 'required|string|max:255',
'entity_type' => 'required|string|max:255',
'description' => 'nullable|string|max:255',
'method' => 'required|string|max:255',
'end_point' => 'required|string|max:255',
'query_params' => 'nullable',
'headers' => 'nullable',
'payload_type' => [
'required',
'string',
'max:255',
Rule::in(['default', 'x-www-form-urlencoded', 'raw']),
],
'raw_payload_type' => [
'string',
'max:255',
Rule::in(['json', 'text']),
],
'payload' => 'nullable',
];
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Exceptions/Handler.php | packages/Webkul/Admin/src/Exceptions/Handler.php | <?php
namespace Webkul\Admin\Exceptions;
use App\Exceptions\Handler as AppExceptionHandler;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Validation\ValidationException;
use PDOException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Throwable;
class Handler extends AppExceptionHandler
{
/**
* Json error messages.
*
* @var array
*/
protected $jsonErrorMessages = [];
/**
* Create handler instance.
*
* @return void
*/
public function __construct(Container $container)
{
parent::__construct($container);
$this->jsonErrorMessages = [
'404' => trans('admin::app.common.resource-not-found'),
'403' => trans('admin::app.common.forbidden-error'),
'401' => trans('admin::app.common.unauthenticated'),
'500' => trans('admin::app.common.internal-server-error'),
];
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function render($request, Throwable $exception)
{
if (! config('app.debug')) {
return $this->renderCustomResponse($exception);
}
return parent::render($request, $exception);
}
/**
* Convert an authentication exception into a response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['message' => $this->jsonErrorMessages[401]], 401);
}
return redirect()->guest(route('customer.session.index'));
}
/**
* Render custom HTTP response.
*
* @return \Illuminate\Http\Response|null
*/
private function renderCustomResponse(Throwable $exception)
{
if ($exception instanceof HttpException) {
$statusCode = in_array($exception->getStatusCode(), [401, 403, 404, 503])
? $exception->getStatusCode()
: 500;
return $this->response($statusCode);
}
if ($exception instanceof ValidationException) {
return parent::render(request(), $exception);
}
if ($exception instanceof ModelNotFoundException) {
return $this->response(404);
} elseif ($exception instanceof PDOException || $exception instanceof \ParseError) {
return $this->response(500);
} else {
return $this->response(500);
}
}
/**
* Return custom response.
*
* @param string $path
* @param string $errorCode
* @return mixed
*/
private function response($errorCode)
{
if (request()->expectsJson()) {
return response()->json([
'message' => isset($this->jsonErrorMessages[$errorCode])
? $this->jsonErrorMessages[$errorCode]
: trans('admin::app.common.something-went-wrong'),
], $errorCode);
}
return response()->view('admin::errors.index', compact('errorCode'));
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Dashboard.php | packages/Webkul/Admin/src/Helpers/Dashboard.php | <?php
namespace Webkul\Admin\Helpers;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Webkul\Admin\Helpers\Reporting\Activity;
use Webkul\Admin\Helpers\Reporting\Lead;
use Webkul\Admin\Helpers\Reporting\Organization;
use Webkul\Admin\Helpers\Reporting\Person;
use Webkul\Admin\Helpers\Reporting\Product;
use Webkul\Admin\Helpers\Reporting\Quote;
class Dashboard
{
/**
* Create a controller instance.
*
* @return void
*/
public function __construct(
protected Lead $leadReporting,
protected Activity $activityReporting,
protected Product $productReporting,
protected Person $personReporting,
protected Organization $organizationReporting,
protected Quote $quoteReporting,
) {}
/**
* Returns the overall revenue statistics.
*/
public function getRevenueStats(): array
{
return [
'total_won_revenue' => $this->leadReporting->getTotalWonLeadValueProgress(),
'total_lost_revenue' => $this->leadReporting->getTotalLostLeadValueProgress(),
];
}
/**
* Returns the overall statistics.
*/
public function getOverAllStats(): array
{
return [
'total_leads' => $this->leadReporting->getTotalLeadsProgress(),
'average_lead_value' => $this->leadReporting->getAverageLeadValueProgress(),
'average_leads_per_day' => $this->leadReporting->getAverageLeadsPerDayProgress(),
'total_quotations' => $this->quoteReporting->getTotalQuotesProgress(),
'total_persons' => $this->personReporting->getTotalPersonsProgress(),
'total_organizations' => $this->organizationReporting->getTotalOrganizationsProgress(),
];
}
/**
* Returns leads statistics.
*/
public function getTotalLeadsStats(): array
{
return [
'all' => [
'over_time' => $this->leadReporting->getTotalLeadsOverTime(),
],
'won' => [
'over_time' => $this->leadReporting->getTotalWonLeadsOverTime(),
],
'lost' => [
'over_time' => $this->leadReporting->getTotalLostLeadsOverTime(),
],
];
}
/**
* Returns leads revenue statistics by sources.
*/
public function getLeadsStatsBySources(): mixed
{
return $this->leadReporting->getTotalWonLeadValueBySources();
}
/**
* Returns leads revenue statistics by types.
*/
public function getLeadsStatsByTypes(): mixed
{
return $this->leadReporting->getTotalWonLeadValueByTypes();
}
/**
* Returns open leads statistics by states.
*/
public function getOpenLeadsByStates(): mixed
{
return $this->leadReporting->getOpenLeadsByStates();
}
/**
* Returns top selling products statistics.
*/
public function getTopSellingProducts(): Collection
{
return $this->productReporting->getTopSellingProductsByRevenue(5);
}
/**
* Returns top selling products statistics.
*/
public function getTopPersons(): Collection
{
return $this->personReporting->getTopCustomersByRevenue(5);
}
/**
* Get the start date.
*
* @return \Carbon\Carbon
*/
public function getStartDate(): Carbon
{
return $this->leadReporting->getStartDate();
}
/**
* Get the end date.
*
* @return \Carbon\Carbon
*/
public function getEndDate(): Carbon
{
return $this->leadReporting->getEndDate();
}
/**
* Returns date range
*/
public function getDateRange(): string
{
return $this->getStartDate()->format('d M').' - '.$this->getEndDate()->format('d M');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Reporting/Organization.php | packages/Webkul/Admin/src/Helpers/Reporting/Organization.php | <?php
namespace Webkul\Admin\Helpers\Reporting;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Webkul\Contact\Repositories\OrganizationRepository;
class Organization extends AbstractReporting
{
/**
* Create a helper instance.
*
* @return void
*/
public function __construct(protected OrganizationRepository $organizationRepository)
{
parent::__construct();
}
/**
* Retrieves total organizations and their progress.
*/
public function getTotalOrganizationsProgress(): array
{
return [
'previous' => $previous = $this->getTotalOrganizations($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getTotalOrganizations($this->startDate, $this->endDate),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves total organizations by date
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getTotalOrganizations($startDate, $endDate): int
{
return $this->organizationRepository
->resetModel()
->whereBetween('created_at', [$startDate, $endDate])
->count();
}
/**
* Gets top customers by revenue.
*
* @param int $limit
*/
public function getTopOrganizationsByRevenue($limit = null): Collection
{
$tablePrefix = DB::getTablePrefix();
$items = $this->organizationRepository
->resetModel()
->leftJoin('persons', 'organizations.id', '=', 'persons.organization_id')
->leftJoin('leads', 'persons.id', '=', 'leads.person_id')
->select('*', 'persons.id as id')
->addSelect(DB::raw('SUM('.$tablePrefix.'leads.lead_value) as revenue'))
->whereBetween('leads.closed_at', [$this->startDate, $this->endDate])
->having(DB::raw('SUM('.$tablePrefix.'leads.lead_value)'), '>', 0)
->groupBy('organization_id')
->orderBy('revenue', 'DESC')
->limit($limit)
->get();
$items = $items->map(function ($item) {
return [
'id' => $item->id,
'name' => $item->name,
'revenue' => $item->revenue,
'formatted_revenue' => core()->formatBasePrice($item->revenue),
];
});
return $items;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Reporting/Product.php | packages/Webkul/Admin/src/Helpers/Reporting/Product.php | <?php
namespace Webkul\Admin\Helpers\Reporting;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Webkul\Lead\Repositories\ProductRepository;
class Product extends AbstractReporting
{
/**
* Create a helper instance.
*
* @return void
*/
public function __construct(
protected ProductRepository $productRepository
) {
parent::__construct();
}
/**
* Gets top-selling products by revenue.
*
* @param int $limit
*/
public function getTopSellingProductsByRevenue($limit = null): Collection
{
$tablePrefix = DB::getTablePrefix();
$items = $this->productRepository
->resetModel()
->with('product')
->leftJoin('leads', 'lead_products.lead_id', '=', 'leads.id')
->leftJoin('products', 'lead_products.product_id', '=', 'products.id')
->select('*')
->addSelect(DB::raw('SUM('.$tablePrefix.'lead_products.amount) as revenue'))
->whereBetween('leads.closed_at', [$this->startDate, $this->endDate])
->having(DB::raw('SUM('.$tablePrefix.'lead_products.amount)'), '>', 0)
->groupBy('product_id')
->orderBy('revenue', 'DESC')
->limit($limit)
->get();
$items = $items->map(function ($item) {
return [
'id' => $item->product_id,
'name' => $item->name,
'price' => $item->product?->price,
'formatted_price' => core()->formatBasePrice($item->price),
'revenue' => $item->revenue,
'formatted_revenue' => core()->formatBasePrice($item->revenue),
];
});
return $items;
}
/**
* Gets top-selling products by quantity.
*
* @param int $limit
*/
public function getTopSellingProductsByQuantity($limit = null): Collection
{
$tablePrefix = DB::getTablePrefix();
$items = $this->productRepository
->resetModel()
->with('product')
->leftJoin('leads', 'lead_products.lead_id', '=', 'leads.id')
->leftJoin('products', 'lead_products.product_id', '=', 'products.id')
->select('*')
->addSelect(DB::raw('SUM('.$tablePrefix.'lead_products.quantity) as total_qty_ordered'))
->whereBetween('leads.closed_at', [$this->startDate, $this->endDate])
->having(DB::raw('SUM('.$tablePrefix.'lead_products.quantity)'), '>', 0)
->groupBy('product_id')
->orderBy('total_qty_ordered', 'DESC')
->limit($limit)
->get();
$items = $items->map(function ($item) {
return [
'id' => $item->product_id,
'name' => $item->name,
'price' => $item->product?->price,
'formatted_price' => core()->formatBasePrice($item->price),
'total_qty_ordered' => $item->total_qty_ordered,
];
});
return $items;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Reporting/AbstractReporting.php | packages/Webkul/Admin/src/Helpers/Reporting/AbstractReporting.php | <?php
namespace Webkul\Admin\Helpers\Reporting;
use Carbon\CarbonPeriod;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
abstract class AbstractReporting
{
/**
* The starting date for a given period.
*/
protected Carbon $startDate;
/**
* The ending date for a given period.
*/
protected Carbon $endDate;
/**
* The starting date for the previous period.
*/
protected Carbon $lastStartDate;
/**
* The ending date for the previous period.
*/
protected Carbon $lastEndDate;
/**
* Create a helper instance.
*
* @return void
*/
public function __construct()
{
$this->setStartDate(request()->date('start'));
$this->setEndDate(request()->date('end'));
}
/**
* Set the start date or default to 30 days ago if not provided.
*
* @param \Carbon\Carbon|null $startDate
* @return void
*/
public function setStartDate(?Carbon $startDate = null): self
{
$this->startDate = $startDate ? $startDate->startOfDay() : now()->subDays(30)->startOfDay();
$this->setLastStartDate();
return $this;
}
/**
* Sets the end date to the provided date's end of day, or to the current
* date if not provided or if the provided date is in the future.
*
* @param \Carbon\Carbon|null $endDate
* @return void
*/
public function setEndDate(?Carbon $endDate = null): self
{
$this->endDate = ($endDate && $endDate->endOfDay() <= now()) ? $endDate->endOfDay() : now();
$this->setLastEndDate();
return $this;
}
/**
* Get the start date.
*
* @return \Carbon\Carbon
*/
public function getStartDate(): Carbon
{
return $this->startDate;
}
/**
* Get the end date.
*
* @return \Carbon\Carbon
*/
public function getEndDate(): Carbon
{
return $this->endDate;
}
/**
* Sets the start date for the last period.
*/
private function setLastStartDate(): void
{
if (! isset($this->startDate)) {
$this->setStartDate(request()->date('start'));
}
if (! isset($this->endDate)) {
$this->setEndDate(request()->date('end'));
}
$this->lastStartDate = $this->startDate->clone()->subDays($this->startDate->diffInDays($this->endDate));
}
/**
* Sets the end date for the last period.
*/
private function setLastEndDate(): void
{
$this->lastEndDate = $this->startDate->clone();
}
/**
* Get the last start date.
*
* @return \Carbon\Carbon
*/
public function getLastStartDate(): Carbon
{
return $this->lastStartDate;
}
/**
* Get the last end date.
*
* @return \Carbon\Carbon
*/
public function getLastEndDate(): Carbon
{
return $this->lastEndDate;
}
/**
* Calculate the percentage change between previous and current values.
*
* @param float|int $previous
* @param float|int $current
*/
public function getPercentageChange($previous, $current): float|int
{
if (! $previous) {
return $current ? 100 : 0;
}
return ($current - $previous) / $previous * 100;
}
/**
* Returns time intervals.
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
* @param string $period
* @return array
*/
public function getTimeInterval($startDate, $endDate, $dateColumn, $period)
{
if ($period == 'auto') {
$totalMonths = $startDate->diffInMonths($endDate) + 1;
/**
* If the difference between the start and end date is more than 5 months
*/
$intervals = $this->getMonthsInterval($startDate, $endDate);
if (! empty($intervals)) {
return [
'group_column' => "MONTH($dateColumn)",
'intervals' => $intervals,
];
}
/**
* If the difference between the start and end date is more than 6 weeks
*/
$intervals = $this->getWeeksInterval($startDate, $endDate);
if (! empty($intervals)) {
return [
'group_column' => "WEEK($dateColumn)",
'intervals' => $intervals,
];
}
/**
* If the difference between the start and end date is less than 6 weeks
*/
return [
'group_column' => "DAYOFYEAR($dateColumn)",
'intervals' => $this->getDaysInterval($startDate, $endDate),
];
} else {
$datePeriod = CarbonPeriod::create($this->startDate, "1 $period", $this->endDate);
if ($period == 'year') {
$formatter = '?';
} elseif ($period == 'month') {
$formatter = '?-?';
} else {
$formatter = '?-?-?';
}
$groupColumn = 'DATE_FORMAT('.$dateColumn.', "'.Str::replaceArray('?', ['%Y', '%m', '%d'], $formatter).'")';
$intervals = [];
foreach ($datePeriod as $date) {
$formattedDate = $date->format(Str::replaceArray('?', ['Y', 'm', 'd'], $formatter));
$intervals[] = [
'filter' => $formattedDate,
'start' => $formattedDate,
];
}
return [
'group_column' => $groupColumn,
'intervals' => $intervals,
];
}
}
/**
* Returns time intervals.
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
* @return array
*/
public function getMonthsInterval($startDate, $endDate)
{
$intervals = [];
$totalMonths = $startDate->diffInMonths($endDate) + 1;
/**
* If the difference between the start and end date is less than 5 months
*/
if ($totalMonths <= 5) {
return $intervals;
}
for ($i = 0; $i < $totalMonths; $i++) {
$intervalStartDate = clone $startDate;
$intervalStartDate->addMonths($i);
$start = $intervalStartDate->startOfDay();
$end = ($totalMonths - 1 == $i)
? $endDate
: $intervalStartDate->addMonth()->subDay()->endOfDay();
$intervals[] = [
'filter' => $start->month,
'start' => $start->format('d M'),
'end' => $end->format('d M'),
];
}
return $intervals;
}
/**
* Returns time intervals.
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
* @return array
*/
public function getWeeksInterval($startDate, $endDate)
{
$intervals = [];
$startWeekDay = Carbon::createFromTimeString(core()->xWeekRange($startDate, 0).' 00:00:01');
$endWeekDay = Carbon::createFromTimeString(core()->xWeekRange($endDate, 1).' 23:59:59');
$totalWeeks = $startWeekDay->diffInWeeks($endWeekDay);
/**
* If the difference between the start and end date is less than 6 weeks
*/
if ($totalWeeks <= 6) {
return $intervals;
}
for ($i = 0; $i < $totalWeeks; $i++) {
$intervalStartDate = clone $startDate;
$intervalStartDate->addWeeks($i);
$start = $i == 0
? $startDate
: Carbon::createFromTimeString(core()->xWeekRange($intervalStartDate, 0).' 00:00:01');
$end = ($totalWeeks - 1 == $i)
? $endDate
: Carbon::createFromTimeString(core()->xWeekRange($intervalStartDate->subDay(), 1).' 23:59:59');
$intervals[] = [
'filter' => $start->week,
'start' => $start->format('d M'),
'end' => $end->format('d M'),
];
}
return $intervals;
}
/**
* Returns time intervals.
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
* @return array
*/
public function getDaysInterval($startDate, $endDate)
{
$intervals = [];
$totalDays = $startDate->diffInDays($endDate) + 1;
for ($i = 0; $i < $totalDays; $i++) {
$intervalStartDate = clone $startDate;
$intervalStartDate->addDays($i);
$intervals[] = [
'filter' => $intervalStartDate->dayOfYear,
'start' => $intervalStartDate->startOfDay()->format('d M'),
'end' => $intervalStartDate->endOfDay()->format('d M'),
];
}
return $intervals;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Reporting/Lead.php | packages/Webkul/Admin/src/Helpers/Reporting/Lead.php | <?php
namespace Webkul\Admin\Helpers\Reporting;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Webkul\Lead\Repositories\LeadRepository;
use Webkul\Lead\Repositories\StageRepository;
class Lead extends AbstractReporting
{
/**
* The channel ids.
*/
protected array $stageIds;
/**
* The all stage ids.
*/
protected array $allStageIds;
/**
* The won stage ids.
*/
protected array $wonStageIds;
/**
* The lost stage ids.
*/
protected array $lostStageIds;
/**
* Create a helper instance.
*
* @return void
*/
public function __construct(
protected LeadRepository $leadRepository,
protected StageRepository $stageRepository
) {
$this->allStageIds = $this->stageRepository->pluck('id')->toArray();
$this->wonStageIds = $this->stageRepository->where('code', 'won')->pluck('id')->toArray();
$this->lostStageIds = $this->stageRepository->where('code', 'lost')->pluck('id')->toArray();
parent::__construct();
}
/**
* Returns current customers over time
*
* @param string $period
*/
public function getTotalLeadsOverTime($period = 'auto'): array
{
$this->stageIds = $this->allStageIds;
$period = $this->determinePeriod($period);
return $this->getOverTimeStats($this->startDate, $this->endDate, 'leads.id', 'created_at', $period);
}
/**
* Returns current customers over time
*
* @param string $period
*/
public function getTotalWonLeadsOverTime($period = 'auto'): array
{
$this->stageIds = $this->wonStageIds;
$period = $this->determinePeriod($period);
return $this->getOverTimeStats($this->startDate, $this->endDate, 'leads.id', 'closed_at', $period);
}
/**
* Returns current customers over time
*
* @param string $period
*/
public function getTotalLostLeadsOverTime($period = 'auto'): array
{
$this->stageIds = $this->lostStageIds;
$period = $this->determinePeriod($period);
return $this->getOverTimeStats($this->startDate, $this->endDate, 'leads.id', 'closed_at', $period);
}
/**
* Determine the appropriate period based on date range
*
* @param string $period
*/
protected function determinePeriod($period = 'auto'): string
{
if ($period !== 'auto') {
return $period;
}
$diffInDays = $this->startDate->diffInDays($this->endDate);
$diffInMonths = $this->startDate->diffInMonths($this->endDate);
$diffInYears = $this->startDate->diffInYears($this->endDate);
if ($diffInYears > 3) {
return 'year';
} elseif ($diffInMonths > 6) {
return 'month';
} elseif ($diffInDays > 60) {
return 'week';
} else {
return 'day';
}
}
/**
* Retrieves total leads and their progress.
*/
public function getTotalLeadsProgress(): array
{
return [
'previous' => $previous = $this->getTotalLeads($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getTotalLeads($this->startDate, $this->endDate),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves total leads by date
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getTotalLeads($startDate, $endDate): int
{
return $this->leadRepository
->resetModel()
->whereBetween('created_at', [$startDate, $endDate])
->count();
}
/**
* Retrieves average leads per day and their progress.
*/
public function getAverageLeadsPerDayProgress(): array
{
return [
'previous' => $previous = $this->getAverageLeadsPerDay($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getAverageLeadsPerDay($this->startDate, $this->endDate),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves average leads per day
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getAverageLeadsPerDay($startDate, $endDate): float
{
$days = $startDate->diffInDays($endDate);
if ($days == 0) {
return 0;
}
return $this->getTotalLeads($startDate, $endDate) / $days;
}
/**
* Retrieves total lead value and their progress.
*/
public function getTotalLeadValueProgress(): array
{
return [
'previous' => $previous = $this->getTotalLeadValue($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getTotalLeadValue($this->startDate, $this->endDate),
'formatted_total' => core()->formatBasePrice($current),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves total lead value
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getTotalLeadValue($startDate, $endDate): float
{
return $this->leadRepository
->resetModel()
->whereBetween('created_at', [$startDate, $endDate])
->sum('lead_value');
}
/**
* Retrieves average lead value and their progress.
*/
public function getAverageLeadValueProgress(): array
{
return [
'previous' => $previous = $this->getAverageLeadValue($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getAverageLeadValue($this->startDate, $this->endDate),
'formatted_total' => core()->formatBasePrice($current),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves average lead value
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getAverageLeadValue($startDate, $endDate): float
{
return $this->leadRepository
->resetModel()
->whereBetween('created_at', [$startDate, $endDate])
->avg('lead_value') ?? 0;
}
/**
* Retrieves total won lead value and their progress.
*/
public function getTotalWonLeadValueProgress(): array
{
return [
'previous' => $previous = $this->getTotalWonLeadValue($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getTotalWonLeadValue($this->startDate, $this->endDate),
'formatted_total' => core()->formatBasePrice($current),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves average won lead value
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
* @return array
*/
public function getTotalWonLeadValue($startDate, $endDate): ?float
{
return $this->leadRepository
->resetModel()
->whereIn('lead_pipeline_stage_id', $this->wonStageIds)
->whereBetween('created_at', [$startDate, $endDate])
->sum('lead_value');
}
/**
* Retrieves average lost lead value and their progress.
*/
public function getTotalLostLeadValueProgress(): array
{
return [
'previous' => $previous = $this->getTotalLostLeadValue($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getTotalLostLeadValue($this->startDate, $this->endDate),
'formatted_total' => core()->formatBasePrice($current),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves average lost lead value
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
* @return array
*/
public function getTotalLostLeadValue($startDate, $endDate): ?float
{
return $this->leadRepository
->resetModel()
->whereIn('lead_pipeline_stage_id', $this->lostStageIds)
->whereBetween('created_at', [$startDate, $endDate])
->sum('lead_value');
}
/**
* Retrieves total lead value by sources.
*/
public function getTotalWonLeadValueBySources()
{
return $this->leadRepository
->resetModel()
->select(
'lead_sources.name',
DB::raw('SUM(lead_value) as total')
)
->leftJoin('lead_sources', 'leads.lead_source_id', '=', 'lead_sources.id')
->whereIn('lead_pipeline_stage_id', $this->wonStageIds)
->whereBetween('leads.created_at', [$this->startDate, $this->endDate])
->groupBy('lead_source_id')
->get();
}
/**
* Retrieves total lead value by types.
*/
public function getTotalWonLeadValueByTypes()
{
return $this->leadRepository
->resetModel()
->select(
'lead_types.name',
DB::raw('SUM(lead_value) as total')
)
->leftJoin('lead_types', 'leads.lead_type_id', '=', 'lead_types.id')
->whereIn('lead_pipeline_stage_id', $this->wonStageIds)
->whereBetween('leads.created_at', [$this->startDate, $this->endDate])
->groupBy('lead_type_id')
->get();
}
/**
* Retrieves open leads by states.
*/
public function getOpenLeadsByStates()
{
return $this->leadRepository
->resetModel()
->select(
'lead_pipeline_stages.name',
DB::raw('COUNT(lead_value) as total')
)
->leftJoin('lead_pipeline_stages', 'leads.lead_pipeline_stage_id', '=', 'lead_pipeline_stages.id')
->whereNotIn('lead_pipeline_stage_id', $this->wonStageIds)
->whereNotIn('lead_pipeline_stage_id', $this->lostStageIds)
->whereBetween('leads.created_at', [$this->startDate, $this->endDate])
->groupBy('lead_pipeline_stage_id')
->orderByDesc('total')
->get();
}
/**
* Returns over time stats.
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
* @param string $valueColumn
* @param string $dateColumn
* @param string $period
*/
public function getOverTimeStats($startDate, $endDate, $valueColumn, $dateColumn = 'created_at', $period = 'auto'): array
{
$period = $this->determinePeriod($period);
$intervals = $this->generateTimeIntervals($startDate, $endDate, $period);
$groupColumn = $this->getGroupColumn($dateColumn, $period);
$query = $this->leadRepository
->resetModel()
->select(
DB::raw("$groupColumn AS date"),
DB::raw('COUNT(DISTINCT id) AS count'),
DB::raw('SUM('.\DB::getTablePrefix()."$valueColumn) AS total")
)
->whereIn('lead_pipeline_stage_id', $this->stageIds)
->whereBetween($dateColumn, [$startDate, $endDate])
->groupBy(DB::raw($groupColumn))
->orderBy(DB::raw($groupColumn));
$results = $query->get();
$resultLookup = $results->keyBy('date');
$stats = [];
foreach ($intervals as $interval) {
$result = $resultLookup->get($interval['key']);
$stats[] = [
'label' => $interval['label'],
'count' => $result ? (int) $result->count : 0,
'total' => $result ? (float) $result->total : 0,
];
}
return $stats;
}
/**
* Generate time intervals based on period
*/
protected function generateTimeIntervals(Carbon $startDate, Carbon $endDate, string $period): array
{
$intervals = [];
$current = $startDate->copy();
while ($current <= $endDate) {
$interval = [
'key' => $this->formatDateForGrouping($current, $period),
'label' => $this->formatDateForLabel($current, $period),
];
$intervals[] = $interval;
switch ($period) {
case 'day':
$current->addDay();
break;
case 'week':
$current->addWeek();
break;
case 'month':
$current->addMonth();
break;
case 'year':
$current->addYear();
break;
}
}
return $intervals;
}
/**
* Get the SQL group column based on period
*/
protected function getGroupColumn(string $dateColumn, string $period): string
{
switch ($period) {
case 'day':
return "DATE($dateColumn)";
case 'week':
return "DATE_FORMAT($dateColumn, '%Y-%u')";
case 'month':
return "DATE_FORMAT($dateColumn, '%Y-%m')";
case 'year':
return "YEAR($dateColumn)";
default:
return "DATE($dateColumn)";
}
}
/**
* Format date for grouping key
*/
protected function formatDateForGrouping(Carbon $date, string $period): string
{
switch ($period) {
case 'day':
return $date->format('Y-m-d');
case 'week':
return $date->format('Y-W');
case 'month':
return $date->format('Y-m');
case 'year':
return $date->format('Y');
default:
return $date->format('Y-m-d');
}
}
/**
* Format date for display label
*/
protected function formatDateForLabel(Carbon $date, string $period): string
{
switch ($period) {
case 'day':
return $date->format('M d');
case 'week':
return 'Week '.$date->format('W, Y');
case 'month':
return $date->format('M Y');
case 'year':
return $date->format('Y');
default:
return $date->format('M d');
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Reporting/Activity.php | packages/Webkul/Admin/src/Helpers/Reporting/Activity.php | <?php
namespace Webkul\Admin\Helpers\Reporting;
class Activity extends AbstractReporting {}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Reporting/Quote.php | packages/Webkul/Admin/src/Helpers/Reporting/Quote.php | <?php
namespace Webkul\Admin\Helpers\Reporting;
use Webkul\Quote\Repositories\QuoteRepository;
class Quote extends AbstractReporting
{
/**
* Create a helper instance.
*
* @return void
*/
public function __construct(protected QuoteRepository $quoteRepository)
{
parent::__construct();
}
/**
* Retrieves total quotes and their progress.
*/
public function getTotalQuotesProgress(): array
{
return [
'previous' => $previous = $this->getTotalQuotes($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getTotalQuotes($this->startDate, $this->endDate),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves total quotes by date
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getTotalQuotes($startDate, $endDate): int
{
return $this->quoteRepository
->resetModel()
->whereBetween('created_at', [$startDate, $endDate])
->count();
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Helpers/Reporting/Person.php | packages/Webkul/Admin/src/Helpers/Reporting/Person.php | <?php
namespace Webkul\Admin\Helpers\Reporting;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Webkul\Contact\Repositories\PersonRepository;
class Person extends AbstractReporting
{
/**
* Create a helper instance.
*
* @return void
*/
public function __construct(protected PersonRepository $personRepository)
{
parent::__construct();
}
/**
* Retrieves total persons and their progress.
*/
public function getTotalPersonsProgress(): array
{
return [
'previous' => $previous = $this->getTotalPersons($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getTotalPersons($this->startDate, $this->endDate),
'progress' => $this->getPercentageChange($previous, $current),
];
}
/**
* Retrieves total persons by date
*
* @param \Carbon\Carbon $startDate
* @param \Carbon\Carbon $endDate
*/
public function getTotalPersons($startDate, $endDate): int
{
return $this->personRepository
->resetModel()
->whereBetween('created_at', [$startDate, $endDate])
->count();
}
/**
* Gets top customers by revenue.
*
* @param int $limit
*/
public function getTopCustomersByRevenue($limit = null): Collection
{
$tablePrefix = DB::getTablePrefix();
$items = $this->personRepository
->resetModel()
->leftJoin('leads', 'persons.id', '=', 'leads.person_id')
->select('*', 'persons.id as id')
->addSelect(DB::raw('SUM('.$tablePrefix.'leads.lead_value) as revenue'))
->whereBetween('leads.closed_at', [$this->startDate, $this->endDate])
->having(DB::raw('SUM('.$tablePrefix.'leads.lead_value)'), '>', 0)
->groupBy('person_id')
->orderBy('revenue', 'DESC')
->limit($limit)
->get();
$items = $items->map(function ($item) {
return [
'id' => $item->id,
'name' => $item->name,
'emails' => $item->emails,
'contact_numbers' => $item->contact_numbers,
'revenue' => $item->revenue,
'formatted_revenue' => core()->formatBasePrice($item->revenue),
];
});
return $items;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/helpers.php | packages/Webkul/Admin/src/Http/helpers.php | <?php
if (! function_exists('bouncer')) {
function bouncer()
{
return app()->make('bouncer');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Requests/UserForm.php | packages/Webkul/Admin/src/Http/Requests/UserForm.php | <?php
namespace Webkul\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserForm extends FormRequest
{
protected $rules;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$this->rules = [
'name' => 'required',
'email' => 'email|unique:users,email',
'password' => 'nullable',
'password_confirmation' => 'nullable|required_with:password|same:password',
'status' => 'sometimes',
'role_id' => 'required',
];
if ($this->method() == 'PUT') {
$this->rules['email'] = 'email|unique:users,email,'.$this->route('id');
}
return $this->rules;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Requests/AttributeForm.php | packages/Webkul/Admin/src/Http/Requests/AttributeForm.php | <?php
namespace Webkul\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Attribute\Repositories\AttributeValueRepository;
use Webkul\Core\Contracts\Validations\Decimal;
class AttributeForm extends FormRequest
{
/**
* @var array
*/
protected $rules = [];
/**
* Create a new form request instance.
*
* @return void
*/
public function __construct(
protected AttributeRepository $attributeRepository,
protected AttributeValueRepository $attributeValueRepository
) {}
/**
* Determine if the product is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$attributes = $this->attributeRepository->scopeQuery(function ($query) {
$query = $query->whereIn('code', array_keys(request()->all()))
->where('entity_type', request('entity_type'));
if (request()->has('quick_add')) {
$query = $query->where('quick_add', 1);
}
return $query;
})->get();
foreach ($attributes as $attribute) {
$validations = [];
if ($attribute->type == 'boolean') {
continue;
} elseif ($attribute->type == 'address') {
if (! $attribute->is_required) {
continue;
}
$validations = [
$attribute->code.'.address' => 'required',
$attribute->code.'.country' => 'required',
$attribute->code.'.state' => 'required',
$attribute->code.'.city' => 'required',
$attribute->code.'.postcode' => 'required',
];
} elseif ($attribute->type == 'email') {
$validations = [
$attribute->code => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code.'.*.value' => [$attribute->is_required ? 'required' : 'nullable', 'email'],
$attribute->code.'.*.label' => $attribute->is_required ? 'required' : 'nullable',
];
} elseif ($attribute->type == 'phone') {
$validations = [
$attribute->code => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code.'.*.value' => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code.'.*.label' => $attribute->is_required ? 'required' : 'nullable',
];
} else {
$validations[$attribute->code] = [$attribute->is_required ? 'required' : 'nullable'];
if ($attribute->type == 'text' && $attribute->validation) {
array_push($validations[$attribute->code],
$attribute->validation == 'decimal'
? new Decimal
: $attribute->validation
);
}
if ($attribute->type == 'price') {
array_push($validations[$attribute->code], new Decimal);
}
if ($attribute->type == 'image' && ! request($attribute->code.'.delete')) {
array_push($validations[$attribute->code], 'mimes:bmp,jpeg,jpg,png,webp');
}
}
if ($attribute->is_unique) {
array_push($validations[in_array($attribute->type, ['email', 'phone'])
? $attribute->code.'.*.value'
: $attribute->code
], function ($field, $value, $fail) use ($attribute) {
if (! $this->attributeValueRepository->isValueUnique($this->id, $attribute->entity_type, $attribute, request($field))) {
$fail('The value has already been taken.');
}
});
}
$this->rules = array_merge($this->rules, $validations);
}
return $this->rules;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Requests/MassUpdateRequest.php | packages/Webkul/Admin/src/Http/Requests/MassUpdateRequest.php | <?php
namespace Webkul\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class MassUpdateRequest extends FormRequest
{
/**
* Determine if the request is authorized or not.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'indices' => ['required', 'array'],
'indices.*' => ['integer'],
'value' => ['required'],
];
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Requests/PipelineForm.php | packages/Webkul/Admin/src/Http/Requests/PipelineForm.php | <?php
namespace Webkul\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Factory as ValidationFactory;
class PipelineForm extends FormRequest
{
/**
* Constructor.
*
* @return void
*/
public function __construct(ValidationFactory $validationFactory)
{
$this->validatorExtensions($validationFactory);
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
if (request('id')) {
return [
'name' => 'required|unique:lead_pipelines,name,'.request('id'),
'stages.*.name' => 'unique_key',
'stages.*.code' => 'unique_key',
];
}
return [
'name' => 'required|unique:lead_pipelines,name',
'rotten_days' => 'required',
'stages.*.name' => 'unique_key',
'stages.*.code' => 'unique_key',
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'stages.*.name.unique_key' => __('admin::app.settings.pipelines.duplicate-name'),
];
}
/**
* Place all your validator extensions here.
*
* @return void
*/
public function validatorExtensions(ValidationFactory $validationFactory)
{
$validationFactory->extend(
'unique_key',
function ($attribute, $value, $parameters) {
$key = last(explode('.', $attribute));
$stages = collect(request()->get('stages'))->filter(function ($stage) use ($key, $value) {
return $stage[$key] === $value;
});
if ($stages->count() > 1) {
return false;
}
return true;
}
);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Requests/MassDestroyRequest.php | packages/Webkul/Admin/src/Http/Requests/MassDestroyRequest.php | <?php
namespace Webkul\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class MassDestroyRequest extends FormRequest
{
/**
* Determine if the request is authorized or not.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'indices' => ['required', 'array'],
'indices.*' => ['integer'],
];
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Requests/ConfigurationForm.php | packages/Webkul/Admin/src/Http/Requests/ConfigurationForm.php | <?php
namespace Webkul\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ConfigurationForm extends FormRequest
{
/**
* Determine if the Configuration is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return collect(request()->input('keys', []))->mapWithKeys(function ($item) {
$data = json_decode($item, true);
return collect($data['fields'])->mapWithKeys(function ($field) use ($data) {
$key = $data['key'].'.'.$field['name'];
// Check delete key exist in the request
if (! $this->has($key.'.delete')) {
$validation = isset($field['validation']) && $field['validation'] ? $field['validation'] : 'nullable';
return [$key => $validation];
}
return [];
})->toArray();
})->toArray();
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Requests/LeadForm.php | packages/Webkul/Admin/src/Http/Requests/LeadForm.php | <?php
namespace Webkul\Admin\Http\Requests;
use Carbon\Carbon;
use Illuminate\Foundation\Http\FormRequest;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Attribute\Repositories\AttributeValueRepository;
use Webkul\Core\Contracts\Validations\Decimal;
class LeadForm extends FormRequest
{
/**
* @var array
*/
protected $rules = [];
/**
* Create a new form request instance.
*
* @return void
*/
public function __construct(
protected AttributeRepository $attributeRepository,
protected AttributeValueRepository $attributeValueRepository
) {}
/**
* Determine if the product is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
foreach (['leads', 'persons'] as $key => $entityType) {
$attributes = $this->attributeRepository->scopeQuery(function ($query) use ($entityType) {
$attributeCodes = $entityType == 'persons'
? array_keys(request('person') ?? [])
: array_keys(request()->all());
$query = $query->whereIn('code', $attributeCodes)
->where('entity_type', $entityType);
if (request()->has('quick_add')) {
$query = $query->where('quick_add', 1);
}
return $query;
})->get();
foreach ($attributes as $attribute) {
if ($entityType == 'persons') {
$attribute->code = 'person.'.$attribute->code;
}
$validations = [];
if ($attribute->type == 'boolean') {
continue;
} elseif ($attribute->type == 'address') {
if (! $attribute->is_required) {
continue;
}
$validations = [
$attribute->code.'.address' => 'required',
$attribute->code.'.country' => 'required',
$attribute->code.'.state' => 'required',
$attribute->code.'.city' => 'required',
$attribute->code.'.postcode' => 'required',
];
} elseif ($attribute->type == 'email') {
$validations = [
$attribute->code => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code.'.*.value' => [$attribute->is_required ? 'required' : 'nullable', 'email'],
$attribute->code.'.*.label' => $attribute->is_required ? 'required' : 'nullable',
];
} elseif ($attribute->type == 'phone') {
$validations = [
$attribute->code => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code.'.*.value' => [$attribute->is_required ? 'required' : 'nullable'],
$attribute->code.'.*.label' => $attribute->is_required ? 'required' : 'nullable',
];
} else {
$validations[$attribute->code] = [$attribute->is_required ? 'required' : 'nullable'];
if ($attribute->type == 'text' && $attribute->validation) {
array_push($validations[$attribute->code],
$attribute->validation == 'decimal'
? new Decimal
: $attribute->validation
);
}
if ($attribute->type == 'price') {
array_push($validations[$attribute->code], new Decimal);
}
}
if ($attribute->is_unique) {
array_push($validations[in_array($attribute->type, ['email', 'phone'])
? $attribute->code.'.*.value'
: $attribute->code
], function ($field, $value, $fail) use ($attribute, $entityType) {
if (! $this->attributeValueRepository->isValueUnique(
$entityType == 'persons' ? request('person.id') : $this->id,
$attribute->entity_type,
$attribute,
request($field)
)
) {
$fail('The value has already been taken.');
}
});
}
$this->rules = array_merge($this->rules, $validations);
}
}
$this->rules['expected_close_date'] = [
'date_format:Y-m-d',
'after:'.Carbon::yesterday()->format('Y-m-d'),
];
return [
...$this->rules,
'products' => 'array',
'products.*.product_id' => 'sometimes|required|exists:products,id',
'products.*.name' => 'required_with:products.*.product_id',
'products.*.price' => 'required_with:products.*.product_id',
'products.*.quantity' => 'required_with:products.*.product_id',
];
}
/**
* Get the validation messages that apply to the request.
*/
public function messages(): array
{
return [
'products.*.product_id.exists' => trans('admin::app.leads.selected-product-not-exist'),
'products.*.name.required_with' => trans('admin::app.leads.product-name-required'),
'products.*.price.required_with' => trans('admin::app.leads.product-price-required'),
'products.*.quantity.required_with' => trans('admin::app.leads.product-quantity-required'),
];
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Controller.php | packages/Webkul/Admin/src/Http/Controllers/Controller.php | <?php
namespace Webkul\Admin\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function redirectToLogin()
{
return redirect()->route('admin.session.create');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/TinyMCEController.php | packages/Webkul/Admin/src/Http/Controllers/TinyMCEController.php | <?php
namespace Webkul\Admin\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Webkul\Core\Traits\Sanitizer;
class TinyMCEController extends Controller
{
use Sanitizer;
/**
* Storage folder path.
*/
private string $storagePath = 'tinymce';
/**
* Upload file from tinymce.
*/
public function upload(): JsonResponse
{
$media = $this->storeMedia();
if (! empty($media)) {
return response()->json([
'location' => $media['file_url'],
]);
}
return response()->json([]);
}
/**
* Store media.
*/
public function storeMedia(): array
{
if (! request()->hasFile('file')) {
return [];
}
$file = request()->file('file');
if (! $file instanceof UploadedFile) {
return [];
}
$filename = md5($file->getClientOriginalName().time()).'.'.$file->getClientOriginalExtension();
$path = $file->storeAs($this->storagePath, $filename);
$this->sanitizeSVG($path, $file);
return [
'file' => $path,
'file_name' => $file->getClientOriginalName(),
'file_url' => Storage::url($path),
];
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/DataGridController.php | packages/Webkul/Admin/src/Http/Controllers/DataGridController.php | <?php
namespace Webkul\Admin\Http\Controllers;
use Illuminate\Support\Facades\Crypt;
class DataGridController extends Controller
{
/**
* Look up.
*/
public function lookUp()
{
/**
* Validation for parameters.
*/
$params = $this->validate(request(), [
'datagrid_id' => ['required'],
'column' => ['required'],
'search' => ['required', 'min:2'],
]);
/**
* Preparing the datagrid instance and only columns.
*/
$datagrid = app(Crypt::decryptString($params['datagrid_id']));
$datagrid->prepareColumns();
/**
* Finding the first column from the collection.
*/
$column = collect($datagrid->getColumns())->map(fn ($column) => $column->toArray())->where('index', $params['column'])->firstOrFail();
/**
* Fetching on the basis of column options.
*/
return app($column['filterable_options']['repository'])
->select([$column['filterable_options']['column']['label'].' as label', $column['filterable_options']['column']['value'].' as value'])
->where($column['filterable_options']['column']['label'], 'LIKE', '%'.$params['search'].'%')
->get();
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/DashboardController.php | packages/Webkul/Admin/src/Http/Controllers/DashboardController.php | <?php
namespace Webkul\Admin\Http\Controllers;
use Webkul\Admin\Helpers\Dashboard;
class DashboardController extends Controller
{
/**
* Request param functions
*
* @var array
*/
protected $typeFunctions = [
'over-all' => 'getOverAllStats',
'revenue-stats' => 'getRevenueStats',
'total-leads' => 'getTotalLeadsStats',
'revenue-by-sources' => 'getLeadsStatsBySources',
'revenue-by-types' => 'getLeadsStatsByTypes',
'top-selling-products' => 'getTopSellingProducts',
'top-persons' => 'getTopPersons',
'open-leads-by-states' => 'getOpenLeadsByStates',
];
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected Dashboard $dashboardHelper) {}
/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
{
return view('admin::dashboard.index')->with([
'startDate' => $this->dashboardHelper->getStartDate(),
'endDate' => $this->dashboardHelper->getEndDate(),
]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\JsonResponse
*/
public function stats()
{
$stats = $this->dashboardHelper->{$this->typeFunctions[request()->query('type')]}();
return response()->json([
'statistics' => $stats,
'date_range' => $this->dashboardHelper->getDateRange(),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Products/ProductController.php | packages/Webkul/Admin/src/Http/Controllers/Products/ProductController.php | <?php
namespace Webkul\Admin\Http\Controllers\Products;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\DataGrids\Product\ProductDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\AttributeForm;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Resources\ProductResource;
use Webkul\Product\Repositories\ProductRepository;
class ProductController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected ProductRepository $productRepository)
{
request()->request->add(['entity_type' => 'products']);
}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(ProductDataGrid::class)->process();
}
return view('admin::products.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::products.create');
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store(AttributeForm $request)
{
Event::dispatch('product.create.before');
$product = $this->productRepository->create($request->all());
Event::dispatch('product.create.after', $product);
session()->flash('success', trans('admin::app.products.index.create-success'));
return redirect()->route('admin.products.index');
}
/**
* Show the form for viewing the specified resource.
*/
public function view(int $id): View
{
$product = $this->productRepository->findOrFail($id);
return view('admin::products.view', compact('product'));
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View|JsonResponse
{
$product = $this->productRepository->findOrFail($id);
$inventories = $product->inventories()
->with('location')
->get()
->map(function ($inventory) {
return [
'id' => $inventory->id,
'name' => $inventory->location->name,
'warehouse_id' => $inventory->warehouse_id,
'warehouse_location_id' => $inventory->warehouse_location_id,
'in_stock' => $inventory->in_stock,
'allocated' => $inventory->allocated,
];
});
return view('admin::products.edit', compact('product', 'inventories'));
}
/**
* Update the specified resource in storage.
*/
public function update(AttributeForm $request, int $id)
{
Event::dispatch('product.update.before', $id);
$product = $this->productRepository->update($request->all(), $id);
Event::dispatch('product.update.after', $product);
if (request()->ajax()) {
return response()->json([
'message' => trans('admin::app.products.index.update-success'),
]);
}
session()->flash('success', trans('admin::app.products.index.update-success'));
return redirect()->route('admin.products.index');
}
/**
* Store a newly created resource in storage.
*/
public function storeInventories(int $id, ?int $warehouseId = null): JsonResponse
{
$this->validate(request(), [
'inventories' => 'array',
'inventories.*.warehouse_location_id' => 'required',
'inventories.*.warehouse_id' => 'required',
'inventories.*.in_stock' => 'required|integer|min:0',
'inventories.*.allocated' => 'required|integer|min:0',
]);
$product = $this->productRepository->findOrFail($id);
Event::dispatch('product.update.before', $id);
$this->productRepository->saveInventories(request()->all(), $id, $warehouseId);
Event::dispatch('product.update.after', $product);
return new JsonResponse([
'message' => trans('admin::app.products.index.update-success'),
], 200);
}
/**
* Search product results
*/
public function search(): JsonResource
{
$products = $this->productRepository
->pushCriteria(app(RequestCriteria::class))
->orderBy('created_at', 'desc')
->take(5)
->get();
return ProductResource::collection($products);
}
/**
* Returns product inventories grouped by warehouse.
*/
public function warehouses(int $id): JsonResponse
{
$warehouses = $this->productRepository->getInventoriesGroupedByWarehouse($id);
return response()->json(array_values($warehouses));
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$product = $this->productRepository->findOrFail($id);
try {
Event::dispatch('settings.products.delete.before', $id);
$product->delete($id);
Event::dispatch('settings.products.delete.after', $id);
return new JsonResponse([
'message' => trans('admin::app.products.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return new JsonResponse([
'message' => trans('admin::app.products.index.delete-failed'),
], 400);
}
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$indices = $massDestroyRequest->input('indices');
foreach ($indices as $index) {
Event::dispatch('product.delete.before', $index);
$this->productRepository->delete($index);
Event::dispatch('product.delete.after', $index);
}
return new JsonResponse([
'message' => trans('admin::app.products.index.delete-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Products/ActivityController.php | packages/Webkul/Admin/src/Http/Controllers/Products/ActivityController.php | <?php
namespace Webkul\Admin\Http\Controllers\Products;
use Webkul\Activity\Repositories\ActivityRepository;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Resources\ActivityResource;
use Webkul\Email\Repositories\EmailRepository;
class ActivityController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected ActivityRepository $activityRepository,
protected EmailRepository $emailRepository
) {}
/**
* Display a listing of the resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function index($id)
{
$activities = $this->activityRepository
->leftJoin('product_activities', 'activities.id', '=', 'product_activities.activity_id')
->where('product_activities.product_id', $id)
->get();
return ActivityResource::collection($this->concatEmail($activities));
}
/**
* Store a newly created resource in storage.
*/
public function concatEmail($activities)
{
return $activities->sortByDesc('id')->sortByDesc('created_at');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Products/TagController.php | packages/Webkul/Admin/src/Http/Controllers/Products/TagController.php | <?php
namespace Webkul\Admin\Http\Controllers\Products;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Product\Repositories\ProductRepository;
class TagController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected ProductRepository $productRepository) {}
/**
* Store a newly created resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function attach($id)
{
Event::dispatch('products.tag.create.before', $id);
$product = $this->productRepository->findOrFail($id);
if (! $product->tags->contains(request()->input('tag_id'))) {
$product->tags()->attach(request()->input('tag_id'));
}
Event::dispatch('products.tag.create.after', $product);
return response()->json([
'message' => trans('admin::app.leads.view.tags.create-success'),
]);
}
/**
* Remove the specified resource from storage.
*
* @param int $productId
* @return \Illuminate\Http\Response
*/
public function detach($productId)
{
Event::dispatch('products.tag.delete.before', $productId);
$product = $this->productRepository->find($productId);
$product->tags()->detach(request()->input('tag_id'));
Event::dispatch('products.tag.delete.after', $product);
return response()->json([
'message' => trans('admin::app.leads.view.tags.destroy-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php | packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php | <?php
namespace Webkul\Admin\Http\Controllers\Mail;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Mail\EmailDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Requests\MassUpdateRequest;
use Webkul\Admin\Http\Resources\EmailResource;
use Webkul\Email\Enums\SupportedFolderEnum;
use Webkul\Email\InboundEmailProcessor\Contracts\InboundEmailProcessor;
use Webkul\Email\Mails\Email;
use Webkul\Email\Repositories\AttachmentRepository;
use Webkul\Email\Repositories\EmailRepository;
use Webkul\Lead\Repositories\LeadRepository;
class EmailController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected LeadRepository $leadRepository,
protected EmailRepository $emailRepository,
protected AttachmentRepository $attachmentRepository
) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse|RedirectResponse
{
$route = request('route');
if (! $route) {
return redirect()->route('admin.mail.index', ['route' => SupportedFolderEnum::INBOX->value]);
}
if (! bouncer()->hasPermission('mail.'.$route)) {
abort(401, trans('admin::app.mail.unauthorized'));
}
if (request()->ajax()) {
return datagrid(EmailDataGrid::class)->process();
}
return view('admin::mail.index', compact('route'));
}
/**
* Display a resource.
*
* @return \Illuminate\View\View
*/
public function view()
{
$route = request('route');
$email = $this->emailRepository
->with([
'emails',
'attachments',
'emails.attachments',
'lead',
'lead.person',
'lead.tags',
'lead.source',
'lead.type',
'person',
])
->findOrFail(request('id'));
if ($userIds = bouncer()->getAuthorizedUserIds()) {
$results = $this->leadRepository->findWhere([
['id', '=', $email->lead_id],
['user_id', 'IN', $userIds],
]);
} else {
$results = $this->leadRepository->findWhere([
['id', '=', $email->lead_id],
]);
}
if (empty($results->toArray())) {
unset($email->lead_id);
}
if ($route == SupportedFolderEnum::DRAFT->value) {
return response()->json([
'data' => new EmailResource($email),
]);
}
return view('admin::mail.view', compact('email', 'route'));
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
$this->validate(request(), [
'reply_to' => 'required|array|min:1',
'reply_to.*' => 'email',
'reply' => 'required',
]);
Event::dispatch('email.create.before');
$email = $this->emailRepository->create(request()->all());
if (! request('is_draft')) {
try {
Mail::send(new Email($email));
$this->emailRepository->update([
'folders' => [SupportedFolderEnum::SENT->value],
], $email->id);
} catch (\Exception $e) {
}
}
Event::dispatch('email.create.after', $email);
if (request()->ajax()) {
return response()->json([
'data' => new EmailResource($email),
'message' => trans('admin::app.mail.create-success'),
]);
}
if (request('is_draft')) {
session()->flash('success', trans('admin::app.mail.saved-to-draft'));
return redirect()->route('admin.mail.index', ['route' => SupportedFolderEnum::DRAFT->value]);
}
session()->flash('success', trans('admin::app.mail.create-success'));
return redirect()->route('admin.mail.index', ['route' => SupportedFolderEnum::SENT->value]);
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update($id)
{
Event::dispatch('email.update.before', $id);
$data = request()->all();
if (! is_null(request('is_draft'))) {
$data['folders'] = request('is_draft') ? [SupportedFolderEnum::DRAFT->value] : [SupportedFolderEnum::OUTBOX->value];
}
$email = $this->emailRepository->update($data, request('id') ?? $id);
Event::dispatch('email.update.after', $email);
if (! is_null(request('is_draft')) && ! request('is_draft')) {
try {
Mail::send(new Email($email));
$this->emailRepository->update([
'folders' => [SupportedFolderEnum::INBOX->value, SupportedFolderEnum::SENT->value],
], $email->id);
} catch (\Exception $e) {
}
}
if (! is_null(request('is_draft'))) {
if (request('is_draft')) {
session()->flash('success', trans('admin::app.mail.saved-to-draft'));
return redirect()->route('admin.mail.index', ['route' => SupportedFolderEnum::DRAFT->value]);
} else {
session()->flash('success', trans('admin::app.mail.create-success'));
return redirect()->route('admin.mail.index', ['route' => SupportedFolderEnum::INBOX->value]);
}
}
if (request()->ajax()) {
return response()->json([
'data' => new EmailResource($email->refresh()),
'message' => trans('admin::app.mail.update-success'),
]);
}
session()->flash('success', trans('admin::app.mail.update-success'));
return redirect()->back();
}
/**
* Run process inbound parse email.
*
* @return \Illuminate\Http\Response
*/
public function inboundParse(InboundEmailProcessor $inboundEmailProcessor)
{
$inboundEmailProcessor->processMessage(request('email'));
return response()->json([], 200);
}
/**
* Download file from storage
*
* @param int $id
* @return \Illuminate\View\View
*/
public function download($id)
{
$attachment = $this->attachmentRepository->findOrFail($id);
try {
return Storage::download($attachment->path);
} catch (\Exception $e) {
session()->flash('error', $e->getMessage());
return redirect()->back();
}
}
/**
* Mass Update the specified resources.
*/
public function massUpdate(MassUpdateRequest $massUpdateRequest): JsonResponse
{
$emails = $this->emailRepository->findWhereIn('id', $massUpdateRequest->input('indices'));
try {
foreach ($emails as $email) {
Event::dispatch('email.update.before', $email->id);
$this->emailRepository->update([
'folders' => request('folders'),
], $email->id);
Event::dispatch('email.update.after', $email->id);
}
return response()->json([
'message' => trans('admin::app.mail.mass-update-success'),
]);
} catch (Exception) {
return response()->json([
'message' => trans('admin::app.mail.mass-update-success'),
], 400);
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse|RedirectResponse
{
$email = $this->emailRepository->findOrFail($id);
try {
Event::dispatch('email.'.request('type').'.before', $id);
$parentId = $email->parent_id;
if (request('type') == SupportedFolderEnum::TRASH->value) {
$this->emailRepository->update([
'folders' => [SupportedFolderEnum::TRASH->value],
], $id);
} else {
$this->emailRepository->delete($id);
}
Event::dispatch('email.'.request('type').'.after', $id);
if (request()->ajax()) {
return response()->json([
'message' => trans('admin::app.mail.delete-success'),
], 200);
}
session()->flash('success', trans('admin::app.mail.delete-success'));
if ($parentId) {
return redirect()->back();
}
return redirect()->route('admin.mail.index', ['route' => SupportedFolderEnum::INBOX->value]);
} catch (\Exception $exception) {
if (request()->ajax()) {
return response()->json([
'message' => trans('admin::app.mail.delete-failed'),
], 400);
}
session()->flash('error', trans('admin::app.mail.delete-failed'));
return redirect()->back();
}
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$mails = $this->emailRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
try {
foreach ($mails as $email) {
Event::dispatch('email.'.$massDestroyRequest->input('type').'.before', $email->id);
if ($massDestroyRequest->input('type') == SupportedFolderEnum::TRASH->value) {
$this->emailRepository->update(['folders' => [SupportedFolderEnum::TRASH->value]], $email->id);
} else {
$this->emailRepository->delete($email->id);
}
Event::dispatch('email.'.$massDestroyRequest->input('type').'.after', $email->id);
}
return response()->json([
'message' => trans('admin::app.mail.delete-success'),
]);
} catch (\Exception $e) {
return response()->json([
'message' => trans('admin::app.mail.delete-success'),
]);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Mail/TagController.php | packages/Webkul/Admin/src/Http/Controllers/Mail/TagController.php | <?php
namespace Webkul\Admin\Http\Controllers\Mail;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Email\Repositories\EmailRepository;
class TagController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected EmailRepository $emailRepository) {}
/**
* Store a newly created resource in storage.
*/
public function attach(int $id): JsonResponse
{
Event::dispatch('mails.tag.create.before', $id);
$mail = $this->emailRepository->find($id);
if (! $mail->tags->contains(request()->input('tag_id'))) {
$mail->tags()->attach(request()->input('tag_id'));
}
Event::dispatch('mails.tag.create.after', $mail);
return response()->json([
'message' => trans('admin::app.mail.view.tags.create-success'),
]);
}
/**
* Remove the specified resource from storage.
*/
public function detach(int $mailId): JsonResponse
{
Event::dispatch('mails.tag.delete.before', $mailId);
$mail = $this->emailRepository->find($mailId);
$mail->tags()->detach(request()->input('tag_id'));
Event::dispatch('mails.tag.delete.after', $mail);
return response()->json([
'message' => trans('admin::app.mail.view.tags.destroy-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Activity/ActivityController.php | packages/Webkul/Admin/src/Http/Controllers/Activity/ActivityController.php | <?php
namespace Webkul\Admin\Http\Controllers\Activity;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Webkul\Activity\Repositories\ActivityRepository;
use Webkul\Activity\Repositories\FileRepository;
use Webkul\Admin\DataGrids\Activity\ActivityDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Requests\MassUpdateRequest;
use Webkul\Admin\Http\Resources\ActivityResource;
use Webkul\Attribute\Repositories\AttributeRepository;
class ActivityController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected ActivityRepository $activityRepository,
protected FileRepository $fileRepository,
protected AttributeRepository $attributeRepository,
) {}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('admin::activities.index');
}
/**
* Returns a listing of the resource.
*/
public function get(): JsonResponse
{
if (! request()->has('view_type')) {
return datagrid(ActivityDataGrid::class)->process();
}
$startDate = request()->get('startDate')
? Carbon::createFromTimeString(request()->get('startDate').' 00:00:01')
: Carbon::now()->startOfWeek()->format('Y-m-d H:i:s');
$endDate = request()->get('endDate')
? Carbon::createFromTimeString(request()->get('endDate').' 23:59:59')
: Carbon::now()->endOfWeek()->format('Y-m-d H:i:s');
$activities = $this->activityRepository->getActivities([$startDate, $endDate])->toArray();
return response()->json([
'activities' => $activities,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(): RedirectResponse|JsonResponse
{
$this->validate(request(), [
'type' => 'required',
'comment' => 'required_if:type,note',
'schedule_from' => 'required_unless:type,note,file',
'schedule_to' => 'required_unless:type,note,file',
'file' => 'required_if:type,file',
]);
if (request('type') === 'meeting') {
/**
* Check if meeting is overlapping with other meetings.
*/
$isOverlapping = $this->activityRepository->isDurationOverlapping(
request()->input('schedule_from'),
request()->input('schedule_to'),
request()->input('participants'),
request()->input('id')
);
if ($isOverlapping) {
if (request()->ajax()) {
return response()->json([
'message' => trans('admin::app.activities.overlapping-error'),
], 400);
}
session()->flash('success', trans('admin::app.activities.overlapping-error'));
return redirect()->back();
}
}
Event::dispatch('activity.create.before');
$activity = $this->activityRepository->create(array_merge(request()->all(), [
'is_done' => request('type') == 'note' ? 1 : 0,
'user_id' => auth()->guard('user')->user()->id,
]));
Event::dispatch('activity.create.after', $activity);
if (request()->ajax()) {
return response()->json([
'data' => new ActivityResource($activity),
'message' => trans('admin::app.activities.create-success'),
]);
}
session()->flash('success', trans('admin::app.activities.create-success'));
return redirect()->back();
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$activity = $this->activityRepository->findOrFail($id);
$leadId = old('lead_id') ?? optional($activity->leads()->first())->id;
$lookUpEntityData = $this->attributeRepository->getLookUpEntity('leads', $leadId);
return view('admin::activities.edit', compact('activity', 'lookUpEntityData'));
}
/**
* Update the specified resource in storage.
*/
public function update($id): RedirectResponse|JsonResponse
{
Event::dispatch('activity.update.before', $id);
$data = request()->all();
$activity = $this->activityRepository->update($data, $id);
/**
* We will not use `empty` directly here because `lead_id` can be a blank string
* from the activity form. However, on the activity view page, we are only updating the
* `is_done` field, so `lead_id` will not be present in that case.
*/
if (isset($data['lead_id'])) {
$activity->leads()->sync(
! empty($data['lead_id'])
? [$data['lead_id']]
: []
);
}
Event::dispatch('activity.update.after', $activity);
if (request()->ajax()) {
return response()->json([
'data' => new ActivityResource($activity),
'message' => trans('admin::app.activities.update-success'),
]);
}
session()->flash('success', trans('admin::app.activities.update-success'));
return redirect()->route('admin.activities.index');
}
/**
* Mass Update the specified resources.
*/
public function massUpdate(MassUpdateRequest $massUpdateRequest): JsonResponse
{
$activities = $this->activityRepository->findWhereIn('id', $massUpdateRequest->input('indices'));
foreach ($activities as $activity) {
Event::dispatch('activity.update.before', $activity->id);
$activity = $this->activityRepository->update([
'is_done' => $massUpdateRequest->input('value'),
], $activity->id);
Event::dispatch('activity.update.after', $activity);
}
return response()->json([
'message' => trans('admin::app.activities.mass-update-success'),
]);
}
/**
* Download file from storage.
*/
public function download(int $id): StreamedResponse
{
try {
$file = $this->fileRepository->findOrFail($id);
return Storage::download($file->path);
} catch (\Exception $exception) {
abort(404);
}
}
/*
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$activity = $this->activityRepository->findOrFail($id);
try {
Event::dispatch('activity.delete.before', $id);
$activity?->delete($id);
Event::dispatch('activity.delete.after', $id);
return response()->json([
'message' => trans('admin::app.activities.destroy-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.activities.destroy-failed'),
], 400);
}
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$activities = $this->activityRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
try {
foreach ($activities as $activity) {
Event::dispatch('activity.delete.before', $activity->id);
$this->activityRepository->delete($activity->id);
Event::dispatch('activity.delete.after', $activity->id);
}
return response()->json([
'message' => trans('admin::app.activities.mass-destroy-success'),
]);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.activities.mass-delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Configuration/ConfigurationController.php | packages/Webkul/Admin/src/Http/Controllers/Configuration/ConfigurationController.php | <?php
namespace Webkul\Admin\Http\Controllers\Configuration;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\ConfigurationForm;
use Webkul\Core\Repositories\CoreConfigRepository as ConfigurationRepository;
class ConfigurationController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected ConfigurationRepository $configurationRepository) {}
/**
* Display a listing of the resource.
*/
public function index(): View
{
if (
request()->route('slug')
&& request()->route('slug2')
) {
return view('admin::configuration.edit');
}
return view('admin::configuration.index');
}
/**
* Store a newly created resource in storage.
*/
public function store(ConfigurationForm $request): RedirectResponse
{
Event::dispatch('core.configuration.save.before');
$this->configurationRepository->create($request->all());
Event::dispatch('core.configuration.save.after');
session()->flash('success', trans('admin::app.configuration.index.save-success'));
return redirect()->back();
}
/**
* download the file for the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function download()
{
$path = request()->route()->parameters()['path'];
$fileName = 'configuration/'.$path;
$config = $this->configurationRepository->findOneByField('value', $fileName);
return Storage::download($config['value']);
}
/**
* Search for configurations.
*/
public function search(): JsonResponse
{
$results = $this->configurationRepository->search(
system_config()->getItems(),
request()->query('query')
);
return new JsonResponse([
'data' => $results,
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/DataGrid/SavedFilterController.php | packages/Webkul/Admin/src/Http/Controllers/DataGrid/SavedFilterController.php | <?php
namespace Webkul\Admin\Http\Controllers\DataGrid;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\DataGrid\Repositories\SavedFilterRepository;
class SavedFilterController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct(protected SavedFilterRepository $savedFilterRepository) {}
/**
* Save filters to the database.
*/
public function store()
{
$userId = auth()->guard()->user()->id;
$this->validate(request(), [
'name' => 'required|unique:datagrid_saved_filters,name,NULL,id,src,'.request('src').',user_id,'.$userId,
]);
Event::dispatch('datagrid.saved_filter.create.before');
$savedFilter = $this->savedFilterRepository->create([
'user_id' => $userId,
'name' => request('name'),
'src' => request('src'),
'applied' => request('applied'),
]);
Event::dispatch('datagrid.saved_filter.create.after', $savedFilter);
return response()->json([
'data' => $savedFilter,
'message' => trans('admin::app.components.datagrid.toolbar.filter.saved-success'),
]);
}
/**
* Retrieves the saved filters.
*/
public function get()
{
$savedFilters = $this->savedFilterRepository->findWhere([
'src' => request()->get('src'),
'user_id' => auth()->guard()->user()->id,
]);
return response()->json(['data' => $savedFilters]);
}
/**
* Update the saved filter.
*/
public function update(int $id)
{
$userId = auth()->guard()->user()->id;
$this->validate(request(), [
'name' => 'required|unique:datagrid_saved_filters,name,'.$id.',id,src,'.request('src').',user_id,'.$userId,
]);
$savedFilter = $this->savedFilterRepository->findOneWhere([
'id' => $id,
'user_id' => auth()->guard()->user()->id,
]);
if (! $savedFilter) {
return response()->json([], 404);
}
Event::dispatch('datagrid.saved_filter.update.before', $id);
$updatedFilter = $this->savedFilterRepository->update(request()->only([
'name',
'src',
'applied',
]), $id);
Event::dispatch('datagrid.saved_filter.update.after', $updatedFilter);
return response()->json([
'data' => $updatedFilter,
'message' => trans('admin::app.components.datagrid.toolbar.filter.updated-success'),
]);
}
/**
* Delete the saved filter.
*/
public function destroy(int $id)
{
Event::dispatch('datagrid.saved_filter.delete.before', $id);
$success = $this->savedFilterRepository->deleteWhere([
'id' => $id,
'user_id' => auth()->guard()->user()->id,
]);
Event::dispatch('datagrid.saved_filter.delete.after', $id);
if (! $success) {
return response()->json([
'message' => trans('admin::app.components.datagrid.toolbar.filter.delete-error'),
]);
}
return response()->json([
'message' => trans('admin::app.components.datagrid.toolbar.filter.delete-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Contact/OrganizationController.php | packages/Webkul/Admin/src/Http/Controllers/Contact/OrganizationController.php | <?php
namespace Webkul\Admin\Http\Controllers\Contact;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Contact\OrganizationDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\AttributeForm;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Contact\Repositories\OrganizationRepository;
class OrganizationController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected OrganizationRepository $organizationRepository)
{
request()->request->add(['entity_type' => 'organizations']);
}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(OrganizationDataGrid::class)->process();
}
return view('admin::contacts.organizations.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::contacts.organizations.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(AttributeForm $request): RedirectResponse
{
Event::dispatch('contacts.organization.create.before');
$organization = $this->organizationRepository->create(request()->all());
Event::dispatch('contacts.organization.create.after', $organization);
session()->flash('success', trans('admin::app.contacts.organizations.index.create-success'));
return redirect()->route('admin.contacts.organizations.index');
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$organization = $this->organizationRepository->findOrFail($id);
return view('admin::contacts.organizations.edit', compact('organization'));
}
/**
* Update the specified resource in storage.
*/
public function update(AttributeForm $request, int $id): RedirectResponse
{
Event::dispatch('contacts.organization.update.before', $id);
$organization = $this->organizationRepository->update(request()->all(), $id);
Event::dispatch('contacts.organization.update.after', $organization);
session()->flash('success', trans('admin::app.contacts.organizations.index.update-success'));
return redirect()->route('admin.contacts.organizations.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
try {
Event::dispatch('contact.organization.delete.before', $id);
$this->organizationRepository->delete($id);
Event::dispatch('contact.organization.delete.after', $id);
return response()->json([
'message' => trans('admin::app.contacts.organizations.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.contacts.organizations.index.delete-failed'),
], 400);
}
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$organizations = $this->organizationRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
foreach ($organizations as $organization) {
Event::dispatch('contact.organization.delete.before', $organization);
$this->organizationRepository->delete($organization->id);
Event::dispatch('contact.organization.delete.after', $organization);
}
return response()->json([
'message' => trans('admin::app.contacts.organizations.index.delete-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/PersonController.php | packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/PersonController.php | <?php
namespace Webkul\Admin\Http\Controllers\Contact\Persons;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\DataGrids\Contact\PersonDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\AttributeForm;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Resources\PersonResource;
use Webkul\Contact\Repositories\PersonRepository;
class PersonController extends Controller
{
/**
* Create a new class instance.
*
* @return void
*/
public function __construct(protected PersonRepository $personRepository)
{
request()->request->add(['entity_type' => 'persons']);
}
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
return datagrid(PersonDataGrid::class)->process();
}
return view('admin::contacts.persons.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::contacts.persons.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(AttributeForm $request): RedirectResponse|JsonResponse
{
Event::dispatch('contacts.person.create.before');
$person = $this->personRepository->create($request->all());
Event::dispatch('contacts.person.create.after', $person);
if (request()->ajax()) {
return response()->json([
'data' => $person,
'message' => trans('admin::app.contacts.persons.index.create-success'),
]);
}
session()->flash('success', trans('admin::app.contacts.persons.index.create-success'));
return redirect()->route('admin.contacts.persons.index');
}
/**
* Display the specified resource.
*/
public function show(int $id): View
{
$person = $this->personRepository->findOrFail($id);
return view('admin::contacts.persons.view', compact('person'));
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$person = $this->personRepository->findOrFail($id);
return view('admin::contacts.persons.edit', compact('person'));
}
/**
* Update the specified resource in storage.
*/
public function update(AttributeForm $request, int $id): RedirectResponse|JsonResponse
{
Event::dispatch('contacts.person.update.before', $id);
$person = $this->personRepository->update($request->all(), $id);
Event::dispatch('contacts.person.update.after', $person);
if (request()->ajax()) {
return response()->json([
'data' => $person,
'message' => trans('admin::app.contacts.persons.index.update-success'),
], 200);
}
session()->flash('success', trans('admin::app.contacts.persons.index.update-success'));
return redirect()->route('admin.contacts.persons.index');
}
/**
* Search person results.
*/
public function search(): JsonResource
{
if ($userIds = bouncer()->getAuthorizedUserIds()) {
$persons = $this->personRepository
->pushCriteria(app(RequestCriteria::class))
->findWhereIn('user_id', $userIds);
} else {
$persons = $this->personRepository
->pushCriteria(app(RequestCriteria::class))
->all();
}
return PersonResource::collection($persons);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$person = $this->personRepository->findOrFail($id);
if (
$person->leads
&& $person->leads->count() > 0
) {
return response()->json([
'message' => trans('admin::app.contacts.persons.index.delete-failed'),
], 400);
}
try {
Event::dispatch('contacts.person.delete.before', $person);
$person->delete();
Event::dispatch('contacts.person.delete.after', $person);
return response()->json([
'message' => trans('admin::app.contacts.persons.index.delete-success'),
], 200);
} catch (Exception $exception) {
return response()->json([
'message' => trans('admin::app.contacts.persons.index.delete-failed'),
], 400);
}
}
/**
* Mass destroy the specified resources from storage.
*/
public function massDestroy(MassDestroyRequest $request): JsonResponse
{
try {
$persons = $this->personRepository->findWhereIn('id', $request->input('indices', []));
$deletedCount = 0;
$blockedCount = 0;
foreach ($persons as $person) {
if (
$person->leads
&& $person->leads->count() > 0
) {
$blockedCount++;
continue;
}
Event::dispatch('contact.person.delete.before', $person);
$this->personRepository->delete($person->id);
Event::dispatch('contact.person.delete.after', $person);
$deletedCount++;
}
$statusCode = 200;
switch (true) {
case $deletedCount > 0 && $blockedCount === 0:
$message = trans('admin::app.contacts.persons.index.all-delete-success');
break;
case $deletedCount > 0 && $blockedCount > 0:
$message = trans('admin::app.contacts.persons.index.partial-delete-warning');
break;
case $deletedCount === 0 && $blockedCount > 0:
$message = trans('admin::app.contacts.persons.index.none-delete-warning');
$statusCode = 400;
break;
default:
$message = trans('admin::app.contacts.persons.index.no-selection');
$statusCode = 400;
break;
}
return response()->json(['message' => $message], $statusCode);
} catch (Exception $exception) {
return response()->json([
'message' => trans('admin::app.contacts.persons.index.delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php | packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php | <?php
namespace Webkul\Admin\Http\Controllers\Contact\Persons;
use Illuminate\Support\Facades\DB;
use Webkul\Activity\Repositories\ActivityRepository;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Resources\ActivityResource;
use Webkul\Email\Repositories\AttachmentRepository;
use Webkul\Email\Repositories\EmailRepository;
class ActivityController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected ActivityRepository $activityRepository,
protected EmailRepository $emailRepository,
protected AttachmentRepository $attachmentRepository
) {}
/**
* Display a listing of the resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function index($id)
{
$activities = $this->activityRepository
->leftJoin('person_activities', 'activities.id', '=', 'person_activities.activity_id')
->where('person_activities.person_id', $id)
->get();
return ActivityResource::collection($this->concatEmailAsActivities($id, $activities));
}
/**
* Store a newly created resource in storage.
*/
public function concatEmailAsActivities($personId, $activities)
{
$emails = DB::table('emails as child')
->select('child.*')
->join('emails as parent', 'child.parent_id', '=', 'parent.id')
->where('parent.person_id', $personId)
->union(DB::table('emails as parent')->where('parent.person_id', $personId))
->get();
return $activities->concat($emails->map(function ($email) {
return (object) [
'id' => $email->id,
'parent_id' => $email->parent_id,
'title' => $email->subject,
'type' => 'email',
'is_done' => 1,
'comment' => $email->reply,
'schedule_from' => null,
'schedule_to' => null,
'user' => auth()->guard('user')->user(),
'participants' => [],
'location' => null,
'additional' => [
'folders' => json_decode($email->folders),
'from' => json_decode($email->from),
'to' => json_decode($email->reply_to),
'cc' => json_decode($email->cc),
'bcc' => json_decode($email->bcc),
],
'files' => $this->attachmentRepository->findWhere(['email_id' => $email->id])->map(function ($attachment) {
return (object) [
'id' => $attachment->id,
'name' => $attachment->name,
'path' => $attachment->path,
'url' => $attachment->url,
'created_at' => $attachment->created_at,
'updated_at' => $attachment->updated_at,
];
}),
'created_at' => $email->created_at,
'updated_at' => $email->updated_at,
];
}))->sortByDesc('id')->sortByDesc('created_at');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/TagController.php | packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/TagController.php | <?php
namespace Webkul\Admin\Http\Controllers\Contact\Persons;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Contact\Repositories\PersonRepository;
class TagController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected PersonRepository $personRepository) {}
/**
* Store a newly created resource in storage.
*/
public function attach(int $id): JsonResponse
{
Event::dispatch('persons.tag.create.before', $id);
$person = $this->personRepository->find($id);
if (! $person->tags->contains(request()->input('tag_id'))) {
$person->tags()->attach(request()->input('tag_id'));
}
Event::dispatch('persons.tag.create.after', $person);
return response()->json([
'message' => trans('admin::app.contacts.persons.view.tags.create-success'),
]);
}
/**
* Remove the specified resource from storage.
*/
public function detach(int $personId): JsonResponse
{
Event::dispatch('persons.tag.delete.before', $personId);
$person = $this->personRepository->find($personId);
$person->tags()->detach(request()->input('tag_id'));
Event::dispatch('persons.tag.delete.after', $person);
return response()->json([
'message' => trans('admin::app.contacts.persons.view.tags.destroy-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Lead/LeadController.php | packages/Webkul/Admin/src/Http/Controllers/Lead/LeadController.php | <?php
namespace Webkul\Admin\Http\Controllers\Lead;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Validator;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\DataGrids\Lead\LeadDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\LeadForm;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Requests\MassUpdateRequest;
use Webkul\Admin\Http\Resources\LeadResource;
use Webkul\Admin\Http\Resources\StageResource;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Contact\Repositories\PersonRepository;
use Webkul\Lead\Helpers\MagicAI;
use Webkul\Lead\Repositories\LeadRepository;
use Webkul\Lead\Repositories\PipelineRepository;
use Webkul\Lead\Repositories\ProductRepository;
use Webkul\Lead\Repositories\SourceRepository;
use Webkul\Lead\Repositories\StageRepository;
use Webkul\Lead\Repositories\TypeRepository;
use Webkul\Lead\Services\MagicAIService;
use Webkul\Tag\Repositories\TagRepository;
use Webkul\User\Repositories\UserRepository;
class LeadController extends Controller
{
/**
* Const variable for supported types.
*/
const SUPPORTED_TYPES = 'pdf,bmp,jpeg,jpg,png,webp';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected UserRepository $userRepository,
protected AttributeRepository $attributeRepository,
protected SourceRepository $sourceRepository,
protected TypeRepository $typeRepository,
protected PipelineRepository $pipelineRepository,
protected StageRepository $stageRepository,
protected LeadRepository $leadRepository,
protected ProductRepository $productRepository,
protected PersonRepository $personRepository
) {
request()->request->add(['entity_type' => 'leads']);
}
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
return datagrid(LeadDataGrid::class)->process();
}
if (request('pipeline_id')) {
$pipeline = $this->pipelineRepository->find(request('pipeline_id'));
} else {
$pipeline = $this->pipelineRepository->getDefaultPipeline();
}
return view('admin::leads.index', [
'pipeline' => $pipeline,
'columns' => $this->getKanbanColumns(),
]);
}
/**
* Returns a listing of the resource.
*/
public function get(): JsonResponse
{
if (request()->query('pipeline_id')) {
$pipeline = $this->pipelineRepository->find(request()->query('pipeline_id'));
} else {
$pipeline = $this->pipelineRepository->getDefaultPipeline();
}
if ($stageId = request()->query('pipeline_stage_id')) {
$stages = $pipeline->stages->where('id', request()->query('pipeline_stage_id'));
} else {
$stages = $pipeline->stages;
}
foreach ($stages as $stage) {
/**
* We have to create a new instance of the lead repository every time, which is
* why we're not using the injected one.
*/
$query = app(LeadRepository::class)
->pushCriteria(app(RequestCriteria::class))
->where([
'lead_pipeline_id' => $pipeline->id,
'lead_pipeline_stage_id' => $stage->id,
]);
if ($userIds = bouncer()->getAuthorizedUserIds()) {
$query->whereIn('leads.user_id', $userIds);
}
$stage->lead_value = (clone $query)->sum('lead_value');
$data[$stage->sort_order] = (new StageResource($stage))->jsonSerialize();
$data[$stage->sort_order]['leads'] = [
'data' => LeadResource::collection($paginator = $query->with([
'tags',
'type',
'source',
'user',
'person',
'person.organization',
'pipeline',
'pipeline.stages',
'stage',
'attribute_values',
])->paginate(10)),
'meta' => [
'current_page' => $paginator->currentPage(),
'from' => $paginator->firstItem(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'to' => $paginator->lastItem(),
'total' => $paginator->total(),
],
];
}
return response()->json($data);
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::leads.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(LeadForm $request): RedirectResponse|JsonResponse
{
Event::dispatch('lead.create.before');
$data = request()->all();
$data['status'] = 1;
if (! empty($data['lead_pipeline_stage_id'])) {
$stage = $this->stageRepository->findOrFail($data['lead_pipeline_stage_id']);
$data['lead_pipeline_id'] = $stage->lead_pipeline_id;
} else {
if (empty($data['lead_pipeline_id'])) {
$pipeline = $this->pipelineRepository->getDefaultPipeline();
$data['lead_pipeline_id'] = $pipeline->id;
} else {
$pipeline = $this->pipelineRepository->findOrFail($data['lead_pipeline_id']);
}
$stage = $pipeline->stages()->first();
$data['lead_pipeline_stage_id'] = $stage->id;
}
if (in_array($stage->code, ['won', 'lost'])) {
$data['closed_at'] = Carbon::now();
}
$lead = $this->leadRepository->create($data);
if (request()->ajax()) {
return response()->json([
'message' => trans('admin::app.leads.create-success'),
'data' => new LeadResource($lead),
]);
}
Event::dispatch('lead.create.after', $lead);
session()->flash('success', trans('admin::app.leads.create-success'));
if (! empty($data['lead_pipeline_id'])) {
$params['pipeline_id'] = $data['lead_pipeline_id'];
}
return redirect()->route('admin.leads.index', $params ?? []);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$lead = $this->leadRepository->findOrFail($id);
return view('admin::leads.edit', compact('lead'));
}
/**
* Display a resource.
*/
public function view(int $id)
{
$lead = $this->leadRepository->findOrFail($id);
$userIds = bouncer()->getAuthorizedUserIds();
if (
$userIds
&& ! in_array($lead->user_id, $userIds)
) {
return redirect()->route('admin.leads.index');
}
return view('admin::leads.view', compact('lead'));
}
/**
* Update the specified resource in storage.
*/
public function update(LeadForm $request, int $id): RedirectResponse|JsonResponse
{
Event::dispatch('lead.update.before', $id);
$data = $request->all();
if (isset($data['lead_pipeline_stage_id'])) {
$stage = $this->stageRepository->findOrFail($data['lead_pipeline_stage_id']);
$data['lead_pipeline_id'] = $stage->lead_pipeline_id;
} else {
$pipeline = $this->pipelineRepository->getDefaultPipeline();
$stage = $pipeline->stages()->first();
$data['lead_pipeline_id'] = $pipeline->id;
$data['lead_pipeline_stage_id'] = $stage->id;
}
$lead = $this->leadRepository->update($data, $id);
Event::dispatch('lead.update.after', $lead);
if (request()->ajax()) {
return response()->json([
'message' => trans('admin::app.leads.update-success'),
]);
}
session()->flash('success', trans('admin::app.leads.update-success'));
if (request()->has('closed_at')) {
return redirect()->back();
} else {
return redirect()->route('admin.leads.index', $data['lead_pipeline_id']);
}
}
/**
* Update the lead attributes.
*/
public function updateAttributes(int $id)
{
$data = request()->all();
$attributes = $this->attributeRepository->findWhere([
'entity_type' => 'leads',
['code', 'NOTIN', ['title', 'description']],
]);
Event::dispatch('lead.update.before', $id);
$lead = $this->leadRepository->update($data, $id, $attributes);
Event::dispatch('lead.update.after', $lead);
return response()->json([
'message' => trans('admin::app.leads.update-success'),
]);
}
/**
* Update the lead stage.
*/
public function updateStage(int $id)
{
$this->validate(request(), [
'lead_pipeline_stage_id' => 'required',
]);
$lead = $this->leadRepository->findOrFail($id);
$stage = $lead->pipeline->stages()
->where('id', request()->input('lead_pipeline_stage_id'))
->firstOrFail();
Event::dispatch('lead.update.before', $id);
$payload = request()->merge([
'entity_type' => 'leads',
'lead_pipeline_stage_id' => $stage->id,
])->only([
'closed_at',
'lost_reason',
'lead_pipeline_stage_id',
'entity_type',
]);
$lead = $this->leadRepository->update($payload, $id, ['lead_pipeline_stage_id']);
Event::dispatch('lead.update.after', $lead);
return response()->json([
'message' => trans('admin::app.leads.update-success'),
]);
}
/**
* Search person results.
*/
public function search(): AnonymousResourceCollection
{
if ($userIds = bouncer()->getAuthorizedUserIds()) {
$results = $this->leadRepository
->pushCriteria(app(RequestCriteria::class))
->findWhereIn('user_id', $userIds);
} else {
$results = $this->leadRepository
->pushCriteria(app(RequestCriteria::class))
->all();
}
return LeadResource::collection($results);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$this->leadRepository->findOrFail($id);
try {
Event::dispatch('lead.delete.before', $id);
$this->leadRepository->delete($id);
Event::dispatch('lead.delete.after', $id);
return response()->json([
'message' => trans('admin::app.leads.destroy-success'),
]);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.leads.destroy-failed'),
], 400);
}
}
/**
* Mass update the specified resources.
*/
public function massUpdate(MassUpdateRequest $massUpdateRequest): JsonResponse
{
$leads = $this->leadRepository->findWhereIn('id', $massUpdateRequest->input('indices'));
try {
foreach ($leads as $lead) {
Event::dispatch('lead.update.before', $lead->id);
$lead = $this->leadRepository->find($lead->id);
$lead?->update(['lead_pipeline_stage_id' => $massUpdateRequest->input('value')]);
Event::dispatch('lead.update.before', $lead->id);
}
return response()->json([
'message' => trans('admin::app.leads.update-success'),
]);
} catch (\Exception $th) {
return response()->json([
'message' => trans('admin::app.leads.update-failed'),
], 400);
}
}
/**
* Mass delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$leads = $this->leadRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
try {
foreach ($leads as $lead) {
Event::dispatch('lead.delete.before', $lead->id);
$this->leadRepository->delete($lead->id);
Event::dispatch('lead.delete.after', $lead->id);
}
return response()->json([
'message' => trans('admin::app.leads.destroy-success'),
]);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.leads.destroy-failed'),
]);
}
}
/**
* Attach product to lead.
*/
public function addProduct(int $leadId): JsonResponse
{
$product = $this->productRepository->updateOrCreate(
[
'lead_id' => $leadId,
'product_id' => request()->input('product_id'),
],
array_merge(
request()->all(),
[
'lead_id' => $leadId,
'amount' => request()->input('price') * request()->input('quantity'),
],
)
);
return response()->json([
'data' => $product,
'message' => trans('admin::app.leads.update-success'),
]);
}
/**
* Remove product attached to lead.
*/
public function removeProduct(int $id): JsonResponse
{
try {
Event::dispatch('lead.product.delete.before', $id);
$this->productRepository->deleteWhere([
'lead_id' => $id,
'product_id' => request()->input('product_id'),
]);
Event::dispatch('lead.product.delete.after', $id);
return response()->json([
'message' => trans('admin::app.leads.destroy-success'),
]);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.leads.destroy-failed'),
]);
}
}
/**
* Kanban lookup.
*/
public function kanbanLookup()
{
$params = $this->validate(request(), [
'column' => ['required'],
'search' => ['required', 'min:2'],
]);
/**
* Finding the first column from the collection.
*/
$column = collect($this->getKanbanColumns())->where('index', $params['column'])->firstOrFail();
/**
* Fetching on the basis of column options.
*/
return app($column['filterable_options']['repository'])
->select([$column['filterable_options']['column']['label'].' as label', $column['filterable_options']['column']['value'].' as value'])
->where($column['filterable_options']['column']['label'], 'LIKE', '%'.$params['search'].'%')
->get()
->map
->only('label', 'value');
}
/**
* Get columns for the kanban view.
*/
private function getKanbanColumns(): array
{
return [
[
'index' => 'id',
'label' => trans('admin::app.leads.index.kanban.columns.id'),
'type' => 'integer',
'searchable' => false,
'search_field' => 'in',
'filterable' => true,
'filterable_type' => null,
'filterable_options' => [],
'allow_multiple_values' => true,
'sortable' => true,
'visibility' => true,
],
[
'index' => 'lead_value',
'label' => trans('admin::app.leads.index.kanban.columns.lead-value'),
'type' => 'string',
'searchable' => false,
'search_field' => 'in',
'filterable' => true,
'filterable_type' => null,
'filterable_options' => [],
'allow_multiple_values' => true,
'sortable' => true,
'visibility' => true,
],
[
'index' => 'user_id',
'label' => trans('admin::app.leads.index.kanban.columns.sales-person'),
'type' => 'string',
'searchable' => false,
'search_field' => 'in',
'filterable' => true,
'filterable_type' => 'searchable_dropdown',
'filterable_options' => [
'repository' => UserRepository::class,
'column' => [
'label' => 'name',
'value' => 'id',
],
],
'allow_multiple_values' => true,
'sortable' => true,
'visibility' => true,
],
[
'index' => 'person.id',
'label' => trans('admin::app.leads.index.kanban.columns.contact-person'),
'type' => 'string',
'searchable' => false,
'search_field' => 'in',
'filterable' => true,
'filterable_options' => [],
'allow_multiple_values' => true,
'sortable' => true,
'visibility' => true,
'filterable_type' => 'searchable_dropdown',
'filterable_options' => [
'repository' => PersonRepository::class,
'column' => [
'label' => 'name',
'value' => 'id',
],
],
],
[
'index' => 'lead_type_id',
'label' => trans('admin::app.leads.index.kanban.columns.lead-type'),
'type' => 'string',
'searchable' => false,
'search_field' => 'in',
'filterable' => true,
'filterable_type' => 'dropdown',
'filterable_options' => $this->typeRepository->all(['name as label', 'id as value'])->toArray(),
'allow_multiple_values' => true,
'sortable' => true,
'visibility' => true,
],
[
'index' => 'lead_source_id',
'label' => trans('admin::app.leads.index.kanban.columns.source'),
'type' => 'string',
'searchable' => false,
'search_field' => 'in',
'filterable' => true,
'filterable_type' => 'dropdown',
'filterable_options' => $this->sourceRepository->all(['name as label', 'id as value'])->toArray(),
'allow_multiple_values' => true,
'sortable' => true,
'visibility' => true,
],
[
'index' => 'tags.name',
'label' => trans('admin::app.leads.index.kanban.columns.tags'),
'type' => 'string',
'searchable' => false,
'search_field' => 'in',
'filterable' => true,
'filterable_options' => [],
'allow_multiple_values' => true,
'sortable' => true,
'visibility' => true,
'filterable_type' => 'searchable_dropdown',
'filterable_options' => [
'repository' => TagRepository::class,
'column' => [
'label' => 'name',
'value' => 'name',
],
],
],
];
}
/**
* Create lead with specified AI.
*/
public function createByAI()
{
$leadData = [];
$errorMessages = [];
foreach (request()->file('files') as $file) {
$lead = $this->processFile($file);
if (
isset($lead['status'])
&& $lead['status'] === 'error'
) {
$errorMessages[] = $lead['message'];
} else {
$leadData[] = $lead;
}
}
if (isset($errorMessages[0]['code'])) {
return response()->json(MagicAI::errorHandler($errorMessages[0]['message']));
}
if (
empty($leadData)
&& ! empty($errorMessages)
) {
return response()->json(MagicAI::errorHandler(implode(', ', $errorMessages)), 400);
}
if (empty($leadData)) {
return response()->json(MagicAI::errorHandler(trans('admin::app.leads.no-valid-files')), 400);
}
return response()->json([
'message' => trans('admin::app.leads.create-success'),
'leads' => $this->createLeads($leadData),
]);
}
/**
* Process file.
*
* @param mixed $file
*/
private function processFile($file)
{
$validator = Validator::make(
['file' => $file],
['file' => 'required|extensions:'.str_replace(' ', '', self::SUPPORTED_TYPES)]
);
if ($validator->fails()) {
return MagicAI::errorHandler($validator->errors()->first());
}
$base64Pdf = base64_encode(file_get_contents($file->getRealPath()));
$extractedData = MagicAIService::extractDataFromFile($base64Pdf);
$lead = MagicAI::mapAIDataToLead($extractedData);
return $lead;
}
/**
* Create multiple leads.
*/
private function createLeads($rawLeads): array
{
$leads = [];
foreach ($rawLeads as $rawLead) {
Event::dispatch('lead.create.before');
foreach ($rawLead['person']['emails'] as $email) {
$person = $this->personRepository
->whereJsonContains('emails', [['value' => $email['value']]])
->first();
if ($person) {
$rawLead['person']['id'] = $person->id;
break;
}
}
$pipeline = $this->pipelineRepository->getDefaultPipeline();
$stage = $pipeline->stages()->first();
$lead = $this->leadRepository->create(array_merge($rawLead, [
'lead_pipeline_id' => $pipeline->id,
'lead_pipeline_stage_id' => $stage->id,
]));
Event::dispatch('lead.create.after', $lead);
$leads[] = $lead;
}
return $leads;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php | packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php | <?php
namespace Webkul\Admin\Http\Controllers\Lead;
use Illuminate\Support\Facades\DB;
use Webkul\Activity\Repositories\ActivityRepository;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Resources\ActivityResource;
use Webkul\Email\Repositories\AttachmentRepository;
use Webkul\Email\Repositories\EmailRepository;
class ActivityController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected ActivityRepository $activityRepository,
protected EmailRepository $emailRepository,
protected AttachmentRepository $attachmentRepository
) {}
/**
* Display a listing of the resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function index($id)
{
$activities = $this->activityRepository
->leftJoin('lead_activities', 'activities.id', '=', 'lead_activities.activity_id')
->where('lead_activities.lead_id', $id)
->get();
return ActivityResource::collection($this->concatEmailAsActivities($id, $activities));
}
/**
* Store a newly created resource in storage.
*/
public function concatEmailAsActivities($leadId, $activities)
{
$emails = DB::table('emails as child')
->select('child.*')
->join('emails as parent', 'child.parent_id', '=', 'parent.id')
->where('parent.lead_id', $leadId)
->union(DB::table('emails as parent')->where('parent.lead_id', $leadId))
->get();
return $activities->concat($emails->map(function ($email) {
return (object) [
'id' => $email->id,
'parent_id' => $email->parent_id,
'title' => $email->subject,
'type' => 'email',
'is_done' => 1,
'comment' => $email->reply,
'schedule_from' => null,
'schedule_to' => null,
'user' => auth()->guard('user')->user(),
'participants' => [],
'location' => null,
'additional' => [
'folders' => json_decode($email->folders),
'from' => json_decode($email->from),
'to' => json_decode($email->reply_to),
'cc' => json_decode($email->cc),
'bcc' => json_decode($email->bcc),
],
'files' => $this->attachmentRepository->findWhere(['email_id' => $email->id])->map(function ($attachment) {
return (object) [
'id' => $attachment->id,
'name' => $attachment->name,
'path' => $attachment->path,
'url' => $attachment->url,
'created_at' => $attachment->created_at,
'updated_at' => $attachment->updated_at,
];
}),
'created_at' => $email->created_at,
'updated_at' => $email->updated_at,
];
}))->sortByDesc('id')->sortByDesc('created_at');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Lead/EmailController.php | packages/Webkul/Admin/src/Http/Controllers/Lead/EmailController.php | <?php
namespace Webkul\Admin\Http\Controllers\Lead;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Mail\EmailController as BaseEmailController;
use Webkul\Admin\Http\Resources\ActivityResource;
class EmailController extends BaseEmailController
{
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
$response = json_decode(parent::store()->getContent(), true);
return response()->json([
'data' => $this->transformToActivity($response['data']),
'message' => $response['message'],
]);
return $response;
}
/**
* Store a newly created resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function detach($id)
{
Event::dispatch('email.update.before', request()->input('email_id'));
$email = $this->emailRepository->update([
'lead_id' => null,
], request()->input('email_id'));
Event::dispatch('email.update.after', $email);
return response()->json([
'message' => trans('admin::app.mail.update-success'),
]);
}
/**
* Transform the email data to activity resource.
*
* @param array $data
* @return \Webkul\Admin\Http\Resources\ActivityResource
*/
public function transformToActivity($data)
{
return new ActivityResource((object) [
'id' => $data['id'],
'parent_id' => $data['parent_id'],
'title' => $data['subject'],
'type' => 'email',
'is_done' => 1,
'comment' => $data['reply'],
'schedule_from' => null,
'schedule_to' => null,
'user' => auth()->guard('user')->user(),
'participants' => [],
'location' => null,
'additional' => json_encode([
'folders' => $data['folders'],
'from' => $data['from'],
'to' => $data['reply_to'],
'cc' => $data['cc'],
'bcc' => $data['bcc'],
]),
'files' => array_map(function ($attachment) {
return (object) $attachment;
}, $data['attachments']),
'created_at' => $data['created_at'],
'updated_at' => $data['updated_at'],
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Lead/QuoteController.php | packages/Webkul/Admin/src/Http/Controllers/Lead/QuoteController.php | <?php
namespace Webkul\Admin\Http\Controllers\Lead;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Lead\Repositories\LeadRepository;
use Webkul\Quote\Repositories\QuoteRepository;
class QuoteController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected LeadRepository $leadRepository,
protected QuoteRepository $quoteRepository
) {}
/**
* Store a newly created resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function store($id)
{
Event::dispatch('leads.quote.create.before');
$lead = $this->leadRepository->find($id);
if (! $lead->quotes->contains(request('id'))) {
$lead->quotes()->attach(request('id'));
}
Event::dispatch('leads.quote.create.after', $lead);
return response()->json([
'message' => trans('admin::app.leads.quote-create-success'),
], 200);
}
/**
* Remove the specified resource from storage.
*
* @param int $leadId
* @param int $tagId
* @return \Illuminate\Http\Response
*/
public function delete($leadId)
{
Event::dispatch('leads.quote.delete.before', $leadId);
$lead = $this->leadRepository->find($leadId);
$lead->quotes()->detach(request('quote_id'));
Event::dispatch('leads.quote.delete.after', $lead);
return response()->json([
'message' => trans('admin::app.leads.view.quotes.destroy-success'),
], 200);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Lead/TagController.php | packages/Webkul/Admin/src/Http/Controllers/Lead/TagController.php | <?php
namespace Webkul\Admin\Http\Controllers\Lead;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Lead\Repositories\LeadRepository;
class TagController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected LeadRepository $leadRepository) {}
/**
* Store a newly created resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function attach($id)
{
Event::dispatch('leads.tag.create.before', $id);
$lead = $this->leadRepository->find($id);
if (! $lead->tags->contains(request()->input('tag_id'))) {
$lead->tags()->attach(request()->input('tag_id'));
}
Event::dispatch('leads.tag.create.after', $lead);
return response()->json([
'message' => trans('admin::app.leads.view.tags.create-success'),
]);
}
/**
* Remove the specified resource from storage.
*
* @param int $leadId
* @return \Illuminate\Http\Response
*/
public function detach($leadId)
{
Event::dispatch('leads.tag.delete.before', $leadId);
$lead = $this->leadRepository->find($leadId);
$lead->tags()->detach(request()->input('tag_id'));
Event::dispatch('leads.tag.delete.after', $lead);
return response()->json([
'message' => trans('admin::app.leads.view.tags.destroy-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/User/AccountController.php | packages/Webkul/Admin/src/Http/Controllers/User/AccountController.php | <?php
namespace Webkul\Admin\Http\Controllers\User;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
use Webkul\Admin\Http\Controllers\Controller;
class AccountController extends Controller
{
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\View\View
*/
public function edit()
{
$user = auth()->guard('user')->user();
return view('admin::user.account.edit', compact('user'));
}
/**
* Update the specified resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function update()
{
$user = auth()->guard('user')->user();
$this->validate(request(), [
'name' => 'required',
'email' => 'email|unique:users,email,'.$user->id,
'password' => 'nullable|min:6|confirmed',
'current_password' => 'required|min:6',
'image.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
]);
$data = request()->only([
'name',
'email',
'password',
'password_confirmation',
'current_password',
'image',
]);
if (! Hash::check($data['current_password'], $user->password)) {
session()->flash('warning', trans('admin::app.account.edit.invalid-password'));
return redirect()->back();
}
if (isset($data['role_id']) || isset($data['view_permission'])) {
session()->flash('warning', trans('admin::app.user.account.permission-denied'));
return redirect()->back();
}
$isPasswordChanged = false;
if (! $data['password']) {
unset($data['password']);
} else {
$isPasswordChanged = true;
$data['password'] = bcrypt($data['password']);
}
if (request()->hasFile('image')) {
$data['image'] = current(request()->file('image'))->store('admins/'.$user->id);
} else {
if (! isset($data['image'])) {
if (! empty($data['image'])) {
Storage::delete($user->image);
}
$data['image'] = null;
} else {
$data['image'] = $user->image;
}
}
$user->update($data);
if ($isPasswordChanged) {
Event::dispatch('user.account.update-password', $user);
}
session()->flash('success', trans('admin::app.account.edit.update-success'));
return back();
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/User/SessionController.php | packages/Webkul/Admin/src/Http/Controllers/User/SessionController.php | <?php
namespace Webkul\Admin\Http\Controllers\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Core\Menu\MenuItem;
class SessionController extends Controller
{
/**
* Show the form for creating a new resource.
*/
public function create(): RedirectResponse|View
{
if (auth()->guard('user')->check()) {
return redirect()->route('admin.dashboard.index');
}
$previousUrl = url()->previous();
$intendedUrl = str_contains($previousUrl, 'admin')
? $previousUrl
: route('admin.dashboard.index');
session()->put('url.intended', $intendedUrl);
return view('admin::sessions.login');
}
/**
* Store a newly created resource in storage.
*/
public function store(): RedirectResponse
{
$this->validate(request(), [
'email' => 'required|email',
'password' => 'required',
]);
if (! auth()->guard('user')->attempt(request(['email', 'password']), request('remember'))) {
session()->flash('error', trans('admin::app.users.login-error'));
return redirect()->back();
}
if (auth()->guard('user')->user()->status == 0) {
session()->flash('warning', trans('admin::app.users.activate-warning'));
auth()->guard('user')->logout();
return redirect()->route('admin.session.create');
}
$menus = menu()->getItems('admin');
$availableNextMenu = $menus?->first();
if (! bouncer()->hasPermission('dashboard')) {
if (is_null($availableNextMenu)) {
session()->flash('error', trans('admin::app.users.not-permission'));
auth()->guard('user')->logout();
return redirect()->route('admin.session.create');
}
return redirect()->to($availableNextMenu->getUrl());
}
$hasAccessToIntendedUrl = $this->canAccessIntendedUrl($menus, redirect()->getIntendedUrl());
if ($hasAccessToIntendedUrl) {
return redirect()->intended(route('admin.dashboard.index'));
}
return redirect()->to($availableNextMenu->getUrl());
}
/**
* Remove the specified resource from storage.
*/
public function destroy(): RedirectResponse
{
auth()->guard('user')->logout();
return redirect()->route('admin.session.create');
}
/**
* Find menu item by URL.
*/
protected function canAccessIntendedUrl(Collection $menus, ?string $url): ?MenuItem
{
if (is_null($url)) {
return null;
}
foreach ($menus as $menu) {
if ($menu->getUrl() === $url) {
return $menu;
}
if ($menu->haveChildren()) {
$found = $this->canAccessIntendedUrl($menu->getChildren(), $url);
if ($found) {
return $found;
}
}
}
return null;
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/User/ForgotPasswordController.php | packages/Webkul/Admin/src/Http/Controllers/User/ForgotPasswordController.php | <?php
namespace Webkul\Admin\Http\Controllers\User;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Support\Facades\Password;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Notifications\User\UserResetPassword;
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
/**
* Show the form for creating a new resource.
*/
public function create()
{
if (auth()->guard('user')->check()) {
return redirect()->route('admin.dashboard.index');
} else {
if (strpos(url()->previous(), 'user') !== false) {
$intendedUrl = url()->previous();
} else {
$intendedUrl = route('admin.dashboard.index');
}
session()->put('url.intended', $intendedUrl);
return view('admin::sessions.forgot-password');
}
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
try {
$this->validate(request(), [
'email' => 'required|email',
]);
$response = $this->broker()->sendResetLink(request(['email']), function ($user, $token) {
$user->notify(new UserResetPassword($token));
});
if ($response == Password::RESET_LINK_SENT) {
session()->flash('success', trans('admin::app.users.forget-password.create.reset-link-sent'));
return back();
}
return back()
->withInput(request(['email']))
->withErrors([
'email' => trans('admin::app.users.forget-password.create.email-not-exist'),
]);
} catch (\Exception $exception) {
session()->flash('error', trans($exception->getMessage()));
return redirect()->back();
}
}
/**
* Get the broker to be used during password reset.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker()
{
return Password::broker('users');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/User/ResetPasswordController.php | packages/Webkul/Admin/src/Http/Controllers/User/ResetPasswordController.php | <?php
namespace Webkul\Admin\Http\Controllers\User;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Webkul\Admin\Http\Controllers\Controller;
class ResetPasswordController extends Controller
{
use ResetsPasswords;
/**
* Display the password reset view for the given token.
*
* If no token is present, display the link request form.
*
* @param string|null $token
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create($token = null)
{
return view('admin::sessions.reset-password')->with([
'token' => $token,
'email' => request('email'),
]);
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
try {
$this->validate(request(), [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
]);
$response = $this->broker()->reset(
request(['email', 'password', 'password_confirmation', 'token']), function ($admin, $password) {
$this->resetPassword($admin, $password);
}
);
if ($response == Password::PASSWORD_RESET) {
return redirect()->route('admin.dashboard.index');
}
return back()
->withInput(request(['email']))
->withErrors([
'email' => trans($response),
]);
} catch (\Exception $exception) {
session()->flash('error', trans($exception->getMessage()));
return redirect()->back();
}
}
/**
* Reset the given admin's password.
*
* @param \Illuminate\Contracts\Auth\CanResetPassword $admin
* @param string $password
* @return void
*/
protected function resetPassword($admin, $password)
{
$admin->password = Hash::make($password);
$admin->setRememberToken(Str::random(60));
$admin->save();
event(new PasswordReset($admin));
auth()->guard('user')->login($admin);
}
/**
* Get the broker to be used during password reset.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker()
{
return Password::broker('users');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Quote/QuoteController.php | packages/Webkul/Admin/src/Http/Controllers/Quote/QuoteController.php | <?php
namespace Webkul\Admin\Http\Controllers\Quote;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Webkul\Admin\DataGrids\Quote\QuoteDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\AttributeForm;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Resources\QuoteResource;
use Webkul\Core\Traits\PDFHandler;
use Webkul\Lead\Repositories\LeadRepository;
use Webkul\Quote\Repositories\QuoteRepository;
class QuoteController extends Controller
{
use PDFHandler;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected QuoteRepository $quoteRepository,
protected LeadRepository $leadRepository
) {
request()->request->add(['entity_type' => 'quotes']);
}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(QuoteDataGrid::class)->process();
}
return view('admin::quotes.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
$lead = $this->leadRepository->find(request('id'));
return view('admin::quotes.create', compact('lead'));
}
/**
* Store a newly created resource in storage.
*/
public function store(AttributeForm $request): RedirectResponse
{
Event::dispatch('quote.create.before');
$quote = $this->quoteRepository->create($request->all());
$leadId = request('lead_id');
if ($leadId) {
$lead = $this->leadRepository->find($leadId);
$lead->quotes()->attach($quote->id);
}
Event::dispatch('quote.create.after', $quote);
session()->flash('success', trans('admin::app.quotes.index.create-success'));
return request()->query('from') === 'lead' && $leadId
? redirect()->route('admin.leads.view', ['id' => $leadId, 'from' => 'quotes'])
: redirect()->route('admin.quotes.index');
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$quote = $this->quoteRepository->findOrFail($id);
return view('admin::quotes.edit', compact('quote'));
}
/**
* Update the specified resource in storage.
*/
public function update(AttributeForm $request, int $id): RedirectResponse
{
Event::dispatch('quote.update.before', $id);
$quote = $this->quoteRepository->update($request->all(), $id);
$quote->leads()->detach();
$leadId = request('lead_id');
if ($leadId) {
$lead = $this->leadRepository->find($leadId);
$lead->quotes()->attach($quote->id);
}
Event::dispatch('quote.update.after', $quote);
session()->flash('success', trans('admin::app.quotes.index.update-success'));
return request()->query('from') === 'lead' && $leadId
? redirect()->route('admin.leads.view', ['id' => $leadId, 'from' => 'quotes'])
: redirect()->route('admin.quotes.index');
}
/**
* Search the quotes.
*/
public function search(): AnonymousResourceCollection
{
$quotes = $this->quoteRepository
->pushCriteria(app(RequestCriteria::class))
->all();
return QuoteResource::collection($quotes);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$this->quoteRepository->findOrFail($id);
try {
Event::dispatch('quote.delete.before', $id);
$this->quoteRepository->delete($id);
Event::dispatch('quote.delete.after', $id);
return response()->json([
'message' => trans('admin::app.quotes.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.quotes.index.delete-failed'),
], 400);
}
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$quotes = $this->quoteRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
try {
foreach ($quotes as $quotes) {
Event::dispatch('quote.delete.before', $quotes->id);
$this->quoteRepository->delete($quotes->id);
Event::dispatch('quote.delete.after', $quotes->id);
}
return response()->json([
'message' => trans('admin::app.quotes.index.delete-success'),
]);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.quotes.index.delete-failed'),
], 400);
}
}
/**
* Print and download the for the specified resource.
*/
public function print($id): Response|StreamedResponse
{
$quote = $this->quoteRepository->findOrFail($id);
return $this->downloadPDF(
view('admin::quotes.pdf', compact('quote'))->render(),
'Quote_'.$quote->subject.'_'.$quote->created_at->format('d-m-Y')
);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/EmailTemplateController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/EmailTemplateController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\EmailTemplateDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Automation\Helpers\Entity;
use Webkul\EmailTemplate\Repositories\EmailTemplateRepository;
class EmailTemplateController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected EmailTemplateRepository $emailTemplateRepository,
protected Entity $workflowEntityHelper
) {}
/**
* Display a listing of the email template.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(EmailTemplateDataGrid::class)->process();
}
return view('admin::settings.email-templates.index');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\View\View
*/
public function create()
{
$placeholders = $this->workflowEntityHelper->getEmailTemplatePlaceholders();
return view('admin::settings.email-templates.create', compact('placeholders'));
}
/**
* Store a newly created email templates in storage.
*/
public function store(): RedirectResponse
{
$this->validate(request(), [
'name' => 'required|unique:email_templates,name',
'subject' => 'required',
'content' => 'required',
]);
Event::dispatch('settings.email_templates.create.before');
$emailTemplate = $this->emailTemplateRepository->create(request()->all());
Event::dispatch('settings.email_templates.create.after', $emailTemplate);
session()->flash('success', trans('admin::app.settings.email-template.index.create-success'));
return redirect()->route('admin.settings.email_templates.index');
}
/**
* Show the form for editing the specified email template.
*/
public function edit(int $id): View
{
$emailTemplate = $this->emailTemplateRepository->findOrFail($id);
$placeholders = $this->workflowEntityHelper->getEmailTemplatePlaceholders();
return view('admin::settings.email-templates.edit', compact('emailTemplate', 'placeholders'));
}
/**
* Update the specified email template in storage.
*/
public function update(int $id): RedirectResponse
{
$this->validate(request(), [
'name' => 'required|unique:email_templates,name,'.$id,
'subject' => 'required',
'content' => 'required',
]);
Event::dispatch('settings.email_templates.update.before', $id);
$emailTemplate = $this->emailTemplateRepository->update(request()->all(), $id);
Event::dispatch('settings.email_templates.update.after', $emailTemplate);
session()->flash('success', trans('admin::app.settings.email-template.index.update-success'));
return redirect()->route('admin.settings.email_templates.index');
}
/**
* Remove the specified email template from storage.
*/
public function destroy(int $id): JsonResponse
{
$emailTemplate = $this->emailTemplateRepository->findOrFail($id);
try {
Event::dispatch('settings.email_templates.delete.before', $id);
$emailTemplate->delete($id);
Event::dispatch('settings.email_templates.delete.after', $id);
return response()->json([
'message' => trans('admin::app.settings.email-template.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.email-template.index.delete-failed'),
], 400);
}
return response()->json([
'message' => trans('admin::app.settings.email-template.index.delete-failed'),
], 400);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/AttributeController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/AttributeController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\AttributeDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Attribute\Repositories\AttributeValueRepository;
use Webkul\Core\Contracts\Validations\Code;
class AttributeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected AttributeRepository $attributeRepository,
protected AttributeValueRepository $attributeValueRepository
) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(AttributeDataGrid::class)->process();
}
return view('admin::settings.attributes.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::settings.attributes.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(): RedirectResponse
{
$this->validate(request(), [
'code' => ['required', 'unique:attributes,code,NULL,NULL,entity_type,'.request('entity_type'), new Code],
'name' => 'required',
'type' => 'required',
]);
Event::dispatch('settings.attribute.create.before');
request()->request->add(['quick_add' => 1]);
$attribute = $this->attributeRepository->create(request()->all());
Event::dispatch('settings.attribute.create.after', $attribute);
session()->flash('success', trans('admin::app.settings.attributes.index.create-success'));
return redirect()->route('admin.settings.attributes.index');
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$attribute = $this->attributeRepository->findOrFail($id);
return view('admin::settings.attributes.edit', compact('attribute'));
}
/**
* Update the specified resource in storage.
*/
public function update($id): RedirectResponse
{
$this->validate(request(), [
'code' => ['required', 'unique:attributes,code,NULL,NULL,entity_type,'.$id, new Code],
'name' => 'required',
'type' => 'required',
]);
Event::dispatch('settings.attribute.update.before', $id);
$attribute = $this->attributeRepository->update(request()->all(), $id);
Event::dispatch('settings.attribute.update.after', $attribute);
session()->flash('success', trans('admin::app.settings.attributes.index.update-success'));
return redirect()->route('admin.settings.attributes.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$attribute = $this->attributeRepository->findOrFail($id);
if (! $attribute->is_user_defined) {
return response()->json([
'message' => trans('admin::app.settings.attributes.index.user-define-error'),
], 400);
}
try {
Event::dispatch('settings.attribute.delete.before', $id);
$this->attributeRepository->delete($id);
Event::dispatch('settings.attribute.delete.after', $id);
return response()->json([
'status' => true,
'message' => trans('admin::app.settings.attributes.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.attributes.index.delete-failed'),
], 400);
}
}
/**
* Check unique validation.
*
* @return void
*/
public function checkUniqueValidation()
{
$attribute = $this->attributeRepository->findOneWhere([
'code' => request('attribute_code'),
]);
return response()->json([
'validated' => $this->attributeValueRepository->isValueUnique(
request('entity_id'),
request('entity_type'),
$attribute,
request('attribute_value'),
),
]);
}
/**
* Search attribute lookup results
*/
public function lookup($lookup): JsonResponse
{
$results = $this->attributeRepository->getLookUpOptions($lookup, request()->input('query'));
return response()->json($results);
}
/**
* Search attribute lookup results
*/
public function lookupEntity(string $lookup): JsonResponse
{
$result = $this->attributeRepository->getLookUpEntity($lookup, request()->input('query'));
return response()->json($result);
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$count = 0;
$attributes = $this->attributeRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
foreach ($attributes as $attribute) {
$attribute = $this->attributeRepository->find($attribute->id);
if (! $attribute->is_user_defined) {
continue;
}
Event::dispatch('settings.attribute.delete.before', $attribute->id);
$this->attributeRepository->delete($attribute->id);
Event::dispatch('settings.attribute.delete.after', $attribute->id);
$count++;
}
if (! $count) {
return response()->json([
'message' => trans('admin::app.settings.attributes.index.mass-delete-failed'),
], 400);
}
return response()->json([
'message' => trans('admin::app.settings.attributes.index.delete-success'),
]);
}
/**
* Get attribute options associated with attribute.
*
* @return \Illuminate\View\View
*/
public function getAttributeOptions(int $id)
{
$attribute = $this->attributeRepository->findOrFail($id);
return $attribute->options()->orderBy('sort_order')->get();
}
/**
* Download image or file
*/
public function download()
{
if (! request('path')) {
return false;
}
return Storage::download(request('path'));
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/SettingController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/SettingController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Core\Menu\MenuItem;
class SettingController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
{
return view('admin::settings.index');
}
/**
* Search for settings.
*/
public function search(): ?JsonResponse
{
$query = strtolower(request()->query('query'));
if (empty($query)) {
return response()->json(['data' => []]);
}
$results = $this->searchMenuItems($this->getSettingsConfig(), $query);
return response()->json([
'data' => $results->values(),
]);
}
/**
* Recursively search through menu items and children.
*
* @param Collection<int, MenuItem> $menuItems
* @return Collection<int, array<string, mixed>>
*/
protected function searchMenuItems(Collection $menuItems, string $query): Collection
{
$results = collect();
foreach ($menuItems as $item) {
if ($this->matchesQuery($item, $query)) {
$results->push([
'name' => $item->getName(),
'url' => $item->getUrl(),
'icon' => $item->getIcon(),
'key' => $item->getKey(),
]);
}
if ($item->haveChildren()) {
$childResults = $this->searchMenuItems($item->getChildren(), $query);
$results = $results->merge($childResults);
}
}
return $results;
}
/**
* Determine if the menu item matches the query.
*/
protected function matchesQuery(MenuItem $item, string $query): bool
{
$query = strtolower($query);
$url = strtolower($item->getUrl());
if (
! $url
|| ! str_contains($url, $query)
) {
return false;
}
return true;
}
/**
* Get the settings configuration.
*/
protected function getSettingsConfig(): Collection
{
return menu()
->getItems('admin')
->filter(fn (MenuItem $item) => $item->getKey() === 'settings');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/UserController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/UserController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\DataGrids\Settings\UserDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Requests\MassUpdateRequest;
use Webkul\Admin\Http\Resources\UserResource;
use Webkul\Admin\Notifications\User\Create as UserCreatedNotification;
use Webkul\User\Repositories\GroupRepository;
use Webkul\User\Repositories\RoleRepository;
use Webkul\User\Repositories\UserRepository;
class UserController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected UserRepository $userRepository,
protected GroupRepository $groupRepository,
protected RoleRepository $roleRepository
) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(UserDataGrid::class)->process();
}
$roles = $this->roleRepository->all();
$groups = $this->groupRepository->all();
return view('admin::settings.users.index', compact('roles', 'groups'));
}
/**
* Store a newly created resource in storage.
*/
public function store(): View|JsonResponse
{
$this->validate(request(), [
'email' => 'required|email|unique:users,email',
'name' => 'required',
'password' => 'nullable',
'confirm_password' => 'nullable|required_with:password|same:password',
'role_id' => 'required',
'status' => 'boolean|in:0,1',
'view_permission' => 'string|in:global,group,individual',
]);
$data = request()->all();
if (
isset($data['password'])
&& $data['password']
) {
$data['password'] = bcrypt($data['password']);
}
Event::dispatch('settings.user.create.before');
$admin = $this->userRepository->create($data);
$admin->groups()->sync($data['groups'] ?? []);
try {
Mail::queue(new UserCreatedNotification($admin));
} catch (\Exception $e) {
report($e);
}
Event::dispatch('settings.user.create.after', $admin);
return new JsonResponse([
'data' => $admin,
'message' => trans('admin::app.settings.users.index.create-success'),
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View|JsonResponse
{
$admin = $this->userRepository->with(['role', 'groups'])->findOrFail($id);
return new JsonResponse([
'data' => $admin,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(int $id): JsonResponse
{
$this->validate(request(), [
'email' => 'required|email|unique:users,email,'.$id,
'name' => 'required|string',
'password' => 'nullable|string|min:6',
'confirm_password' => 'nullable|required_with:password|same:password',
'role_id' => 'required|integer|exists:roles,id',
'status' => 'nullable|boolean|in:0,1',
'view_permission' => 'required|string|in:global,group,individual',
]);
$data = request()->all();
if (empty($data['password'])) {
$data = Arr::except($data, ['password', 'confirm_password']);
} else {
$data['password'] = bcrypt($data['password']);
}
$authUser = auth()->guard('user')->user();
if ($authUser->id == $id) {
$data['status'] = true;
}
Event::dispatch('settings.user.update.before', $id);
$admin = $this->userRepository->update($data, $id);
$admin->groups()->sync($data['groups'] ?? []);
Event::dispatch('settings.user.update.after', $admin);
return new JsonResponse([
'data' => $admin,
'message' => trans('admin::app.settings.users.index.update-success'),
]);
}
/**
* Search user results.
*/
public function search(): JsonResource
{
$users = $this->userRepository
->pushCriteria(app(RequestCriteria::class))
->all();
return UserResource::collection($users);
}
/**
* Destroy specified user.
*/
public function destroy(int $id): JsonResponse
{
if ($this->userRepository->count() == 1) {
return new JsonResponse([
'message' => trans('admin::app.settings.users.index.last-delete-error'),
], 400);
}
try {
Event::dispatch('user.admin.delete.before', $id);
$this->userRepository->delete($id);
Event::dispatch('user.admin.delete.after', $id);
return new JsonResponse([
'message' => trans('admin::app.settings.users.index.delete-success'),
], 200);
} catch (\Exception $e) {
}
return new JsonResponse([
'message' => trans('admin::app.settings.users.index.delete-failed'),
], 500);
}
/**
* Mass Update the specified resources.
*/
public function massUpdate(MassUpdateRequest $massDestroyRequest): JsonResponse
{
$count = 0;
$users = $this->userRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
foreach ($users as $users) {
if (auth()->guard('user')->user()->id == $users->id) {
continue;
}
Event::dispatch('settings.user.update.before', $users->id);
$this->userRepository->update([
'status' => $massDestroyRequest->input('value'),
], $users->id);
Event::dispatch('settings.user.update.after', $users->id);
$count++;
}
if (! $count) {
return response()->json([
'message' => trans('admin::app.settings.users.index.mass-update-failed'),
], 400);
}
return response()->json([
'message' => trans('admin::app.settings.users.index.mass-update-success'),
]);
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$count = 0;
$users = $this->userRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
foreach ($users as $user) {
if (auth()->guard('user')->user()->id == $user->id) {
continue;
}
Event::dispatch('settings.user.delete.before', $user->id);
$this->userRepository->delete($user->id);
Event::dispatch('settings.user.delete.after', $user->id);
$count++;
}
if (! $count) {
return response()->json([
'message' => trans('admin::app.settings.users.index.mass-delete-failed'),
], 400);
}
return response()->json([
'message' => trans('admin::app.settings.users.index.mass-delete-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Contact\Repositories\PersonRepository;
use Webkul\Lead\Repositories\LeadRepository;
use Webkul\Lead\Repositories\PipelineRepository;
use Webkul\Lead\Repositories\SourceRepository;
use Webkul\Lead\Repositories\TypeRepository;
use Webkul\WebForm\DataGrids\WebFormDataGrid;
use Webkul\WebForm\Repositories\WebFormRepository;
class WebFormController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected AttributeRepository $attributeRepository,
protected WebFormRepository $webFormRepository,
protected PersonRepository $personRepository,
protected LeadRepository $leadRepository,
protected PipelineRepository $pipelineRepository,
protected SourceRepository $sourceRepository,
protected TypeRepository $typeRepository
) {}
/**
* Display a listing of the email template.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(WebFormDataGrid::class)->process();
}
return view('admin::settings.web-forms.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
$tempAttributes = $this->attributeRepository->findWhereIn('entity_type', ['persons', 'leads']);
$attributes = [];
foreach ($tempAttributes as $attribute) {
if (
$attribute->entity_type == 'persons'
&& in_array($attribute->code, ['name', 'emails', 'contact_numbers'])
) {
$attributes['default'][] = $attribute;
} else {
$attributes['other'][] = $attribute;
}
}
return view('admin::settings.web-forms.create', compact('attributes'));
}
/**
* Store a newly created email templates in storage.
*/
public function store(): RedirectResponse
{
$this->validate(request(), [
'title' => 'required',
'submit_button_label' => 'required',
'submit_success_action' => 'required',
'submit_success_content' => 'required',
]);
Event::dispatch('settings.web_forms.create.before');
$data = request()->all();
$webForm = $this->webFormRepository->create($data);
Event::dispatch('settings.web_forms.create.after', $webForm);
session()->flash('success', trans('admin::app.settings.webforms.index.create-success'));
return redirect()->route('admin.settings.web_forms.index');
}
/**
* Show the form for editing the specified email template.
*/
public function edit(int $id): View
{
$webForm = $this->webFormRepository->findOrFail($id);
$attributes = $this->attributeRepository->findWhere([
['entity_type', 'IN', ['persons', 'leads']],
['id', 'NOTIN', $webForm->attributes()->pluck('attribute_id')->toArray()],
]);
return view('admin::settings.web-forms.edit', compact('webForm', 'attributes'));
}
/**
* Update the specified email template in storage.
*/
public function update(int $id): RedirectResponse
{
$this->validate(request(), [
'title' => 'required',
'submit_button_label' => 'required',
'submit_success_action' => 'required',
'submit_success_content' => 'required',
]);
Event::dispatch('settings.web_forms.update.before', $id);
$data = request()->all();
$webForm = $this->webFormRepository->update($data, $id);
Event::dispatch('settings.web_forms.update.after', $webForm);
session()->flash('success', trans('admin::app.settings.webforms.index.update-success'));
return redirect()->route('admin.settings.web_forms.index');
}
/**
* Remove the specified email template from storage.
*/
public function destroy(int $id): JsonResponse
{
$webForm = $this->webFormRepository->findOrFail($id);
try {
Event::dispatch('settings.web_forms.delete.before', $id);
$webForm->delete($id);
Event::dispatch('settings.web_forms.delete.after', $id);
return response()->json([
'message' => trans('admin::app.settings.webforms.index.delete-success'),
]);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.webforms.index.delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/LocationController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/LocationController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\AttributeForm;
use Webkul\Warehouse\Repositories\LocationRepository;
class LocationController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected LocationRepository $locationRepository) {}
/**
* Search location results
*
* @return \Illuminate\Http\Response
*/
public function search()
{
$results = $this->locationRepository
->pushCriteria(app(RequestCriteria::class))
->all();
return response()->json([
'data' => $results,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(AttributeForm $request): JsonResponse
{
Event::dispatch('settings.location.create.before');
$location = $this->locationRepository->create(request()->all());
Event::dispatch('settings.location.create.after', $location);
return new JsonResponse([
'data' => $location,
'message' => trans('admin::app.settings.warehouses.view.locations.create-success'),
]);
}
/**
* Remove the specified resource from storage.
*
* @return \Illuminate\Http\Response
*/
public function destroy(int $id): JsonResponse
{
$this->locationRepository->findOrFail($id);
try {
Event::dispatch('settings.location.delete.before', $id);
$this->locationRepository->delete($id);
Event::dispatch('settings.location.delete.after', $id);
return new JsonResponse([
'message' => trans('admin::app.settings.warehouses.view.locations.delete-success'),
], 200);
} catch (\Exception $exception) {
return new JsonResponse([
'message' => trans('admin::app.settings.warehouses.view.locations.delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/TypeController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/TypeController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\TypeDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Lead\Repositories\TypeRepository;
class TypeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected TypeRepository $typeRepository) {}
/**
* Display a listing of the type.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(TypeDataGrid::class)->process();
}
return view('admin::settings.types.index');
}
/**
* Store a newly created type in storage.
*/
public function store(): JsonResponse
{
$this->validate(request(), [
'name' => ['required', 'unique:lead_types,name'],
]);
Event::dispatch('settings.type.create.before');
$type = $this->typeRepository->create(request()->only(['name']));
Event::dispatch('settings.type.create.after', $type);
return new JsonResponse([
'data' => $type,
'message' => trans('admin::app.settings.types.index.create-success'),
]);
}
/**
* Show the form for editing the specified type.
*/
public function edit(int $id): View|JsonResponse
{
$type = $this->typeRepository->findOrFail($id);
return new JsonResponse([
'data' => $type,
]);
}
/**
* Update the specified type in storage.
*/
public function update(int $id): JsonResponse
{
$this->validate(request(), [
'name' => 'required|unique:lead_types,name,'.$id,
]);
Event::dispatch('settings.type.update.before', $id);
$type = $this->typeRepository->update(request()->only(['name']), $id);
Event::dispatch('settings.type.update.after', $type);
return new JsonResponse([
'data' => $type,
'message' => trans('admin::app.settings.types.index.update-success'),
]);
}
/**
* Remove the specified type from storage.
*/
public function destroy(int $id): JsonResponse
{
$type = $this->typeRepository->findOrFail($id);
try {
Event::dispatch('settings.type.delete.before', $id);
$type->delete($id);
Event::dispatch('settings.type.delete.after', $id);
return new JsonResponse([
'message' => trans('admin::app.settings.types.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return new JsonResponse([
'message' => trans('admin::app.settings.types.index.delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/SourceController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/SourceController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\SourceDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Lead\Repositories\SourceRepository;
class SourceController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected SourceRepository $sourceRepository) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(SourceDataGrid::class)->process();
}
return view('admin::settings.sources.index');
}
/**
* Store a newly created resource in storage.
*/
public function store(): JsonResponse
{
$this->validate(request(), [
'name' => ['required', 'unique:lead_sources,name'],
]);
Event::dispatch('settings.source.create.before');
$source = $this->sourceRepository->create(request()->only(['name']));
Event::dispatch('settings.source.create.after', $source);
return new JsonResponse([
'data' => $source,
'message' => trans('admin::app.settings.sources.index.create-success'),
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View|JsonResponse
{
$source = $this->sourceRepository->findOrFail($id);
return new JsonResponse([
'data' => $source,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(int $id): JsonResponse
{
$this->validate(request(), [
'name' => 'required|unique:lead_sources,name,'.$id,
]);
Event::dispatch('settings.source.update.before', $id);
$source = $this->sourceRepository->update(request()->only(['name']), $id);
Event::dispatch('settings.source.update.after', $source);
return new JsonResponse([
'data' => $source,
'message' => trans('admin::app.settings.sources.index.update-success'),
]);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$source = $this->sourceRepository->findOrFail($id);
if ($source->leads()->count() > 0) {
return new JsonResponse([
'message' => trans('admin::app.settings.sources.index.delete-failed-associated-leads'),
], 400);
}
try {
Event::dispatch('settings.source.delete.before', $id);
$source->delete();
Event::dispatch('settings.source.delete.after', $id);
return new JsonResponse([
'message' => trans('admin::app.settings.sources.index.delete-success'),
], 200);
} catch (Exception $exception) {
return new JsonResponse([
'message' => trans('admin::app.settings.sources.index.delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/WebhookController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/WebhookController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\WebhookDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Requests\WebhookRequest;
use Webkul\Automation\Repositories\WebhookRepository;
class WebhookController extends Controller
{
public function __construct(protected WebhookRepository $webhookRepository) {}
/**
* Display the listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(WebhookDataGrid::class)->process();
}
return view('admin::settings.webhook.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::settings.webhook.create');
}
/**
* Store the newly created resource in storage.
*/
public function store(WebhookRequest $webhookRequest): RedirectResponse
{
Event::dispatch('settings.webhook.create.before');
$webhook = $this->webhookRepository->create($webhookRequest->validated());
Event::dispatch('settings.webhook.create.after', $webhook);
session()->flash('success', trans('admin::app.settings.webhooks.index.create-success'));
return redirect()->route('admin.settings.webhooks.index');
}
/**
* Store the newly created resource in storage.
*/
public function edit(int $id): View
{
$webhook = $this->webhookRepository->findOrFail($id);
return view('admin::settings.webhook.edit', compact('webhook'));
}
/**
* Update the specified resource in storage.
*/
public function update(WebhookRequest $webhookRequest, int $id): RedirectResponse
{
Event::dispatch('settings.webhook.update.before', $id);
$webhook = $this->webhookRepository->update($webhookRequest->validated(), $id);
Event::dispatch('settings.webhook.update.after', $webhook);
session()->flash('success', trans('admin::app.settings.webhooks.index.update-success'));
return redirect()->route('admin.settings.webhooks.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$webhook = $this->webhookRepository->findOrFail($id);
Event::dispatch('settings.webhook.delete.before', $id);
$webhook?->delete();
Event::dispatch('settings.webhook.delete.after', $id);
return response()->json([
'message' => trans('admin::app.settings.webhooks.index.delete-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/WorkflowController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/WorkflowController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\WorkflowDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Automation\Repositories\WorkflowRepository;
class WorkflowController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected WorkflowRepository $workflowRepository) {}
/**
* Display a listing of the workflow.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(WorkflowDataGrid::class)->process();
}
return view('admin::settings.workflows.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::settings.workflows.create');
}
/**
* Store a newly created workflow in storage.
*/
public function store(): RedirectResponse
{
$this->validate(request(), [
'name' => 'required',
]);
Event::dispatch('settings.workflow.create.before');
$workflow = $this->workflowRepository->create(request()->all());
Event::dispatch('settings.workflow.create.after', $workflow);
session()->flash('success', trans('admin::app.settings.workflows.index.create-success'));
return redirect()->route('admin.settings.workflows.index');
}
/**
* Show the form for editing the specified workflow.
*/
public function edit(int $id): View
{
$workflow = $this->workflowRepository->findOrFail($id);
return view('admin::settings.workflows.edit', compact('workflow'));
}
/**
* Update the specified workflow in storage.
*/
public function update(int $id): RedirectResponse
{
$this->validate(request(), [
'name' => 'required',
]);
Event::dispatch('settings.workflow.update.before', $id);
$workflow = $this->workflowRepository->update(request()->all(), $id);
Event::dispatch('settings.workflow.update.after', $workflow);
session()->flash('success', trans('admin::app.settings.workflows.index.update-success'));
return redirect()->route('admin.settings.workflows.index');
}
/**
* Remove the specified workflow from storage.
*/
public function destroy(int $id): JsonResponse
{
$workflow = $this->workflowRepository->findOrFail($id);
try {
Event::dispatch('settings.workflow.delete.before', $id);
$workflow->delete($id);
Event::dispatch('settings.workflow.delete.after', $id);
return response()->json([
'message' => trans('admin::app.settings.workflows.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.workflows.index.delete-failed'),
], 400);
}
return response()->json([
'message' => trans('admin::app.settings.workflows.index.delete-failed'),
], 400);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/TagController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/TagController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\DataGrids\Settings\TagDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Resources\TagResource;
use Webkul\Tag\Repositories\TagRepository;
class TagController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected TagRepository $tagRepository) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(TagDataGrid::class)->process();
}
return view('admin::settings.tags.index');
}
/**
* Store a newly created resource in storage.
*/
public function store(): JsonResponse
{
$this->validate(request(), [
'name' => ['required', 'unique:tags,name', 'max:50'],
]);
Event::dispatch('settings.tag.create.before');
$tag = $this->tagRepository->create(array_merge(request()->only([
'name',
'color',
]), [
'user_id' => auth()->guard('user')->user()->id,
]));
Event::dispatch('settings.tag.create.after', $tag);
return new JsonResponse([
'data' => new TagResource($tag),
'message' => trans('admin::app.settings.tags.index.create-success'),
]);
}
/**
* Show the form for editing the specified tag.
*/
public function edit(int $id): View|JsonResponse
{
$tag = $this->tagRepository->findOrFail($id);
return new JsonResponse([
'data' => $tag,
]);
}
/**
* Update the specified tag in storage.
*/
public function update(int $id): JsonResponse
{
$this->validate(request(), [
'name' => 'required|max:50|unique:tags,name,'.$id,
]);
Event::dispatch('settings.tag.update.before', $id);
$tag = $this->tagRepository->update(request()->only([
'name',
'color',
]), $id);
Event::dispatch('settings.tag.update.after', $tag);
return new JsonResponse([
'data' => new TagResource($tag),
'message' => trans('admin::app.settings.tags.index.update-success'),
]);
}
/**
* Remove the specified type from storage.
*/
public function destroy(int $id): JsonResponse
{
$tag = $this->tagRepository->findOrFail($id);
try {
Event::dispatch('settings.tag.delete.before', $id);
$tag->delete($id);
Event::dispatch('settings.tag.delete.after', $id);
return new JsonResponse([
'message' => trans('admin::app.settings.tags.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return new JsonResponse([
'message' => trans('admin::app.settings.tags.index.delete-failed'),
], 400);
}
}
/**
* Search tag results
*
* @return \Illuminate\Http\Response
*/
public function search()
{
$tags = $this->tagRepository
->pushCriteria(app(RequestCriteria::class))
->all();
return TagResource::collection($tags);
}
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$indices = $massDestroyRequest->input('indices');
try {
foreach ($indices as $index) {
Event::dispatch('settings.tag.delete.before', $index);
$this->tagRepository->delete($index);
Event::dispatch('settings.tag.delete.after', $index);
}
return new JsonResponse([
'message' => trans('admin::app.customers.reviews.index.datagrid.mass-delete-success'),
], 200);
} catch (\Exception $e) {
return new JsonResponse([
'message' => $e->getMessage(),
], 500);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/GroupController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/GroupController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\GroupDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\User\Repositories\GroupRepository;
class GroupController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected GroupRepository $groupRepository) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(GroupDataGrid::class)->process();
}
return view('admin::settings.groups.index');
}
/**
* Store a newly created resource in storage.
*/
public function store(): JsonResponse
{
$this->validate(request(), [
'name' => 'required|unique:groups,name|max:50',
'description' => 'required|max:250',
]);
Event::dispatch('settings.group.create.before');
$group = $this->groupRepository->create(request()->only([
'name',
'description',
]));
Event::dispatch('settings.group.create.after', $group);
return new JsonResponse([
'data' => $group,
'message' => trans('admin::app.settings.groups.index.create-success'),
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): JsonResource
{
$group = $this->groupRepository->findOrFail($id);
return new JsonResource([
'data' => $group,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(int $id): JsonResponse
{
$this->validate(request(), [
'name' => 'required|max:50|unique:groups,name,'.$id,
'description' => 'required|max:250',
]);
Event::dispatch('settings.group.update.before', $id);
$group = $this->groupRepository->update(request()->only([
'name',
'description',
]), $id);
Event::dispatch('settings.group.update.after', $group);
return new JsonResponse([
'data' => $group,
'message' => trans('admin::app.settings.groups.index.update-success'),
]);
}
/**
* Remove the specified resource from storage.
*
* @return \Illuminate\Http\Response
*/
public function destroy(int $id): JsonResponse
{
$group = $this->groupRepository->findOrFail($id);
if ($group->users()->exists()) {
return response()->json([
'message' => trans('admin::app.settings.groups.index.delete-failed-associated-users'),
], 400);
}
try {
Event::dispatch('settings.group.delete.before', $id);
$group->delete($id);
Event::dispatch('settings.group.delete.after', $id);
return new JsonResponse([
'message' => trans('admin::app.settings.groups.index.destroy-success'),
], 200);
} catch (\Exception $exception) {
return new JsonResponse([
'message' => trans('admin::app.settings.groups.index.delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/PipelineController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/PipelineController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\PipelineDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\PipelineForm;
use Webkul\Lead\Repositories\PipelineRepository;
class PipelineController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected PipelineRepository $pipelineRepository) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(PipelineDataGrid::class)->process();
}
return view('admin::settings.pipelines.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::settings.pipelines.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(PipelineForm $request): RedirectResponse
{
$request->validated();
$request->merge([
'is_default' => request()->has('is_default') ? 1 : 0,
]);
Event::dispatch('settings.pipeline.create.before');
$pipeline = $this->pipelineRepository->create($request->all());
Event::dispatch('settings.pipeline.create.after', $pipeline);
session()->flash('success', trans('admin::app.settings.pipelines.index.create-success'));
return redirect()->route('admin.settings.pipelines.index');
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$pipeline = $this->pipelineRepository->findOrFail($id);
return view('admin::settings.pipelines.edit', compact('pipeline'));
}
/**
* Update the specified resource in storage.
*/
public function update(PipelineForm $request, int $id): RedirectResponse
{
$request->validated();
$isDefault = request()->has('is_default') ? 1 : 0;
if (! $isDefault) {
$defaultCount = $this->pipelineRepository->findWhere(['is_default' => 1])->count();
$pipeline = $this->pipelineRepository->find($id);
if (
$defaultCount === 1
&& $pipeline->is_default
) {
session()->flash('error', trans('admin::app.settings.pipelines.index.default-required'));
return redirect()->back();
}
}
$request->merge(['is_default' => $isDefault]);
Event::dispatch('settings.pipeline.update.before', $id);
$pipeline = $this->pipelineRepository->update($request->all(), $id);
Event::dispatch('settings.pipeline.update.after', $pipeline);
session()->flash('success', trans('admin::app.settings.pipelines.index.update-success'));
return redirect()->route('admin.settings.pipelines.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id): JsonResponse
{
$pipeline = $this->pipelineRepository->findOrFail($id);
if ($pipeline->is_default) {
return response()->json([
'message' => trans('admin::app.settings.pipelines.index.default-delete-error'),
], 400);
} else {
$defaultPipeline = $this->pipelineRepository->getDefaultPipeline();
$pipeline->leads()->update([
'lead_pipeline_id' => $defaultPipeline->id,
'lead_pipeline_stage_id' => $defaultPipeline->stages()->first()->id,
]);
}
try {
Event::dispatch('settings.pipeline.delete.before', $id);
$this->pipelineRepository->delete($id);
Event::dispatch('settings.pipeline.delete.after', $id);
return response()->json([
'message' => trans('admin::app.settings.pipelines.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.pipelines.index.delete-failed'),
], 400);
}
return response()->json([
'message' => trans('admin::app.settings.pipelines.index.delete-failed'),
], 400);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/RoleController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/RoleController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\RoleDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\User\Repositories\RoleRepository;
class RoleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected RoleRepository $roleRepository) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(RoleDataGrid::class)->process();
}
return view('admin::settings.roles.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::settings.roles.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(): RedirectResponse
{
$this->validate(request(), [
'name' => 'required',
'permission_type' => 'required|in:all,custom',
'description' => 'required',
]);
if (request('permission_type') == 'custom') {
$this->validate(request(), [
'permissions' => 'required',
]);
}
Event::dispatch('settings.role.create.before');
$data = request()->only([
'name',
'description',
'permission_type',
'permissions',
]);
$role = $this->roleRepository->create($data);
Event::dispatch('settings.role.create.after', $role);
session()->flash('success', trans('admin::app.settings.roles.index.create-success'));
return redirect()->route('admin.settings.roles.index');
}
/**
* Show the form for editing the specified resource.
*/
public function edit(int $id): View
{
$role = $this->roleRepository->findOrFail($id);
return view('admin::settings.roles.edit', compact('role'));
}
/**
* Update the specified resource in storage.
*/
public function update(int $id): RedirectResponse
{
$this->validate(request(), [
'name' => 'required',
'permission_type' => 'required|in:all,custom',
'description' => 'required',
'permissions' => 'required_if:permission_type,custom',
]);
Event::dispatch('settings.role.update.before', $id);
$data = array_merge(request()->only([
'name',
'description',
'permission_type',
]), [
'permissions' => request()->has('permissions') ? request('permissions') : [],
]);
$role = $this->roleRepository->update($data, $id);
Event::dispatch('settings.role.update.after', $role);
session()->flash('success', trans('admin::app.settings.roles.index.update-success'));
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$response = [
'responseCode' => 400,
];
$role = $this->roleRepository->findOrFail($id);
if ($role->users && $role->users->count() >= 1) {
$response['message'] = trans('admin::app.settings.roles.index.being-used');
session()->flash('error', $response['message']);
} elseif ($this->roleRepository->count() == 1) {
$response['message'] = trans('admin::app.settings.roles.index.last-delete-error');
session()->flash('error', $response['message']);
} else {
try {
Event::dispatch('settings.role.delete.before', $id);
if (auth()->guard('user')->user()->role_id == $id) {
$response['message'] = trans('admin::app.settings.roles.index.current-role-delete-error');
} else {
$this->roleRepository->delete($id);
Event::dispatch('settings.role.delete.after', $id);
$message = trans('admin::app.settings.roles.index.delete-success');
$response = [
'responseCode' => 200,
'message' => $message,
];
session()->flash('success', $message);
}
} catch (\Exception $exception) {
$message = $exception->getMessage();
$response['message'] = $message;
session()->flash('error', $message);
}
}
return response()->json($response, $response['responseCode']);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/EventController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/EventController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings\Marketing;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\Marketing\EventDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Marketing\Repositories\EventRepository;
class EventController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct(protected EventRepository $eventRepository) {}
/**
* Display a listing of the marketing events.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(EventDataGrid::class)->process();
}
return view('admin::settings.marketing.events.index');
}
/**
* Store a newly created marketing event in storage.
*/
public function store(): JsonResponse
{
$validatedData = $this->validate(request(), [
'name' => 'required|max:60',
'description' => 'required',
'date' => 'required|date|after_or_equal:today',
]);
Event::dispatch('settings.marketing.events.create.before');
$marketingEvent = $this->eventRepository->create($validatedData);
Event::dispatch('settings.marketing.events.create.after', $marketingEvent);
return response()->json([
'message' => trans('admin::app.settings.marketing.events.index.create-success'),
'data' => $marketingEvent,
]);
}
/**
* Update the specified marketing event in storage.
*/
public function update(int $id): JsonResponse
{
$validatedData = $this->validate(request(), [
'name' => 'required|max:60',
'description' => 'required',
'date' => 'required|date|after_or_equal:today',
]);
Event::dispatch('settings.marketing.events.update.before', $id);
$marketingEvent = $this->eventRepository->update($validatedData, $id);
Event::dispatch('settings.marketing.events.update.after', $marketingEvent);
return response()->json([
'message' => trans('admin::app.settings.marketing.events.index.update-success'),
'data' => $marketingEvent,
]);
}
/**
* Remove the specified marketing event from storage.
*/
public function destroy(int $id): JsonResponse
{
$event = $this->eventRepository->findOrFail($id);
if ($event->campaigns->isNotEmpty()) {
return response()->json([
'message' => trans('admin::app.settings.marketing.events.index.delete-failed-associated-campaigns'),
], 422);
}
Event::dispatch('settings.marketing.events.delete.before', $event);
$this->eventRepository->delete($event->id);
Event::dispatch('settings.marketing.events.delete.after', $event);
return response()->json([
'message' => trans('admin::app.settings.marketing.events.index.delete-success'),
]);
}
/**
* Remove the specified marketing events from storage.
*/
public function massDestroy(MassDestroyRequest $request): JsonResponse
{
try {
$events = $this->eventRepository->findWhereIn('id', $request->input('indices', []));
$deletedCount = 0;
$blockedCount = 0;
foreach ($events as $event) {
if (
$event->campaigns
&& $event->campaigns->isNotEmpty()
) {
$blockedCount++;
continue;
}
Event::dispatch('settings.marketing.events.delete.before', $event);
$this->eventRepository->delete($event->id);
Event::dispatch('settings.marketing.events.delete.after', $event);
$deletedCount++;
}
$statusCode = 200;
switch (true) {
case $deletedCount > 0 && $blockedCount === 0:
$message = trans('admin::app.settings.marketing.events.index.mass-delete-success');
break;
case $deletedCount > 0 && $blockedCount > 0:
$message = trans('admin::app.settings.marketing.events.index.partial-delete-warning');
break;
case $deletedCount === 0 && $blockedCount > 0:
$message = trans('admin::app.settings.marketing.events.index.none-delete-warning');
$statusCode = 400;
break;
default:
$message = trans('admin::app.settings.marketing.events.index.no-selection');
$statusCode = 400;
break;
}
return response()->json(['message' => $message], $statusCode);
} catch (Exception $e) {
return response()->json([
'message' => trans('admin::app.settings.marketing.events.index.mass-delete-failed'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/CampaignsController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/CampaignsController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings\Marketing;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\Marketing\CampaignDatagrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\EmailTemplate\Repositories\EmailTemplateRepository;
use Webkul\Marketing\Repositories\CampaignRepository;
use Webkul\Marketing\Repositories\EventRepository;
class CampaignsController extends Controller
{
/**
* Create new a controller instance.
*/
public function __construct(
protected CampaignRepository $campaignRepository,
protected EventRepository $eventRepository,
protected EmailTemplateRepository $emailTemplateRepository,
) {}
/**
* Display a listing of the marketing campaigns.
*/
public function index(): View|JsonResponse
{
if (request()->isXmlHttpRequest()) {
return datagrid(CampaignDatagrid::class)->process();
}
return view('admin::settings.marketing.campaigns.index');
}
/**
* Get marketing events.
*/
public function getEvents(): JsonResponse
{
$events = $this->eventRepository->get(['id', 'name']);
return response()->json([
'data' => $events,
]);
}
/**
* Get Email Templates.
*/
public function getEmailTemplates(): JsonResponse
{
$emailTemplates = $this->emailTemplateRepository->get(['id', 'name']);
return response()->json([
'data' => $emailTemplates,
]);
}
/**
* Store a newly created marketing campaign in storage.
*/
public function store(): JsonResponse
{
$validatedData = $this->validate(request(), [
'name' => 'required|string|max:255',
'subject' => 'required|string|max:255',
'marketing_template_id' => 'required|exists:email_templates,id',
'marketing_event_id' => 'required|exists:marketing_events,id',
'status' => 'sometimes|required|in:0,1',
]);
Event::dispatch('settings.marketing.campaigns.create.before');
$marketingCampaign = $this->campaignRepository->create($validatedData);
Event::dispatch('settings.marketing.campaigns.create.after', $marketingCampaign);
return response()->json([
'message' => trans('admin::app.settings.marketing.campaigns.index.create-success'),
]);
}
/**
* Show the specified Resource.
*/
public function show(int $id): JsonResponse
{
$campaign = $this->campaignRepository->findOrFail($id);
return response()->json([
'data' => $campaign,
]);
}
/**
* Update the specified marketing campaign in storage.
*/
public function update(int $id): JsonResponse
{
$validatedData = $this->validate(request(), [
'name' => 'required|string|max:255',
'subject' => 'required|string|max:255',
'marketing_template_id' => 'required|exists:email_templates,id',
'marketing_event_id' => 'required|exists:marketing_events,id',
'status' => 'sometimes|required|in:0,1',
]);
Event::dispatch('settings.marketing.campaigns.update.before', $id);
$marketingCampaign = $this->campaignRepository->update($validatedData, $id);
Event::dispatch('settings.marketing.campaigns.update.after', $marketingCampaign);
return response()->json([
'message' => trans('admin::app.settings.marketing.campaigns.index.update-success'),
]);
}
/**
* Remove the specified marketing campaign from storage.
*/
public function destroy(int $id): JsonResponse
{
Event::dispatch('settings.marketing.campaigns.delete.before', $id);
$this->campaignRepository->delete($id);
Event::dispatch('settings.marketing.campaigns.delete.after', $id);
return response()->json([
'message' => trans('admin::app.settings.marketing.campaigns.index.delete-success'),
]);
}
/**
* Remove the specified marketing campaigns from storage.
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$campaigns = $this->campaignRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
foreach ($campaigns as $campaign) {
Event::dispatch('settings.marketing.campaigns.delete.before', $campaign);
$this->campaignRepository->delete($campaign->id);
Event::dispatch('settings.marketing.campaigns.delete.after', $campaign);
}
return response()->json([
'message' => trans('admin::app.settings.marketing.campaigns.index.mass-delete-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/DataTransfer/ImportController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/DataTransfer/ImportController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings\DataTransfer;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\DataTransfer\ImportDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\DataTransfer\Helpers\Import;
use Webkul\DataTransfer\Repositories\ImportRepository;
class ImportController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected ImportRepository $importRepository,
protected Import $importHelper
) {}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(ImportDataGrid::class)->process();
}
return view('admin::settings.data-transfer.imports.index');
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::settings.data-transfer.imports.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(): RedirectResponse
{
$importers = array_keys(config('importers'));
$this->validate(request(), [
'type' => 'required|in:'.implode(',', $importers),
'action' => 'required:in:append,delete',
'validation_strategy' => 'required:in:stop-on-errors,skip-errors',
'allowed_errors' => 'required|integer|min:0',
'field_separator' => 'required',
'file' => 'required|mimes:csv,xls,xlsx,txt',
]);
Event::dispatch('data_transfer.imports.create.before');
$data = request()->only([
'type',
'action',
'process_in_queue',
'validation_strategy',
'validation_strategy',
'allowed_errors',
'field_separator',
]);
if (! isset($data['process_in_queue'])) {
$data['process_in_queue'] = false;
} else {
$data['process_in_queue'] = true;
}
$import = $this->importRepository->create(
array_merge(
[
'file_path' => request()->file('file')->storeAs(
'imports',
time().'-'.request()->file('file')->getClientOriginalName(),
'public'
),
],
$data
)
);
Event::dispatch('data_transfer.imports.create.after', $import);
session()->flash('success', trans('admin::app.settings.data-transfer.imports.create-success'));
return redirect()->route('admin.settings.data_transfer.imports.import', $import->id);
}
/**
* Show the form for editing a new resource.
*/
public function edit(int $id): View
{
$import = $this->importRepository->findOrFail($id);
return view('admin::settings.data-transfer.imports.edit', compact('import'));
}
/**
* Update a resource in storage.
*/
public function update(int $id): RedirectResponse
{
$importers = array_keys(config('importers'));
$import = $this->importRepository->findOrFail($id);
$this->validate(request(), [
'type' => 'required|in:'.implode(',', $importers),
'action' => 'required:in:append,delete',
'validation_strategy' => 'required:in:stop-on-errors,skip-errors',
'allowed_errors' => 'required|integer|min:0',
'field_separator' => 'required',
'file' => 'mimes:csv,xls,xlsx,txt',
]);
Event::dispatch('data_transfer.imports.update.before');
$data = array_merge(
request()->only([
'type',
'action',
'process_in_queue',
'validation_strategy',
'validation_strategy',
'allowed_errors',
'field_separator',
]),
[
'state' => 'pending',
'processed_rows_count' => 0,
'invalid_rows_count' => 0,
'errors_count' => 0,
'errors' => null,
'error_file_path' => null,
'started_at' => null,
'completed_at' => null,
'summary' => null,
]
);
Storage::disk('public')->delete($import->error_file_path ?? '');
if (request()->file('file') && request()->file('file')->isValid()) {
Storage::disk('public')->delete($import->file_path);
$data['file_path'] = request()->file('file')->storeAs(
'imports',
time().'-'.request()->file('file')->getClientOriginalName(),
'public'
);
}
if (! isset($data['process_in_queue'])) {
$data['process_in_queue'] = false;
}
$import = $this->importRepository->update($data, $import->id);
Event::dispatch('data_transfer.imports.update.after', $import);
session()->flash('success', trans('admin::app.settings.data-transfer.imports.update-success'));
return redirect()->route('admin.settings.data_transfer.imports.import', $import->id);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$import = $this->importRepository->findOrFail($id);
try {
Storage::disk('public')->delete($import->file_path);
Storage::disk('public')->delete($import->error_file_path ?? '');
$this->importRepository->delete($id);
return response()->json([
'message' => trans('admin::app.settings.data-transfer.imports.delete-success'),
]);
} catch (\Exception $e) {
}
return response()->json([
'message' => trans('admin::app.settings.data-transfer.imports.delete-failed'),
], 500);
}
/**
* Show the form for creating a new resource.
*/
public function import(int $id): View
{
$import = $this->importRepository->findOrFail($id);
$isValid = $this->importHelper
->setImport($import)
->isValid();
if ($import->state == Import::STATE_LINKING) {
if ($this->importHelper->isIndexingRequired()) {
$state = Import::STATE_INDEXING;
} else {
$state = Import::STATE_COMPLETED;
}
} elseif ($import->state == Import::STATE_INDEXING) {
$state = Import::STATE_COMPLETED;
} else {
$state = Import::STATE_COMPLETED;
}
$stats = $this->importHelper->stats($state);
$import->unsetRelations();
return view('admin::settings.data-transfer.imports.import', compact('import', 'isValid', 'stats'));
}
/**
* Store a newly created resource in storage.
*/
public function validateImport(int $id): JsonResponse
{
$import = $this->importRepository->findOrFail($id);
$isValid = $this->importHelper
->setImport($import)
->validate();
return new JsonResponse([
'is_valid' => $isValid,
'import' => $this->importHelper->getImport()->unsetRelations(),
]);
}
/**
* Store a newly created resource in storage.
*/
public function start(int $id): JsonResponse
{
$import = $this->importRepository->findOrFail($id);
if (! $import->processed_rows_count) {
return new JsonResponse([
'message' => trans('admin::app.settings.data-transfer.imports.nothing-to-import'),
], 400);
}
$this->importHelper->setImport($import);
if (! $this->importHelper->isValid()) {
return new JsonResponse([
'message' => trans('admin::app.settings.data-transfer.imports.not-valid'),
], 400);
}
if (
$import->process_in_queue
&& config('queue.default') == 'sync'
) {
return new JsonResponse([
'message' => trans('admin::app.settings.data-transfer.imports.setup-queue-error'),
], 400);
}
/**
* Set the import state to processing
*/
if ($import->state == Import::STATE_VALIDATED) {
$this->importHelper->started();
}
/**
* Get the first pending batch to import
*/
$importBatch = $import->batches->where('state', Import::STATE_PENDING)->first();
if ($importBatch) {
/**
* Start the import process
*/
try {
if ($import->process_in_queue) {
$this->importHelper->start();
} else {
$this->importHelper->start($importBatch);
}
} catch (\Exception $e) {
return new JsonResponse([
'message' => $e->getMessage(),
], 400);
}
} else {
if ($this->importHelper->isLinkingRequired()) {
$this->importHelper->linking();
} elseif ($this->importHelper->isIndexingRequired()) {
$this->importHelper->indexing();
} else {
$this->importHelper->completed();
}
}
return new JsonResponse([
'stats' => $this->importHelper->stats(Import::STATE_PROCESSED),
'import' => $this->importHelper->getImport()->unsetRelations(),
]);
}
/**
* Store a newly created resource in storage.
*/
public function link(int $id): JsonResponse
{
$import = $this->importRepository->findOrFail($id);
if (! $import->processed_rows_count) {
return new JsonResponse([
'message' => trans('admin::app.settings.data-transfer.imports.nothing-to-import'),
], 400);
}
$this->importHelper->setImport($import);
if (! $this->importHelper->isValid()) {
return new JsonResponse([
'message' => trans('admin::app.settings.data-transfer.imports.not-valid'),
], 400);
}
/**
* Set the import state to linking
*/
if ($import->state == Import::STATE_PROCESSED) {
$this->importHelper->linking();
}
/**
* Get the first processing batch to link
*/
$importBatch = $import->batches->where('state', Import::STATE_PROCESSED)->first();
/**
* Set the import state to linking/completed
*/
if ($importBatch) {
/**
* Start the resource linking process
*/
try {
$this->importHelper->link($importBatch);
} catch (\Exception $e) {
return new JsonResponse([
'message' => $e->getMessage(),
], 400);
}
} else {
if ($this->importHelper->isIndexingRequired()) {
$this->importHelper->indexing();
} else {
$this->importHelper->completed();
}
}
return new JsonResponse([
'stats' => $this->importHelper->stats(Import::STATE_LINKED),
'import' => $this->importHelper->getImport()->unsetRelations(),
]);
}
/**
* Store a newly created resource in storage.
*/
public function indexData(int $id): JsonResponse
{
$import = $this->importRepository->findOrFail($id);
if (! $import->processed_rows_count) {
return new JsonResponse([
'message' => trans('admin::app.settings.data-transfer.imports.nothing-to-import'),
], 400);
}
$this->importHelper->setImport($import);
if (! $this->importHelper->isValid()) {
return new JsonResponse([
'message' => trans('admin::app.settings.data-transfer.imports.not-valid'),
], 400);
}
/**
* Set the import state to linking
*/
if ($import->state == Import::STATE_LINKED) {
$this->importHelper->indexing();
}
/**
* Get the first processing batch to link
*/
$importBatch = $import->batches->where('state', Import::STATE_LINKED)->first();
/**
* Set the import state to linking/completed
*/
if ($importBatch) {
/**
* Start the resource linking process
*/
try {
$this->importHelper->index($importBatch);
} catch (\Exception $e) {
return new JsonResponse([
'message' => $e->getMessage(),
], 400);
}
} else {
/**
* Set the import state to completed
*/
$this->importHelper->completed();
}
return new JsonResponse([
'stats' => $this->importHelper->stats(Import::STATE_INDEXED),
'import' => $this->importHelper->getImport()->unsetRelations(),
]);
}
/**
* Returns import stats
*/
public function stats(int $id, string $state = Import::STATE_PROCESSED): JsonResponse
{
$import = $this->importRepository->findOrFail($id);
$stats = $this->importHelper
->setImport($import)
->stats($state);
return new JsonResponse([
'stats' => $stats,
'import' => $this->importHelper->getImport()->unsetRelations(),
]);
}
/**
* Download import error report
*/
public function downloadSample(string $type)
{
$importer = config('importers.'.$type);
return Storage::download($importer['sample_path']);
}
/**
* Download import error report
*/
public function download(int $id)
{
$import = $this->importRepository->findOrFail($id);
return Storage::disk('public')->download($import->file_path);
}
/**
* Download import error report
*/
public function downloadErrorReport(int $id)
{
$import = $this->importRepository->findOrFail($id);
return Storage::disk('public')->download($import->file_path);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/Warehouse/WarehouseController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/Warehouse/WarehouseController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings\Warehouse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\DataGrids\Product\ProductDataGrid;
use Webkul\Admin\DataGrids\Settings\WarehouseDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\AttributeForm;
use Webkul\Warehouse\Repositories\WarehouseRepository;
class WarehouseController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected WarehouseRepository $warehouseRepository)
{
request()->request->add(['entity_type' => 'warehouses']);
}
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(WarehouseDataGrid::class)->process();
}
return view('admin::settings.warehouses.index');
}
/**
* Search location results
*/
public function search(): JsonResponse
{
$results = $this->warehouseRepository
->pushCriteria(app(RequestCriteria::class))
->all();
return response()->json($results);
}
/**
* Display a listing of the product resource.
*/
public function products(int $id)
{
if (request()->ajax()) {
return datagrid(ProductDataGrid::class)->process();
}
$warehouse = $this->warehouseRepository->findOrFail($id);
return view('admin::settings.warehouses.products', compact('warehouse'));
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('admin::settings.warehouses.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(AttributeForm $request): RedirectResponse
{
Event::dispatch('settings.warehouse.create.before');
$warehouse = $this->warehouseRepository->create($request->all());
Event::dispatch('settings.warehouse.create.after', $warehouse);
session()->flash('success', trans('admin::app.settings.warehouses.index.create-success'));
return redirect()->route('admin.settings.warehouses.index');
}
/**
* Show the form for viewing the specified resource.
*/
public function view(int $id): View
{
$warehouse = $this->warehouseRepository->findOrFail($id);
return view('admin::settings.warehouses.view', compact('warehouse'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function edit($id)
{
$warehouse = $this->warehouseRepository->findOrFail($id);
return view('admin::settings.warehouses.edit', compact('warehouse'));
}
/**
* Update the specified resource in storage.
*/
public function update(AttributeForm $request, int $id): RedirectResponse|JsonResponse
{
Event::dispatch('settings.warehouse.update.before', $id);
$warehouse = $this->warehouseRepository->update($request->all(), $id);
Event::dispatch('settings.warehouse.update.after', $warehouse);
if (request()->ajax()) {
return response()->json([
'data' => $warehouse,
'message' => trans('admin::app.settings.warehouses.index.update-success'),
]);
}
session()->flash('success', trans('admin::app.settings.warehouses.index.update-success'));
return redirect()->route('admin.settings.warehouses.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(int $id): JsonResponse
{
$this->warehouseRepository->findOrFail($id);
try {
Event::dispatch('settings.warehouse.delete.before', $id);
$this->warehouseRepository->delete($id);
Event::dispatch('settings.warehouse.delete.after', $id);
return response()->json([
'message' => trans('admin::app.settings.warehouses.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.warehouses.index.delete-success'),
], 400);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/Warehouse/ActivityController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/Warehouse/ActivityController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings\Warehouse;
use Webkul\Activity\Repositories\ActivityRepository;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Resources\ActivityResource;
use Webkul\Email\Repositories\EmailRepository;
class ActivityController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected ActivityRepository $activityRepository,
protected EmailRepository $emailRepository
) {}
/**
* Display a listing of the resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function index($id)
{
$activities = $this->activityRepository
->leftJoin('warehouse_activities', 'activities.id', '=', 'warehouse_activities.activity_id')
->where('warehouse_activities.warehouse_id', $id)
->get();
return ActivityResource::collection($this->concatEmail($activities));
}
/**
* Store a newly created resource in storage.
*/
public function concatEmail($activities)
{
return $activities->sortByDesc('id')->sortByDesc('created_at');
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Controllers/Settings/Warehouse/TagController.php | packages/Webkul/Admin/src/Http/Controllers/Settings/Warehouse/TagController.php | <?php
namespace Webkul\Admin\Http\Controllers\Settings\Warehouse;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Warehouse\Repositories\WarehouseRepository;
class TagController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected WarehouseRepository $warehouseRepository) {}
/**
* Store a newly created resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function attach($id)
{
Event::dispatch('warehouse.tag.create.before', $id);
$warehouse = $this->warehouseRepository->find($id);
if (! $warehouse->tags->contains(request()->input('tag_id'))) {
$warehouse->tags()->attach(request()->input('tag_id'));
}
Event::dispatch('warehouse.tag.create.after', $warehouse);
return response()->json([
'message' => trans('admin::app.warehouse.view.tags.create-success'),
]);
}
/**
* Remove the specified resource from storage.
*
* @param int $warehouseId
* @return \Illuminate\Http\Response
*/
public function detach($warehouseId)
{
Event::dispatch('warehouse.tag.delete.before', $warehouseId);
$warehouse = $this->warehouseRepository->find($warehouseId);
$warehouse->tags()->detach(request()->input('tag_id'));
Event::dispatch('warehouse.tag.delete.after', $warehouse);
return response()->json([
'message' => trans('admin::app.leads.view.tags.destroy-success'),
]);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Middleware/SanitizeUrl.php | packages/Webkul/Admin/src/Http/Middleware/SanitizeUrl.php | <?php
namespace Webkul\Admin\Http\Middleware;
use Closure;
use Illuminate\Support\Str;
use Webkul\Email\Enums\SupportedFolderEnum;
class SanitizeUrl
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->ajax()) {
return $next($request);
}
$route = $request->route('route');
$sanitizedRoute = Str::of($route)->ascii()->lower()->replaceMatches('/[^a-z0-9_-]/', '')->__toString();
$request->route()->setParameter('route', $sanitizedRoute);
/**
* Whitelist acceptable route values to prevent unexpected input
*/
$allowedRoutes = [
SupportedFolderEnum::INBOX->value,
SupportedFolderEnum::IMPORTANT->value,
SupportedFolderEnum::STARRED->value,
SupportedFolderEnum::DRAFT->value,
SupportedFolderEnum::OUTBOX->value,
SupportedFolderEnum::SENT->value,
SupportedFolderEnum::SPAM->value,
SupportedFolderEnum::TRASH->value,
];
if (! in_array($route, $allowedRoutes, true)) {
abort(401, trans('admin::app.mail.invalid-route'));
}
return $next($request);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Middleware/Bouncer.php | packages/Webkul/Admin/src/Http/Middleware/Bouncer.php | <?php
namespace Webkul\Admin\Http\Middleware;
use Illuminate\Support\Facades\Route;
class Bouncer
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param string|null $guard
* @return mixed
*/
public function handle($request, \Closure $next, $guard = 'user')
{
if (! auth()->guard($guard)->check()) {
return redirect()->route('admin.session.create');
}
/**
* If user status is changed by admin. Then session should be
* logged out.
*/
if (! (bool) auth()->guard($guard)->user()->status) {
auth()->guard($guard)->logout();
session()->flash('error', __('admin::app.errors.401'));
return redirect()->route('admin.session.create');
}
/**
* If somehow the user deleted all permissions, then it should be
* auto logged out and need to contact the administrator again.
*/
if ($this->isPermissionsEmpty()) {
auth()->guard($guard)->logout();
session()->flash('error', __('admin::app.errors.401'));
return redirect()->route('admin.session.create');
}
return $next($request);
}
/**
* Check for user, if they have empty permissions or not except admin.
*
* @return bool
*/
public function isPermissionsEmpty()
{
if (! $role = auth()->guard('user')->user()->role) {
abort(401, 'This action is unauthorized.');
}
if ($role->permission_type === 'all') {
return false;
}
if ($role->permission_type !== 'all' && empty($role->permissions)) {
return true;
}
$this->checkIfAuthorized();
return false;
}
/**
* Check authorization.
*
* @return null
*/
public function checkIfAuthorized()
{
$roles = acl()->getRoles();
if (isset($roles[Route::currentRouteName()])) {
bouncer()->allow($roles[Route::currentRouteName()]);
}
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Middleware/Locale.php | packages/Webkul/Admin/src/Http/Middleware/Locale.php | <?php
namespace Webkul\Admin\Http\Middleware;
use Closure;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
class Locale
{
/**
* The middleware instance.
*
* @return void
*/
public function __construct(
Application $app,
Request $request
) {
$this->app = $app;
$this->request = $request;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function handle($request, Closure $next)
{
app()->setLocale(
core()->getConfigData('general.general.locale_settings.locale')
?: app()->getLocale()
);
return $next($request);
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
krayin/laravel-crm | https://github.com/krayin/laravel-crm/blob/6b6fadfecea0ff5d80aedb9345602ff79e11922d/packages/Webkul/Admin/src/Http/Resources/UserResource.php | packages/Webkul/Admin/src/Http/Resources/UserResource.php | <?php
namespace Webkul\Admin\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'image' => $this->image,
'created_at' => $this->created_at,
'updated_at' => $this->name,
];
}
}
| php | MIT | 6b6fadfecea0ff5d80aedb9345602ff79e11922d | 2026-01-04T15:02:34.361572Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.