laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

Can’t use param named "message" for view blade file in class extends Notification #1792

Open cocoeyes02 opened 5 years ago

cocoeyes02 commented 5 years ago

Problem

In class extends Notification, I inserted array ['message' => 'hoge'] at view method's second param. Then I executed dd($message) in view blade file, but it’s not result I expected.

For example

return (new MailMessage())
    ->subject('email.hoge')
    ->view(
        'hoge',
        [
            'message' => 'huga'
        ]
    );

hoge.blade.php

dd($message)

Expected

huga

Result

スクリーンショット 2019-08-15 17 45 13

cause

when using Render method Illuminate\Mail\Mailer, $data includes "message" property and SimpleMessage’s property. https://github.com/laravel/framework/blob/5eef06c7b6a21857a41c7eada53303a94b87edad/src/Illuminate/Mail/Mailer.php#L213 https://github.com/laravel/framework/blob/5eef06c7b6a21857a41c7eada53303a94b87edad/src/Illuminate/Notifications/Channels/MailChannel.php#L64

In other words, We can’t insert those keys in array at view method’s second param.

message
level
subject
greeting
salutation
introLines
outroLines
actionText
actionUrl

In my opinion

I think it’s not intuitive. it shouldn’t know "message" and SimpleMessage’s property when render tamplate.

cocoeyes02 commented 5 years ago

The documentation already mentions

Laravel automatically makes the $message variable available to all of your email templates

IMO, rather than doing this (which creates a breaking change for little benefit) the documentation could be updated to better explain that there are reserved words that cannot be used as view parameter variables.

I'll add sentense which explain that there are reserved words that cannot be used as view parameter variables.