Files
kaunter/app/Http/Controllers/CustomersController.php
T
2020-10-22 09:21:18 +08:00

135 lines
3.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use Config;
use App\Customer;
use App\Media;
use Illuminate\Http\Request;
use App\Services\CustomerService;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Auth;
class CustomersController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->customerService = New CustomerService();
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$search = false;
$auth_user = Auth::user();
$cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
return view('customers.index',compact('search','cawangan_info'));
}
public function info(){
$auth_user = Auth::user();
$cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
return view('customers.info',compact('cawangan_info'));
}
public function search(Request $request){
$noic = $request->noic;
$auth_user = Auth::user();
$cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
$customer_info = Http::get(config('api.url') . '/api/customers/'. $noic)->json();
// dd($customer_info);
$search = true;
if($customer_info){
Session::put('customer_info',$customer_info);
return redirect()->route('customer_info')->with( ['customer_info' => $customer_info,'cawangan_info'=>$cawangan_info] );
}else{
return view('customers.index',compact('customer_info','search','noic','cawangan_info'));
}
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
// dd($request);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$customer = $this->customerService->createNewCustomer($request);
$customer_info = Customer::where('noic','=',$request['noic'])->first();
// dd($customer_info);
Session::put('customer_info',$customer_info);
return redirect()->route('customer_info')->with( ['customer_info' => $customer_info] );
}
/**
* Display the specified resource.
*
* @param \App\Customer $customer
* @return \Illuminate\Http\Response
*/
public function show(Customer $customer)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Customer $customer
* @return \Illuminate\Http\Response
*/
public function edit(Customer $customer)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Customer $customer
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Customer $customer)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Customer $customer
* @return \Illuminate\Http\Response
*/
public function destroy(Customer $customer)
{
//
}
public function test(){
$response = Http::get('http://localhost:8000/api/customers');
dd($response->json());
}
}