Skip to content

Instantly share code, notes, and snippets.

@cdmathukiya
Last active January 5, 2022 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdmathukiya/6fb392fe60c7a7039107d69307c77e28 to your computer and use it in GitHub Desktop.
Save cdmathukiya/6fb392fe60c7a7039107d69307c77e28 to your computer and use it in GitHub Desktop.
Controller and service
<?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,
];
}
}
<?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