lasthourcloud/app/Traits/SaveFromRedirect.php

27 lines
706 B
PHP
Raw Normal View History

2023-08-30 12:46:51 +00:00
<?php
namespace App\Traits;
use Illuminate\Support\Collection;
trait SaveFromRedirect
{
public function saveFromRedirect(string $route, ?Collection $parameters = null)
{
session()->forget('from');
2024-06-10 20:43:34 +00:00
if (! $parameters || $parameters->count() === 0) {
2023-08-30 12:46:51 +00:00
$parameters = $this->parameters;
}
$parameters = collect($parameters) ?? collect([]);
$queries = collect($this->query) ?? collect([]);
$parameters = $parameters->merge($queries);
session(['from' => [
'back' => $this->currentRoute,
'route' => $route,
2024-06-10 20:43:34 +00:00
'parameters' => $parameters,
2023-08-30 12:46:51 +00:00
]]);
2024-06-10 20:43:34 +00:00
2023-08-30 12:46:51 +00:00
return redirect()->route($route);
}
}