First, let's get into the application's context:
We are on CustomerController, which is a Resource Controller sending a post request to the Store method.
This is my store method:
$customerDTO = new \repositories\dtos\CreateCustomerDTO();
$customerDTO->hydrate( Input::All() );
/** @var Customer $customer */
$customer = $this->customers->create( $customerDTO );
if ( $customer != null ){
header('Location: '.url('/customers/'.$customer->clacli));
return Redirect::action('CustomerController@show', array($customer->id) );
}
$userMessage = array(
'messageType' => 'error',
'messageContent' => 'Error creating a new Customer'
);
return Redirect::action('CustomerController@index')
->with(array('userMessage' => $userMessage));
I had to put a "header" because the Redirect call is not working.
When i put this line:
$customer = $this->customers->create( $customerDTO );
All the redirects stops to work.
And what is inside $this->customers? It's just a repository to abstract the database from the controller, i'm going to need to change the database on the near future.
Well, the code inside $this->customers->create is:
return Customer::create( $dto->toArray() );
And it's working, also all the test of my customersRepository are working. It's just a call to the Eloquent Model create method with an array of data.
So i can't figure out why the Redirect is not working. Any tip?
I tried with return 'test'; just after the call to $this->customers->create( $customerDTO); and didn't work either.
Redirect::action, doesn't there need to be a route corresponding to that controller? That's probably the one type of redirect I've not used, so I'm not 100%. - ollieread