authentication - Unable to get to route behind auth middleware for two routes -
my 2 routes 'admin.media.begin-destroy' , 'admin.media.destroy' fails when middleware => 'auth'.
when trying access route 'admin.media.begin-destroy' presented login page authentication controller, , cannot away without trying access page.
on development machine works fine both , without auth middleware
here routes protected:
route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() { route::get('/', ['as' => 'admin.dashboard', 'uses' => 'admin\dashboardcontroller@index']); route::get('show/{show}/toggle',['as' => 'admin.show.toggle','uses'=>'admin\showcontroller@toggle']); route::resource('show', 'admin\showcontroller'); // admin.media.begin-destroy , admin.media.destroy fails when middleware => 'auth' route::get('media/begin-destroy-ddd/{id}', ['as' => 'admin.media.begin-destroy', 'uses' => 'admin\mediacontroller@begindestroy']); route::resource('media', 'admin\mediacontroller', ['only' => ['index', 'create', 'store', 'destroy']]); route::get('order', ['as'=> 'admin.order.index', 'uses' => 'admin\ordercontroller@index']); route::get('order/list-for-modification', ['as' => 'admin.order.list-for-modification', 'uses' => 'admin\ordercontroller@listmodify']); route::get('order/{order}/begin-destroy', ['as' => 'admin.order.begin-destroy', 'uses' => 'admin\ordercontroller@begindestroy']); route::delete('order/{order}/destroy', ['as' => 'admin.order.destroy', 'uses' => 'admin\ordercontroller@destroy']); }); the controller method 'admin.media.begin-destroy' , 'admin.media.destroy' super simple:
public function begindestroy($filename) { return view('admin.media.begin-destroy', compact('filename')); } /** * remove specified resource storage. * * @param int $filename * @return response */ public function destroy($filename) { storage::disk('free-media')->delete($filename); return redirect()->route('admin.media.index'); } i puzzled why doesn't work.
edit!--- trying work me around problem i
/ moved problematic routes own group no middleware
route::group(['prefix' => 'admin'], function() { route::get('media/begin-destroy/{id}', ['as' => 'admin.media.begin-destroy', 'uses' => 'admin\mediacontroller@begindestroy']); route::resource('media', 'admin\mediacontroller', ['only' => ['index', 'create', 'store', 'destroy']]); }); / added middleware registration in admin\mediacontroller constructor, cannot add begindestroy, because fail unknown reason public function __construct() { $this->middleware('auth', ['except' => ['begindestroy']]); }
// in begindestroy, check user, , user not logged in wtf
public function begindestroy($filename) { if (auth::check()) { return view('admin.media.begin-destroy', compact('filename')); } // end here. return "un-authorized"; } for particular use case, ok me disable check in begindestroy, because in actual destroy code, auth works again, happening ?
changing route have filename passed using old question mark made difference!
this more of workaround answer, , still have no idea why doesn't work other way, anyway, here workaround did trick.
// works route::get('media/begin-destroy', ['as' => 'admin.media.begin-destroy', 'uses' => 'admin\mediacontroller@begindestroy']); // not work! // reason beyond me, 'auth' middleware fails here // , auth::check() fails // (yes ofcourse updated signature accordingly in begindestroy) route::get('media/begin-destroy/{filename}', ['as' => 'admin.media.begin-destroy', 'uses' => 'admin\mediacontroller@begindestroy']);
Comments
Post a Comment