문제

I have been working on some old code that was given to me to play with and edit to get familar with and i was wondering if you can see if what i am doing is syntactly sound as im confusing myself with the laravel framework. i basically want to know if im close to what my comments are wanting to do and whether my code and comments marry up or a i missing the point? As im getting the following error message

The error message im getting when running this command through my terminal is

PHP Parse error:  syntax error, unexpected '$email' (T_VARIABLE), expecting '(' in /Libraryenter code here/WebServer/Documents/healthandsafetymonitoringsystem.local/app/commands/IncompleteReportsCommand.php on line 157

my code is as follows

// This function uses the parameters $data that is passed to this function each time
// the fire() function loops through and assigns and determines that there is a duereport
private function sendGeneralManagerEmail($data)
{
    // create an array called 'Park' that is poulated via the $data parameters
    // in the function and is specificly looking for the ParkName entries 
    $data['Park'] = $Park->ParkName;
    //for each item in that array use $ParkName as a key and name each elements $name
    foreach($data['Park'] as $ParkName => $name)
    {
        // Every time i loop through this file get the element $name and 
        // attach this prefix to it
        $email = $name."generalmanager@parkholidays.com";
    }
        // Then send an email with new $email variable as a reciepient and sending the $data passed 
        // from the fire() function and used within this functions parameters
        Mail::send('emails.GeneralManager', $data, function($message) use $email
        {
            $message->to( $email, 'General Manager')->subject('[Urgent] Health & Safety Reports');
        });
}

Sorry for the dumb question if there are any articles regarding arrays/data models and php functions in laravel that you suggest reading thatll be great. This is a steep learnign curve as i have gone from plain php coding on notepad ++ to laravel 4 and i cant seem to find a nice tutorial that goes from the start to finish with a complete novice in mind.

Regards mike

올바른 솔루션이 없습니다

다른 팁

Regarding your error

You just have a PHP syntax error. Here's the code you want:

// This function uses the parameters $data that is passed to this function each time
// the fire() function loops through and assigns and determines that there is a duereport
private function sendGeneralManagerEmail($data)
{
    // create an array called 'Park' that is poulated via the $data parameters
    // in the function and is specificly looking for the ParkName entries 
    $data['Park'] = $Park->ParkName;
    //for each item in that array use $ParkName as a key and name each elements $name
    foreach($data['Park'] as $ParkName => $name)
    {
        // Every time i loop through this file get the element $name and 
        // attach this prefix to it
        $email = $name."generalmanager@parkholidays.com";
    }
        // Then send an email with new $email variable as a reciepient and sending the $data passed 
        // from the fire() function and used within this functions parameters
        Mail::send('emails.GeneralManager', $data, function($message) use ($email)
        {
            $message->to( $email, 'General Manager')->subject('[Urgent] Health & Safety Reports');
        });
}

See the use $email you had that I've changed to use ($email) in the closure at the end.

Regarding your more general question about coding

I can see a few things that don't look right to me. Is this code an exact replica of the function or have you removed some code?

It is hard to say more about you code, since it is taken out of context. Writing new code as answer, will confuse you more.

So it is better to:

Subscribe to laracast and you will learn everything you need to know about Laravel. Also there is new, updated Laravel 4.1 documentation

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top