hoping that someone can help out.
I have all other methods (edit and new) working well with protected routes at this stage. It's just delete that is not playing nice. (although I'm sure it's something silly that I am doing). I have removed the auth by taking the delete out of the route group with the middleware assigned to it and it successfully deletes the config (object) so the action is working correctly. I try to check it in firebug as suggested in another post and I get:
405 Method Not Allowed
Allow DELETE
Cache-Control no-cache, private
Connection close
Content-Type text/html
Date Wed, 11 Nov 2015 12:36:40 GMT
Host 127.0.0.1:8000
X-Powered-By PHP/5.5.9-1ubuntu4.14
I would like to have the user authenticate before creating a new entry or editing an existing one (and likewise for delete).
When I try a delete by pressing the button, and it directs me to auth/login (out of the box quickstart auth for laravel) as it should, but then upon successful login, the url in the address bar is:
127.0.0.1:8000/delete/48
showing:
MethodNotAllowedHttpException in RouteCollection.php line 219:
routes.php:
Route::get('/new', [
'as' => 'create',
'middleware' => 'auth',
'uses' => 'ConfigsController@getCreate'
]);
$router->group(['middleware' => 'auth'], function($router)
{
Route::get('{id}/edit', 'ConfigsController@edit');
Route::delete('/delete/{id}/', 'ConfigsController@getDL');
});
+--------+----------+-------------------+----------+-------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------+----------+-------------------------------------------------------+------------+
| | DELETE | delete/{id} | | App\Http\Controllers\ConfigsController@getDL | auth |
| | POST | new | | App\Http\Controllers\ConfigsController@postCreate | |
| | GET|HEAD | new | create | App\Http\Controllers\ConfigsController@getCreate | auth |
| | GET|HEAD | {id}/edit | | App\Http\Controllers\ConfigsController@edit | auth |
ConfigsController.php:
public function getCreate() {
return view('create');
}
public function edit($id)
{
$configs = Config::find($id);
return view('edit')
->with('configs', $configs);
}
public function getDL($id) {
$configs = Config::find($id)->delete();
return Redirect::to('/');
}
index.blade.php (edit & delete) & app.blade.php (new):
<ul class="nav navbar-nav">
<li><a href="{{ URL::route('create') }}">New</a></li>
</ul>
{!! Form::open(array('url' => '/delete/' . $config->id . '/', 'class' => 'pull-right')) !!}
{!! Form::hidden('_method', 'DELETE') !!}
{!! Form::submit('Delete this Config', array('class' => 'btn btn-warning')) !!}
{!! Form::close() !!}
<a class="btn btn-small btn-info" href="{{ URL::to('/' . $config->id . '/edit') }}">Edit this Config</a>