firstcommit
This commit is contained in:
0
Modules/Customer/app/Repositories/.gitkeep
Normal file
0
Modules/Customer/app/Repositories/.gitkeep
Normal file
15
Modules/Customer/app/Repositories/CustomerInterface.php
Normal file
15
Modules/Customer/app/Repositories/CustomerInterface.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Customer\Repositories;
|
||||
|
||||
interface CustomerInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getCustomerById($CustomerId);
|
||||
public function getCustomerByEmail($email);
|
||||
public function delete($CustomerId);
|
||||
public function create($CustomerDetails);
|
||||
public function update($CustomerId, array $newDetails);
|
||||
public function pluck();
|
||||
|
||||
}
|
51
Modules/Customer/app/Repositories/CustomerRepository.php
Normal file
51
Modules/Customer/app/Repositories/CustomerRepository.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Customer\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Customer\Models\Customer;
|
||||
|
||||
class CustomerRepository implements CustomerInterface
|
||||
{
|
||||
public function findAll()
|
||||
{
|
||||
return Customer::when(true, function ($query) {
|
||||
// if (auth()->user()->hasRole('Customer')) {
|
||||
// $user = \Auth::user();
|
||||
// $query->where('id', $user->Customer_id);
|
||||
// }
|
||||
})->paginate(20);
|
||||
}
|
||||
|
||||
public function getCustomerById($CustomerId)
|
||||
{
|
||||
return Customer::findOrFail($CustomerId);
|
||||
}
|
||||
|
||||
public function getCustomerByEmail($email)
|
||||
{
|
||||
return Customer::where('email', $email)->first();
|
||||
}
|
||||
|
||||
public function delete($CustomerId)
|
||||
{
|
||||
Customer::destroy($CustomerId);
|
||||
}
|
||||
|
||||
public function create($CustomerDetails)
|
||||
{
|
||||
return Customer::create($CustomerDetails);
|
||||
}
|
||||
|
||||
public function update($CustomerId, array $newDetails)
|
||||
{
|
||||
return Customer::whereId($CustomerId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function pluck()
|
||||
{
|
||||
return Customer::pluck(DB::raw("IFNULL(CONCAT(first_name, ' ', last_name), first_name) AS customer_name"), 'id');
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user