Commit c3c8ed1f by Vladislav

refactor

1 parent 3655103f
......@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use App\Models\Tokens;
use App\Models\Variable;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Inertia\Inertia;
class CampaignVariablesController extends Controller
......@@ -16,13 +18,13 @@ class CampaignVariablesController extends Controller
function __invoke(Tokens $token, $campaign_id)
{
if ($token->isMain()) {
return back();
return Redirect::back();
}
$campaign = Tokens::where('type', Tokens::MAIN)->get()->first()->campaignsForEnabled()->with('variables')->find($campaign_id);
if (!$campaign) {
return back();
return Redirect::back();
};
switch (request()->method()) {
......@@ -36,7 +38,7 @@ class CampaignVariablesController extends Controller
case 'POST':
if (request('variable') === 'add') {
request()->validate([
Request::validate([
'name' => $this->rule_variable_name,
'value' => $this->rule_value,
]);
......@@ -47,7 +49,7 @@ class CampaignVariablesController extends Controller
$variable_id = $variable_new->getKey();
$value = request('value');
} else {
request()->validate([
Request::validate([
'variable' => $this->rule_variable,
'value' => $this->rule_value,
]);
......@@ -61,7 +63,7 @@ class CampaignVariablesController extends Controller
],
]);
return back()->with('success', 'Campaign variable added.');
return Redirect::back()->with('success', 'Campaign variable added.');
break;
case 'PUT':
......@@ -69,14 +71,14 @@ class CampaignVariablesController extends Controller
$campaign_variable = $campaign->variables()->find(request('id'));
if (!$campaign_variable) {
return back();
return Redirect::back();
}
if (request()->validate(['name' => $this->rule_variable_name])) {
$campaign_variable->update(request()->only('name'));
}
$campaign_variable->update([
Request::validate(['name' => $this->rule_variable_name])
]);
return back()->with('success', 'Variable name updated.');
return Redirect::back()->with('success', 'Variable name updated.');
break;
......@@ -85,14 +87,14 @@ class CampaignVariablesController extends Controller
$campaign_variable = $campaign->variables()->find(request('id'));
if (!$campaign_variable) {
return back();
return Redirect::back();
}
if (request()->validate(['value' => $this->rule_value])) {
$campaign_variable->update(request()->only('value'));
}
return back()->with('success', 'Campaign variable updated.');
return Redirect::back()->with('success', 'Campaign variable updated.');
break;
case 'DELETE':
......@@ -100,15 +102,15 @@ class CampaignVariablesController extends Controller
$campaign_variable = $campaign->vars()->find(request('id'));
if (!$campaign_variable) {
return back();
return Redirect::back();
}
$campaign_variable->delete();
return back()->with('success', 'Campaign variable deleted.');
return Redirect::back()->with('success', 'Campaign variable deleted.');
break;
}
return back();
return Redirect::back();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!