Mixed content issue in laravel - laravel

I have a following form:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/admin/email') }}">
On localhost, it generates https//.... but on server it generates http://... which results in mixed content warning. Is there any flag to fix it ?

<form class="form-horizontal" role="form" method="POST" action="{{ url('/admin/email') }}">
actualy url() accepts three params. string,Array,bool the third params is for secure, means https. you can set it to true.
i hope this helps

If you look at declaration of url method, it's like this
function url($path = null, $parameters = [], $secure = null)
so third parameter is for generating secure URL or not, so your line will be like this
<form class="form-horizontal" role="form" method="POST" action="{{ url('/admin/email', [], true) }}">

Related

Methods (PUT, UPDATE, DELETE) that are not supported in some routes in Laravel

I'm having some problems about some routes that don't support certain methods.
// The PUT method is not supported for this route. Supported methods: POST.
Route::post('/action_create_hunter', [HunterController::class, 'store'])->name('action_create_hunter.store');
<form action="{{ url("action_create_hunter") }}" method="POST">
#csrf
.....
// The UPDATE method is not supported for this route. Supported methods: POST.
Route::post('/action_update_hunter/{id}', [HunterController::class, 'update'])->name('action_update_hunter.update');
<form action="{{ url("action_update_hunter/$hunter->id") }}" method="POST">
#csrf
.....
// The GET method is not supported for this route. Supported methods: DELETE.
Route::delete('/delete_hunter/{id}', [UserController::class, 'destroy'])->name('action_delete_hunter.destroy');
<i class="fa fa-trash"></i> Delete
You should define a hidden input with the Method name in this case , and for Laravel you can use #method , for example , If you want this be Put Method
The Route Will be
Route::put('/action_update_hunter/{id}', [HunterController::class, 'update'])->name('action_update_hunter.update');
And The form :
<form action="{{ url("action_update_hunter/$hunter->id") }}" method="POST">
#csrf
#method('put')
....
</form>
it's called Form Method Spoofing , check it in laravel docs For more information
https://laravel.com/docs/9.x/routing#form-method-spoofing

Route not defined in form action in laravel 7

View Form
Form
Routes
Routes
Route list
Route list
Controller
Reg controller
ERROR
Route [] not defined.
if you use resource
{{ route('student.store') }}
if you use ->name("student")
{{ route('student') }}
you have to read carefully the laravel documentation for routes
The form action attribute specifies where to send the form-data when a form is submitted.
so you simply direct submitted data as follow :
<form method="POST" action="student/store">
provided that your route like :
Route::post("student/store", "RegStudentsController#store");
or if you want to use the route:
Route::post("/student", "RegStudentsController#store")->name("student");
<form method="POST" action="{{ route('student') }}">
Update
as per your updated screen shoots the solution will be doing something like:
<form method="POST" action="{{ url('/student') }}">

Laravel MethodNotAllowedHttpException No message

I'm getting this error after posting the data.
Route;
Route::post('/classified/location', 'ClassifiedController#locationPost')->name('location-post');
Form;
<form class="form" method="post" action="/classified/location">
#csrf
Please check your route file to make sure that you haven't defined the same route twice, in that case later will replace the prior so make sure route definition is unique and exactly once.
Also if you anyway are naming your routes then use the name itself to target it so use:
<form class="form" method="post" action="{{ route('location-post') }}">
Also, make sure you don't define two or more routes with the same name.
Your form tag like that:
<form class="form" method="post" action="{{route('location-post')}}">
OR
<form class="form" method="post" action="{{url('/classified/location')}}">

How to refer laravel csrf field inside a vue template

I have a vue template that contains a form:
<form id="logout-form" :action="href" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
In laravel, forms must have a csrf_field() defined. But within a vue component, the statement {{ csrf_field() }} means that I have a method named csrf_field in my vue instance and I am calling it.
How do I add csrf_field under this circumstance?
If you have the token in the meta tag of your header (view)
<meta name="csrf-token" content="{{ csrf_token() }}">
you could access the token using
data() {
return {
csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content')
}
}
And add a hidden input field within the form and bind the csrf property to the value like this:
<form id="logout-form" :action="href" method="POST" style="display: none;">
<input type="hidden" name="_token" :value="csrf">
</form>
If you're using axios with Vue2 for your ajax requests you can just add the following (usually in your bootstrap.js file):
window.axios.defaults.headers.common = {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
'X-Requested-With': 'XMLHttpRequest'
};
You can use this package: npm install vue-laravel-csrf
Usage: <form v-csrf-token>
This is how i use it:
{!! csrf_field() !!}
Put that in your form.
and in your vue script you can simply
methods: {
submitForm: function(e) {
var form = e.target || e.srcElement;
var action = form.action;
get the form and his action then the data value will be:
data: $(form).serialize()
This works perfectly for me and gives no errors at all.

How can I use parsley.js with Codeigniter form_open() function?

Actually I want to pass data-parsley-validate as a parameter to form_open() function.
Like <form action="http://recruit.com/controller/add_jobs" accept-charset="utf-8" data-parsley-validate>
Actually, you can init parsleyJS with jQuery:
<form id="form"></form>
<script>
$('#form').parsley();
</script>
So, you dont need to do <form data-parsley-validate></form>
At first load parsley.js in the head of html.
then apply parsley.js in the CI like this:
<form role="form" method="post" id="parsleyForm" data-parsley-validate
action="<?php echo site_url('.........') ?>">
go to this link for details of parsley.js.

Resources