1
votes

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.

1
What does a dd($customer) shows after $customer = $this->customers->create( $customerDTO ); ? - marcanuy
When using 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
object(Customer)#325 (20) ...etc - Carlos Goce
It's not the redirect, it's the response. return 'text'; doesn't work either - Carlos Goce

1 Answers

-1
votes

It was a strange problem with the sessions. We get it fixed, not sure why...