Skip to content

[5.4] Ensure Mailable view data is not overridden by order of operations#18322

Merged
taylorotwell merged 2 commits into
laravel:5.4from
jameshulse:5.4
Mar 13, 2017
Merged

[5.4] Ensure Mailable view data is not overridden by order of operations#18322
taylorotwell merged 2 commits into
laravel:5.4from
jameshulse:5.4

Conversation

@jameshulse
Copy link
Copy Markdown
Contributor

@jameshulse jameshulse commented Mar 13, 2017

The markdown(), view() and text() methods on the Mailable class currently override the instances viewData field with their own data parameter (which defaults to an empty array).

This means if any of these methods are called after the with() method that the previous view data supplied in the call to with() is lost.

In the following case the view data is empty:

public function build()
{
    $this->view('sample-view')
         ->with([ 'data' => 'example' ])
         ->text('sample-view_plain');
}

This pull request ensures the viewData is always merged with each subsequent call.

Unit tests are provided which exhibit the incorrect behaviour.

@taylorotwell taylorotwell merged commit b842085 into laravel:5.4 Mar 13, 2017
@jameshulse
Copy link
Copy Markdown
Contributor Author

Thanks @taylorotwell. I can fix the styling issue if you'd like - I'm afraid I didn't run a linter but I'll know for next time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants