내 서비스 클래스를 만들었고 리디렉션 할 경로를 선택하기 전에 최소한의 논리 검사를 수행해야하는 handleRedirect()
함수가 있습니다.서비스 클래스 내부로 리디렉션 하시겠습니까?
class LoginService
{
private $CartTable;
private $SessionCustomer;
private $Customer;
public function __construct(Container $SessionCustomer, CartTable $CartTable, Customer $Customer)
{
$this->SessionCustomer = $SessionCustomer;
$this->CartTable = $CartTable;
$this->Customer = $Customer;
$this->prepareSession();
$this->setCartOwner();
$this->handleRedirect();
}
public function prepareSession()
{
// Store user's first name
$this->SessionCustomer->offsetSet('first_name', $this->Customer->first_name);
// Store user id
$this->SessionCustomer->offsetSet('customer_id', $this->Customer->customer_id);
}
public function handleRedirect()
{
// If redirected to log in, or if previous page visited before logging in is cart page:
// Redirect to shipping_info
// Else
// Redirect to/
}
public function setCartOwner()
{
// GET USER ID FROM SESSION
$customer_id = $this->SessionCustomer->offsetGet('customer_id');
// GET CART ID FROM SESSION
$cart_id = $this->SessionCustomer->offsetGet('cart_id');
// UPDATE
$this->CartTable->updateCartCustomerId($customer_id, $cart_id);
}
}
이 서비스는 로그인 또는 등록이 성공한 후 컨트롤러에서 호출됩니다. 여기서 redirect()->toRoute();
에 액세스하는 가장 좋은 방법이 무엇인지 잘 모르겠습니다. (또는 여기에서해야합니다.)
또한 코드 작성 방법에 대한 다른 의견이 있으면 언제든지 남겨 두십시오.
명확하고 참으로 간단, 감사합니다! – herondale