Skip to content

Commit

Permalink
updating for store edit store implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopekodi committed Jul 8, 2020
1 parent 64cbd6f commit 5401422
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
42 changes: 41 additions & 1 deletion app/Http/Controllers/StoreController.php
Expand Up @@ -198,7 +198,47 @@ public function show($id)
*/
public function edit($id)
{
return view('backend.stores.edit');
$url = env('API_URL', 'https://dev.api.customerpay.me') . '/store/' . $id;

try {
$client = new Client;
$payload = [
'headers' => [
'x-access-token' => Cookie::get('api_token')
],
'form_params' => [
'current_user' => Cookie::get('user_id'),
]
];
$response = $client->request("GET", $url, $payload);
$statusCode = $response->getStatusCode();
$body = $response->getBody();
$StoreData = json_decode($body)->data->store;
if ($statusCode == 200) {

return view('backend.stores.edit')->with('response', $StoreData);
}
} catch (RequestException $e) {

Log::info('Catch error: LoginController - ' . $e->getMessage());

// check for 5xx server error
if ($e->getResponse()->getStatusCode() >= 500) {
return view('errors.500');
}
// get response to catch 4xx errors
$response = json_decode($e->getResponse()->getBody());
Session::flash('alert-class', 'alert-danger');
// dd($response);
Session::flash('message', $response->message);
return redirect()->route('store.index', ['response' => []]);

} catch (\Exception $e) {
//log error;
Log::error('Catch error: StoreController - ' . $e->getMessage());
return redirect()->route('store.index', ['response' => []]);

}
}

/**
Expand Down
10 changes: 6 additions & 4 deletions resources/views/backend/stores/edit.blade.php
Expand Up @@ -35,11 +35,13 @@
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<form action="{{ route('store.update') }}" method="POST">
<form action="{{ route('store.update', $response->_id) }}" method="POST">
@csrf
@method('PUT')
<div class="form-row">
<div class="form-group col-md-6">
<label for="store name">Store Name</label>
<input type="text" name="store_name" class="form-control" placeholder="XYZ Stores">
<input type="text" name="store_name" class="form-control" value="{{ $response->store_name }}" placeholder="XYZ Stores">
</div>
<div class="form-group col-md-6">
<label for="inputTagline">Tagline</label>
Expand All @@ -58,7 +60,7 @@
</div>
<div class="form-group">
<label for="inputAddress">Address</label>
<input type="text" name="address" class="form-control" placeholder="123 Abby Avenue">
<input type="text" name="address" class="form-control" value="{{ $response->shop_address }}" placeholder="123 Abby Avenue">
</div>
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
Update Changes
Expand Down Expand Up @@ -88,7 +90,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success"><a href="{{ route('store.update', $store->_id) }}" class="text-white">Save changes</a></button>
<button type="submit" class="btn btn-success"><a href="{{ route('store.update', $response->_id) }}" class="text-white">Save changes</a></button>
</div>
</div>
</div>
Expand Down

0 comments on commit 5401422

Please sign in to comment.