Trying to delete a user. Getting method not allowed - laravel

I'm trying to delete a user, and I'm getting the error - method not allowed.
This is some of the form.
<form class="form-horizontal" role="form" action="/admin/access/users/delete/{{$user->id}}" method="POST">
{{ method_field('DELETE') }}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<div class="col-sm-10">
<input type="hidden" class="form-control" id="id_delete" disabled>
</div>
</div>
</form>
Route
Route::group(['namespace' => 'Backend', 'prefix' => 'admin'], function () {
Route::group(['prefix' => 'access', 'namespace' => 'Access'], function () {
Route::group(['namespace' => 'User'], function () {
Route::post('users/delete/{id}', 'UserBackendController#destroy');
});
});
});

Your form is using method DELETE but your route is defined for method POST.
Change your route to
Route::delete('users/delete/{id}', 'UserBackendController#destroy');
Then it'll be fixed.

Change Route Method from POST to DELETE
Route::group(['namespace' => 'Backend', 'prefix' => 'admin'], function () {
Route::group(['prefix' => 'access', 'namespace' => 'Access'], function () {
Route::group(['namespace' => 'User'], function () {
Route::delete('users/delete/{id}', 'UserBackendController#destroy');// --> change method from post to delete
});
});
});

Related

Undefined variable $daten a kind of ErrorException

this is my laravel project, the is a problem named undefined variable
it is funny I think the route is ok and Controller is also fine
route
Auth::routes();
Route::get('/', 'PagesController#home')->middleware('auth')->middleware('assign');
Route::get('/home', 'HomeController#index')->name('home')->middleware('auth');
Route::get('/groupchat', 'PagesController#getGroupchatPage')->name('groupchat')->middleware('auth');
Route::get('/groupsearch', 'PagesController#getGroupsearchPage')->name('groupsearch')->middleware('auth');
Route::get('/statistics', 'PagesController#getStatisticsPage')->name('statistics')->middleware('auth');
//Route::get('/author_views.statisticsA', 'PagesController#getStatisticsAdmin')->name('statisticsA')->middleware('auth');
// Routes for SQL Controller Querys
Route::get('/getQuestions/{id}', 'QuestionsController#getQuestions');
Route::get('/getChapterQuestions/{id}', 'QuestionsController#getChapterQuestions');
Route::get('/getAnswers/{id}', 'AnswersController#getAnswers');
Route::get('/getChapters/{id}', 'ChaptersController#getChapters');
Route::get('/countMembers/{id}', 'GroupsMembersController#countMembers');
Route::get('/getGroupMembers/{id}', 'GroupsMembersController#getGroupMembers');
Route::get('/getGroups/{id}', 'GroupsController#getGroups');
Route::get('/groupChapters/{id}', 'GroupsChaptersController#groupChapters');
Route::get('/getChaptersAndGroup/{id}', 'ChaptersController#getChaptersAndGroup');
Route::get('/getGroupsChaptersMembersKombined/{id}', 'ChaptersController#getGroupsChaptersMembersKombined');
// 28.06.2021
Route::get('/statistics', 'StatisticsController#statistic');
Route::get('/statisticsA', 'StatisticsController#statisticA');
Route::get('/admin', [
'uses' => 'PagesController#getAdminPage',
'as' => 'admin',
'middleware' => 'roles',
'roles' => ['Admin'],
])->middleware('auth');
Route::post('/admin_assign', [
'uses' => 'PagesController#postAdminAssignRoles',
'as' => 'admin_assign',
'middleware' => 'roles',
'roles' => ['Admin'],
])->middleware('auth');
Route::get('/statisticsA', [
'uses' => 'PagesController#getStatisticsAdmin',
'as' => 'statisticsA',
'middleware' => 'roles',
'roles' => ['Author','Admin']
])->middleware('auth');
Route::get('/eventA', [
'uses' => 'PagesController#getEventAdmin',
'as' => 'eventA',
'middleware' => 'roles',
'roles' => ['Author','Admin'],
])->middleware('auth');
and my blade
#extends('layouts.appAuthor')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('DozentAnsicht') }}</div>
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<table id="statisticforteacher" class="table-responsive">
<thead>
<th>Id</th>
<th>FrageBezeichnung</th>
<th>Kapitel</th>
<th>richtige Antwort</th>
<th>falsche Antwort</th>
<th>Richtige Rate</th>
</thead>
<tbody>
#foreach($daten as $value)
<tr>
<td>{{$value -> Id}}</td>
<td>{{$value -> FrageBezeichnung}}</td>
<td>{{$value -> Kapitel}}</td>
<td>{{$value -> richtigeAntwort}}</td>
<td>{{$value -> falscheAntwort}}</td>
<td>{{$value -> richtigeRate}}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
I want to show the table in the view, but it didn't work in statisticA but it works in statistic
I don't know what happen
my controller
<?php
namespace App\Http\Controllers;
use DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class StatisticsController extends Controller
{
//
public function statistic(){
$data =DB::table('statisticforteacher') -> get();
return view('/statistics',compact('data'));
}
public function statisticA(){
$daten =DB::table('statisticforteacher') -> get();
return view('/statisticsA',compact('daten'));
}
}
has anyone a idea?
You have in route file two different routes with same url but different controllers. As in order when Laravel read the file, get the last matched route, for that reason you have the issue. So, fix your routes statements and must work
Route::get('/statisticsA', 'StatisticsController#statisticA');
Route::get('/statisticsA', [
'uses' => 'PagesController#getStatisticsAdmin',
'as' => 'statisticsA',
'middleware' => 'roles',
'roles' => ['Author','Admin']
])->middleware('auth');

Unable to get input data from Form submit GET request in laravel 5.1 [duplicate]

This question already has answers here:
Can't retrieve url GET parameters with Laravel 5.1on remote server
(2 answers)
Closed 2 years ago.
I have a search form that is sending a GET request to the method that it is using to view the form:
<form class="form-horizontal" method="GET" action="{{ route('LoggedIn.StudentModule.StudentHomeWork.index') }}">
<div class="form-group form-group-sm">
<div class="col-sm-3">
<input type="text" name="inputdate" class="form-control datepicker" placeholder="Date" >
</div>
<div class="col-sm-2">
<button class="btn btn-primary btn-sm btn-block" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
Search
</button>
</div>
</div>
</form>
And the route:
Route::group(array(
'middleware' => 'auth',
'prefix' => '!',
'namespace' => 'LoggedIn',
'as' => 'LoggedIn.',
), function() {
.................
Route::group(array(
'prefix' => 'StudentModule',
'namespace' => 'StudentModule',
'as' => 'StudentModule.'
), function () {
............
Route::group(array(
'prefix' => 'StudentHomeWork',
'as' => 'StudentHomeWork.',
), function () {
Route::get('/', array(
'as' => 'index',
'uses' => 'StudentHomeWorkController#index'
));
});
..................
});
...............
});
And my controller:
public function index()
{
$searchParam = request('inputdate') ? request('inputdate') : date('Y-m-d');
echo $searchParam; // this is showing no data
}
The problem is, i couldn't get the data from submitted form. I have used every option that i found in stackoverflow but couldn't get the data. Can anyone point me out what i am missing! My laravel version is 5.1
Note: I am using this method in Laravel 5.8 + 6. Which is working just fine
Try This
How To Pass GET Parameters To Laravel From With GET Method ?
Route::get('any', ['as' => 'index', 'uses' => 'StudentHomeWorkController#index']);
Then Controller
public function index(){
$searchParam = Input::get('category', 'default category');
}
Form:
{{ Form::open(['route' => 'any', 'method' => 'GET'])}}
<input type="text" name="inputdate"/>
{{ Form::submit('submit') }}
{{ Form::close() }}
There Also various method...
Change it as your need.. You can also pass it in url like:
Route::get('any/{data}','StudentHomeWorkController#index')->name('something);
Controller:
public function index($data){
print_r($data);
}
Hope it will help

Calling same route on submit

I dont know why I am facing this issue.
I have a table where I called new route to open a update view that is
Route::get('update_view/{id}', ['as' => 'update_view', 'uses' => 'admin\study_material\StudyMaterialController#update_view']);
And after submit the form below route is called
Route::post('update/{id}', ['as' => 'update', 'uses' => 'admin\study_material\StudyMaterialController#update']);
Now, issue is when update page is called it is showing update page correctly,but when form is submitted i get error use of post method is not allowed.Use Get or Put.But I check url it is showing me update_view/3 instead of update/3.
Route::group(['prefix' => 'StudyMaterial', 'as' => 'StudyMaterial.'], function () {
Route::get('view', ['as' => 'view', 'uses' => 'admin\study_material\StudyMaterialController#view']);
Route::get('add', ['as' => 'add', 'uses' => 'admin\study_material\StudyMaterialController#add_view']);
Route::post('add_studyMaterial', ['as' => 'add_studyMaterial', 'uses' => 'admin\study_material\StudyMaterialController#add']);
Route::get('update_view/{id}', ['as' => 'update_view', 'uses' => 'admin\study_material\StudyMaterialController#update_view']);
Route::post('update/{id}', ['as' => 'update', 'uses' => 'admin\study_material\StudyMaterialController#update']);
});
My Form :
<form action="{{ route('StudyMaterial.update',$data[0]->id) }}" method="POST" class="text-center" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" name="_token" id="_token" value="{{ csrf_token() }}">
<button type="submit>Update</button>
</form>
Generated Url :
To View Form to update fileds =>
localhost/project/public/StudyMaterial/update_view/13
To redirect Url to submit form to controller =>
localhost/project/public/StudyMaterial/update/13
after submitting form URL 2 should generate.But here it is showing only Url 1 which is GET method.
This is happening in my whole project.
Thank You in advance
Try this:
<form action="{{ route('StudyMaterial.update',$data[0]->id) }}" method="POST" class="text-center" enctype="multipart/form-data">
#csrf
<button type="submit>Update</button>
</form>

Laravel route not showing as HTTPS in form?

I created a form:
{{ Form::open(array('route' => 'cart.add')) }}
I have this in my routes.php file:
Route::post( 'cart/add', array('https' => true, 'uses' => 'CartController#addToCart', 'as' => 'cart.add'));
Yet, the resulting HTML is:
<form method="POST" action="http://localhost/cart/add" accept-charset="UTF-8">
I was expecting:
<form method="POST" action="https://localhost/cart/add" accept-charset="UTF-8">
because the route is defined as needing HTTPS.
What am I missing?
My problem was that this:
Route::post( 'cart/add', array('https' => true, 'uses' => 'CartController#addToCart', 'as' => 'cart.add'));
Had to be this:
Route::post( 'cart/add', array('https', 'uses' => 'CartController#addToCart', 'as' => 'cart.add'));

missing argument on laravel update

I am working with laravel 4. I have created an edit form like below:
{{ Form::model($v, array('route' => array('insur_docs.update', $v->id),'method' => 'PUT','class'=>'form-horizontal')) }}
and update route
Route::put('insur_docs/update', array('as' => 'insur_docs.update', 'uses' => 'Insur_DocController#update'));
The problem it shows is:
Missing argument 1 for Insur_DocController::update()
The problem is in your route, you need to add /{id} to it. Here's a test I did:
class Insur extends Eloquent {
}
Route::put('insur_docs/update/{id}', array('as' => 'insur_docs.update', 'uses' => 'Insur_DocController#update'));
Route::get('test', function() {
$v = new Insur;
$v->id = 1;
return Form::model($v, array('route' => array('insur_docs.update', $v->id),'method' => 'PUT','class'=>'form-horizontal'));
});
And the generated form open was:
<form method="POST" action="http://localhost/insur_docs/update/1" accept-charset="UTF-8" class="form-horizontal"><input name="_method" type="hidden" value="PUT">
<input name="_token" type="hidden" value="V0TP6LbCjO1kGF6LCLObEi6hofbW5ZgNo5Kz7nQ3">
Route::put('insur_docs/update/{id}', array('as' => 'insur_docs.update', 'uses' => 'Insur_DocController#update'));

Resources