Reputation: 188
Hi i found some bug in my laravel app and wondering how to fix it :/
My controlers code
public function patvirtinimas($id,$bookid)
{
return \View::make('grazintiknyga.patvirtinti',compact('id','bookid'));
}
public function grazintiknygasave($id,$bookid,Request $request)
{
if(Input::get('taip'))
{
$grazinimas = Carbon::now();
$grazinimas->format("Y-m-d");
$kasprieme = Auth::user()->id;
$resetas = NULL;
//dd($kasprieme);
DB::beginTransaction();
try {
DB::table('borrows')
->where('id', $id)
->update(['grazinimo_data' => $grazinimas,
'prieme' => $kasprieme
]);
DB::table('books')
->where('id', $bookid)
->update(['isdavimo_data' => $resetas,
'terminas' => $resetas,
'grazinimo_data' => $resetas
]);
DB::commit();
// jeigu viskas gerai
} catch (\Exception $e) {
DB::rollback();
dd($e);
// jeigu kazkas negerai
}
return \Redirect::to(url('grazinti-knyga'))->with('grazinta','Knyga grąžinta sėkmingai!');
}
elseif(Input::get('ne'))
{
return \Redirect::to(url('grazinti-knyga'))->with('negrazinta','Knygos grąžinimas atšauktas!');
}
}
One function for viewing other for updating tables in db
routes
Route::get('patvirtinti-grazinima-{id}-{bookid}', 'BorrowController@patvirtinimas');
Route::post('grazinimas-save-{id}-{bookid}', 'BorrowController@grazintiknygasave');
The problem is when i edit route directly in my browser grazinimas-save-{someid}-{somebookid}
When one of parameters matches other dont then half of db transaction works and other doesn't update and destroys my db :? can some one help fix this bugs ? that both parameters must match in db to update. Maybe there is some parameters hidding and validation?
Upvotes: 1
Views: 296
Reputation: 2951
Slashes /
are the expected way to separate arguments in your routes.
Your parameters are not getting passed on properly to your Controller.
Changes the routes to the following (if you can)
Route::get('patvirtinti-grazinima/{id}/{bookid}', 'BorrowController@patvirtinimas');
Route::post('grazinimas-save/{id}/{bookid}', 'BorrowController@grazintiknygasave');
Another option is to handle the logic in your Controller or a Middleware (https://laracasts.com/discuss/channels/laravel/using-dash-instead-of-slash-in-routes)
Upvotes: 1