Last active
January 5, 2022 06:22
-
-
Save cdmathukiya/6fb392fe60c7a7039107d69307c77e28 to your computer and use it in GitHub Desktop.
Controller and service
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\Controllers\Controller; | |
use App\Services\CustomerService; | |
use Illuminate\Http\Request; | |
class CustomerController extends Controller | |
{ | |
public function __construct(CustomerService $customerService) | |
{ | |
$this->customerService = $customerService; | |
} | |
public function store(Request $request) | |
{ | |
$data = $request->validate([ | |
'name' => 'required', | |
'email' => 'required', | |
]); | |
$data = $this->customerService->storeCustomer($data); | |
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 App\Mail\WelcomeNewCustomer; | |
use DB; | |
use Mail; | |
/** | |
* Class CustomerService | |
* | |
*/ | |
class CustomerService | |
{ | |
/** | |
* CustomerService constructor. | |
* | |
*/ | |
public function __construct() | |
{ | |
} | |
public function storeCustomer($inputs) | |
{ | |
DB::table('customers')->insert($inputs); | |
Mail::to($inputs['email'])->send(new WelcomeNewCustomer($inputs)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment