missing argument on laravel update - laravel

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'));

Related

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>

Trying to delete a user. Getting method not allowed

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
});
});
});

why is my web routes going to api routes? laravel 5.4

so in my blade files i have these code to do CRUD,
<form method="POST" class="form-horizontal" action="{{ url('tickets/'.$ticket->id) }}"
enctype="multipart/form-data">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="PATCH" />
so i created my api routes. code below. (routes/api.php)
Route::group(['middleware' => ['api']], function () {
Route::resource('/v1/tickets','Api\TicketsController');
});
these are my routes. for web, it's in routes.php, because i got it from a package.
Route::resource($main_route_path, 'App\Http\Controllers\TicketsController', [
'names' => [
'index' => $main_route.'.index',
'store' => $main_route.'.store',
'create' => $main_route.'.create',
'update' => $main_route.'.update',
'show' => $main_route.'.show',
'destroy' => $main_route.'.destroy',
'edit' => $main_route.'.edit',
],
'parameters' => [
$field_name => 'ticket',
],
]);
now, the PROBLEM, is that every time i click the button using the form request, the whole operation goes to the api, any thoughts why is this happening?
All the routes in the api.php are grouped with the prefix, middleware and namespace by default. You don't have to add the api middleware again like you are.
For the web routes you can just use TicketsController since the namespace already points to the Controllers folder.
Can you run php artisan route:list and see what shows up?
Also you can do this to change the name prefix of all resource routes.
Route::resource($main_route_path, 'TicketsController', [
'names' => $main_route,
'parameters' => [
$field_name => 'ticket',
],
]);

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'));

Resources