horcrux88
horcrux88

Reputation: 331

Extract user email address in Laravel with Artisan::call

I want to know how can I put $user->email in the following code snippet, where the email address is. Everything works well when hard coded in but not when I put $user->email where the email address is - I get error then. Please help. thanks.

        public function runCommand(Request $request){
          $user = User::all();
          $signature = $request->input('signature');
          $command =  Artisan::call($signature, ['user' => '[email protected]']);
          return response($command);
}

Upvotes: 0

Views: 164

Answers (1)

Stefan
Stefan

Reputation: 1355

$user = User::all();

returns a Collection

The following illustrates how you iterate over all user emails:

$users = User::all();
foreach ($users as $user) {
    echo $user->email;
}

( In case you want to send an email to the currently authenticated user (?) from within a Controller, not a Command see here. )

Upvotes: 1

Related Questions