Created
January 5, 2022 07:25
-
-
Save mbpating/c8068f39f27c7775dc3ce4fe81d0de0a to your computer and use it in GitHub Desktop.
Write a service class that handles saving and sending email then rewrite the store method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Requests\CustomerRequest; | |
use App\Services\CustomerService; | |
class CustomerController extends Controller | |
{ | |
public function store(CustomerRequest $request, CustomerService $service) { | |
$service->store($request->name,$request->email); | |
return [ | |
'saved' => true | |
]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services; | |
use DB; | |
use Mail; | |
use App\Mail\WelcomeNewCustomer; | |
class CustomerService { | |
public function store($name,$email) { | |
$data = array ( | |
'name' => $name, | |
'email' => $email | |
); | |
DB::table('customers')->insert($data); | |
Mail::to($email)->send(new WelcomeNewCustomer($data)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment