Laravel route not showing as HTTPS in form? - laravel-4

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

Related

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>

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

Route not defined in laravel

I'm getting this error
ErrorException in UrlGenerator.php line 304: Route [customer.signup] not defined. (View: C:\xampp\htdocs\ecomm\app\Modules\Templates\Resources\Views\layouts\public.blade.php) (View: C:\xampp\htdocs\ecomm\app\Modules\Templates\Resources\Views\layouts\public.blade.php)
but as far as I know my routes is all correct.
My public.blade.php
<li class="dropdown">
<i class="fa fa-user" aria-hidden="true"></i> User Management <span class="caret"></span>
<ul class="dropdown-menu">
<li>Sign up</li>
<li>Login</li>
<li role="separator" class="divider"></li>
<li>Logout</li>
</ul>
</li>
my routes
Route::get('/shipping-info', [
'uses' => 'OpenController#shippingInfo',
'as' => 'cart.shippingInfo'
]);
Route::get('/signup', [
'uses' => 'OpenController#signup',
'as' => 'customer.signup'
]);
Route::delete('/product/deleting/{id}', [
'uses' => 'OpenController#deleting',
'as' => 'deleting'
]);
Route::get('/login', [
'uses' => 'OpenController#login',
'as' => 'client.login'
]);
Route::get('/shopping-cart', [
'uses' => 'OpenController#shoppingCart',
'as' => 'cart.shop'
]);
Route::get('/product/update-item/{id}', [
'uses' => 'OpenController#updateProduct',
'as' => 'cart.update'
]);
Route::get('/', [
'uses' => 'OpenController#index',
'as' => 'index',
]);
Route::get('/{id}', 'OpenController#content');
Route::get('gallery/{title}', 'OpenController#galleryCategory');
Route::get('/product/{id}', [
'uses' => 'OpenController#product',
'as' => 'shop.product'
]);
Route::post('/product/update-cart/{id}', [
'uses' => 'OpenController#updateCart',
'as' => 'cart.updateCart'
]);
Route::put('/product/update-qty/{id}', [
'uses' => 'OpenController#newQty',
'as' => 'new.qty'
]);
My signup method in OpenController
public function signup()
{
echo "OpenController Signup";
}
You have to clear your route cache, if you've already run route:cache before:
php artisan route:clear

Call a controller Action when using route group

I want to call an action of a controller in laravel blade, when using router group...
route
$router->group([
'namespace' => 'Admin',
'middleware' => 'auth',
], function () {
resource('admin/adsense', 'AdsenseController');
resource('admin/post', 'PostController');
});
So, I want call an action of adsenseController in the blade template
{!! Form::model($var, ['method' => 'PATCH','route' => ['what should i write to call an action ']]) !!}
Example (without router groupe)
route
Route::resource('subject','SubjectController');
blade template
{!! Form::model($var, ['method' => 'PATCH','route' => ['subject.actionName']]) !!}
thanks
If you want to use action, try to use this:
'action' => 'SubjectController#index'
Instead of this:
'route' => ['someroute']
https://laravelcollective.com/docs/5.0/html#opening-a-form
So , i want call an action of adsenseController in the blade template
Why don't you simply point your form's action directly to the controller? Eg
{!! Form::model($var, ['method' => 'PATCH', 'action' => 'Controller#method']) !!}
If you want to redirect to a custom route, it's this simple
{!! Form::model($var, ['method' => 'PATCH', 'route' => 'route.name']) !!}
Check out the documentation on Laravel.com

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