Last active
September 6, 2018 21:52
-
-
Save HDias/37c3a725251696f66d73ca2d3f058d99 to your computer and use it in GitHub Desktop.
Controller Action to Store Using POST and service Provider
This file contains hidden or 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 | |
/*In Provider*/ | |
... | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->app->bind('certificate.model.signature', Signature::class); | |
} | |
... | |
/*In Controller*/ | |
//... | |
public function store(Request $request) | |
{ | |
try { | |
\DB::beginTransaction(); | |
$signature = app('certificate.model.signature')->fill($request->all()); | |
$signature->signature_image_id = $request->all()['files'][0]; | |
$signature->save(); | |
\DB::commit(); | |
return redirect()->route('certificate.signature.index'); | |
} catch (\Exception $exception) { | |
\DB::rollBack(); | |
flash('danger', trans('flash.save_error'), $exception->getMessage()); | |
return \Redirect::route('certificate.signature.create') | |
->withErrors($request->validate()) | |
->withInput(); | |
} | |
} | |
//... | |
/*In route*/ | |
//... | |
$this->post('store', [ | |
'uses' => 'SignatureController@store', | |
'as' => 'certificate.signature.store' | |
]); | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment