changes
This commit is contained in:
@@ -13,15 +13,46 @@ public function index(Request $request){
|
||||
|
||||
return Inertia::render('Settings/Index', [
|
||||
'actions' => \App\Models\Action::query()
|
||||
->with('decisions')
|
||||
->with(['decisions', 'segment'])
|
||||
->get(),
|
||||
'decisions' => \App\Models\Decision::query()
|
||||
->with('actions')
|
||||
->get(),
|
||||
'segments' => \App\Models\Segment::query()
|
||||
->get()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function storeAction(Request $request)
|
||||
{
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'segment_id' => 'nullable|integer|exists:segments,id',
|
||||
'decisions' => 'nullable|array',
|
||||
'decisions.*.id' => 'required_with:decisions.*|integer|exists:decisions,id',
|
||||
'decisions.*.name' => 'required_with:decisions.*|string|max:50',
|
||||
]);
|
||||
|
||||
$decisionIds = collect($attributes['decisions'] ?? [])->pluck('id')->toArray();
|
||||
|
||||
\DB::transaction(function () use ($attributes, $decisionIds) {
|
||||
/** @var \App\Models\Action $row */
|
||||
$row = \App\Models\Action::create([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'] ?? null,
|
||||
'segment_id' => $attributes['segment_id'] ?? null,
|
||||
]);
|
||||
|
||||
if (!empty($decisionIds)) {
|
||||
$row->decisions()->sync($decisionIds);
|
||||
}
|
||||
});
|
||||
|
||||
return to_route('settings')->with('success', 'Action created successfully!');
|
||||
}
|
||||
|
||||
public function updateAction(int $id, Request $request) {
|
||||
|
||||
$row = \App\Models\Action::findOrFail($id);
|
||||
@@ -29,6 +60,7 @@ public function updateAction(int $id, Request $request) {
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'segment_id' => 'nullable|integer|exists:segments,id',
|
||||
'decisions' => 'nullable|array',
|
||||
'decisions.*.id' => 'required_with:decisions.*|integer|exists:decisions,id',
|
||||
'decisions.*.name' => 'required_with:decisions.*|string|max:50'
|
||||
@@ -39,7 +71,8 @@ public function updateAction(int $id, Request $request) {
|
||||
\DB::transaction(function() use ($attributes, $decisionIds, $row) {
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag']
|
||||
'color_tag' => $attributes['color_tag'],
|
||||
'segment_id' => $attributes['segment_id'] ?? null,
|
||||
]);
|
||||
|
||||
$row->decisions()->sync($decisionIds);
|
||||
@@ -48,4 +81,56 @@ public function updateAction(int $id, Request $request) {
|
||||
return to_route('settings')->with('success', 'Update successful!');
|
||||
|
||||
}
|
||||
|
||||
public function storeDecision(Request $request)
|
||||
{
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'actions' => 'nullable|array',
|
||||
'actions.*.id' => 'required_with:actions.*|integer|exists:actions,id',
|
||||
'actions.*.name' => 'required_with:actions.*|string|max:50',
|
||||
]);
|
||||
|
||||
$actionIds = collect($attributes['actions'] ?? [])->pluck('id')->toArray();
|
||||
|
||||
\DB::transaction(function () use ($attributes, $actionIds) {
|
||||
/** @var \App\Models\Decision $row */
|
||||
$row = \App\Models\Decision::create([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'] ?? null,
|
||||
]);
|
||||
|
||||
if (!empty($actionIds)) {
|
||||
$row->actions()->sync($actionIds);
|
||||
}
|
||||
});
|
||||
|
||||
return to_route('settings')->with('success', 'Decision created successfully!');
|
||||
}
|
||||
|
||||
public function updateDecision(int $id, Request $request)
|
||||
{
|
||||
$row = \App\Models\Decision::findOrFail($id);
|
||||
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'actions' => 'nullable|array',
|
||||
'actions.*.id' => 'required_with:actions.*|integer|exists:actions,id',
|
||||
'actions.*.name' => 'required_with:actions.*|string|max:50',
|
||||
]);
|
||||
|
||||
$actionIds = collect($attributes['actions'] ?? [])->pluck('id')->toArray();
|
||||
|
||||
\DB::transaction(function () use ($attributes, $actionIds, $row) {
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'] ?? null,
|
||||
]);
|
||||
$row->actions()->sync($actionIds);
|
||||
});
|
||||
|
||||
return to_route('settings')->with('success', 'Decision updated successfully!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class Action extends Model
|
||||
use HasFactory;
|
||||
use Searchable;
|
||||
|
||||
protected $fillable = ['name', 'color_tag'];
|
||||
protected $fillable = ['name', 'color_tag', 'segment_id'];
|
||||
|
||||
public function decisions(): BelongsToMany
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ class Activity extends Model
|
||||
'amount',
|
||||
'note',
|
||||
'action_id',
|
||||
'user_id',
|
||||
'decision_id'
|
||||
];
|
||||
|
||||
@@ -25,9 +26,20 @@ class Activity extends Model
|
||||
'action_id',
|
||||
'decision_id',
|
||||
'client_case_id',
|
||||
'user_id',
|
||||
'contract_id'
|
||||
];
|
||||
|
||||
protected static function booted(){
|
||||
static::creating(function (Activity $activity) {
|
||||
if(!isset($activity->user_id)){
|
||||
$activity->user_id = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function action(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Action::class);
|
||||
|
||||
@@ -13,6 +13,8 @@ class Decision extends Model
|
||||
/** @use HasFactory<\Database\Factories\DecisionFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'color_tag'];
|
||||
|
||||
public function actions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Action::class);
|
||||
|
||||
Reference in New Issue
Block a user