Try: method=method="POST" with capitals.
Mar 14, 2019
10
Level 5
Status Code: 405 Method Not Allowed message: "The PUT method is not supported for this route. Supported methods: GET, HEAD, POST."
Hi what am I doing wrong?
Status Code: 405 Method Not Allowed
message: "The PUT method is not supported for this route. Supported methods: GET, HEAD, POST."
Outputs:
<!--EDIT MODULE-->
<div class="row justify-content-center hide-this edit-module-form" id="update_module_{{ $module->id }}">
<div class="col-md-11 alert alert-secondary mt-3 mb-3 ">
<form class="mt-2 edit_module_form" method="post" action="/modules/{{ $module->id }}">
@csrf @method('PUT')
<div class="form-group">
Title
<input value="{{ $module->title }}" type="text" class="form-control mb-1 required" id="title" name="title" placeholder="Module Title" required> Release after how many days?
<div class="col-4">
<input type="number" class="form-control required" id="release_after" name="release_after" value="{{ $module->release_after }}">
</div>
<input type="hidden" class="form-control" name="course_id" value="{{ $module->id }}">
</div>
<div class="form-group">
<label for="module_description">Description</label>
<textarea class="form-control" id="module_description" name="description" rows="3">{{ $module->description }}</textarea>
</div>
<button type="submit" class="btn btn-success btn-sml">
<i class="fas fa-pencil-alt"></i> Update {{ $module->title }}
</button>
<button type="button" class="btn btn-warning btn-sml hide-edit-module-form">Cancel</button>
</form>
</div>
</div>
<!--END EDIT MODULE-->
| | POST | modules | modules.store | App\Http\Controllers\ModuleController@store | web |
| | GET|HEAD | modules | modules.index | App\Http\Controllers\ModuleController@index | web |
| | GET|HEAD | modules/create | modules.create | App\Http\Controllers\ModuleController@create | web |
| | GET|HEAD | modules/{module} | modules.show | App\Http\Controllers\ModuleController@show | web |
| | PUT|PATCH | modules/{module} | modules.update | App\Http\Controllers\ModuleController@update | web |
| | DELETE | modules/{module} | modules.destroy | App\Http\Controllers\ModuleController@destroy | web |
| | GET|HEAD | modules/{module}/edit | modules.edit | App\Http\Controllers\ModuleController@edit | web |
//START Edit module
$( ".edit_module_form" ).on( "submit", function( event )
{
event.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var str = $( this ).serialize();
$.ajax({
method: "POST",
url: "{{ url('/modules') }}",
data: str
})
.done(function( msg ) {
$( '.edit-module-form' ).hide();
alert('Module Edited successfully!');
location.reload();
});
});
//End Edit module
Level 5
@TALINON - Can't add the module id like you say!
url: "{{ url('/modules/', [$module-id]) }}",
ErrorException (E_ERROR)
Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP)
I am pretty sure the best way is to access it in the result of the serlizlized as I mentioned above.
*Edit
I ended up doing this and I don't like it it's super messy. Will have to implement gates etc.
Route::put('modules', 'ModuleController@update');
public function update(Request $request, Module $module)
{
$module = \App\Module::where('id', $request->module_id)->first();
if($module->user_id== \Auth::id())
{
$validated = $request->validate(['title' => 'required|max:255','release_after'=>'numeric']);
\DB::table('modules')
->where('id', $module->id)
->update(['title' => $request->title,
'description' => $request->description,
'release_after' => $request->release_after
]);
}
else
{
echo "Not allowed";
}
}
//START Edit module
$( ".edit_module_form" ).on( "submit", function( event )
{
event.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var str = $( this ).serialize();
$.ajax({
method: "POST",
url: "{{ url('/modules/') }}",
data: str
})
.done(function( msg ) {
$( '.edit-module-form' ).hide();
alert('Module Edited successfully!');
location.reload();
});
});
//End Edit module
Please or to participate in this conversation.