Method 'POST' error 419 on local server Laravel - laravel

When i submit a post form on my page it doesn't work, it redirects me on the action route with error 419, this is an example of my form:
<form action="{{route('client.login')}}" method="POST">
#csrf
#method('POST')
<h4 class="login-title">Login</h4>
<div class="login-form">
<div class="row">
<div class="col-md-12 col-12 mb--20">
<label>Email*</label>
<input class="mb-0" type="email" name="email" value="{{ old('email') }}">
</div>
<div class="col-12 mb--20">
<label>Password</label>
<input class="mb-0" type="password" autocomplete="current-password" name="password"
value="{{ old('password') }}">
</div>
<div class="col-md-12">
<div class="d-flex align-items-center flex-wrap">
<button type="submit" class="btn btn-black me-3">Login</button>
<div class="d-inline-flex align-items-center">
<input type="checkbox" id="remember" name="remember" class="mb-0 me-1">
<label for="remember" class="mb-0 font-weight-400">Ricordami</label>
</div>
</div>
#if (Route::has('password.request'))
<p>Password dimenticata?</p>
#endif
</div>
</div>
</div>
</form>
I've checked the csrf tokens, and they match.
I've the exact same code on my server-side files and they work perfectly, but doesn't work on my local server.
I can't find anywhere the log of this error.
EDIT:
My issue was in the .env file, I’ve written a ; rather than a :

Remove #method('POST') this line and try because you don't need to mention method="POST", you already mentioned method in form tag.
Welcome you in advance.

Try to add <meta name="csrf-token" content="{{ csrf_token() }}"> in the head of app.blade.php file

Related

How to submit traditional blade form from livewire component?

I am trying to reuse laravel's default authentication components in livewire component. But when the login form is submitting I am getting a console error
wire-directives.js:86 Uncaught TypeError: Cannot read properties of
null (reading 'match')
The login form working perfectly fine when I am using the default login blade. But when I am reusing the login form in my livewire component, it is not working. Here is my code:
In my livewire component, I have this
<div>
<x-login-form/>
</div>
and the login form component is laravels default login form:
<form role="form" class="text-start" method="POST" action="{{ route('login') }}">
#csrf
<div class="input-group input-group-outline my-3">
<input type="email" id="email" class="form-control" name="email" :value="old('email')" required placeholder="email">
</div>
<div class="input-group input-group-outline mb-3">
<input type="password" class="form-control" id="password" type="password" name="password" required autocomplete="current-password" placeholder="password">
</div>
<div class="form-check form-switch d-flex align-items-center mb-3">
<input class="form-check-input" type="checkbox" id="remember_me" name="remember">
<label class="form-check-label mb-0 ms-2" for="rememberMe">Remember Me</label>
</div>
<div class="text-center">
<button type="submit" class="btn bg-gradient-primary w-100 my-4 mb-2">Sign In</button>
</div>
#if (Route::has('password.request'))
<p class="text-xs text-center">
Forgot your password?
</p>
#endif
</form>

Selection variable expressions fields are not working in Thymeleaf

I properly define everything in my back end file. When I try to use
the back end variables in Thymeleaf by using selection variable
expression it is not working. It show errors in every field:
cannot resolve field name
register.html
<!doctype html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:replace="/fragments/head"></head>
<body>
<nav th:replace="/fragments/nav :: nav-front"></nav>
<div class="container-fluid mt-5">
<div class="row">
<div th:replace="/fragments/categories"></div>
<div class="col"></div>
<div class="col-6">
<h3 class="display-4">Register</h3>
<form method="post" th:object="${user}" th:action="#{/register}" >
<div th:if="${#fields.hasErrors('*')}" class="alert alert-danger">
There are errors
</div>
<div class="form-group">
<label for>Username:</label>
<input type="text" class="form-control" th:field="*{username}" placeholder="Username">
<span class="error" th:if="${#fields.hasErrors('username')}" th:errors="*{username}"></span>
</div>
<div class="form-group">
<label for>Password:</label>
<input type="password" class="form-control" th:field="*{password}">
<span class="error" th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></span>
</div>
<div class="form-group">
<label for>Confirm Password:</label>
<input type="password" class="form-control" th:field="*{confirmPassword}">
<span class="error" th:if="${passwordMatchProblem}">Passwords do not match</span>
</div>
<div class="form-group">
<label for>E-mail:</label>
<input type="email" class="form-control" th:field="*{email}" placeholder="E-mail" required>
<span class="error" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></span>
</div>
<div class="form-group">
<label for>Phone number:</label>
<input type="text" class="form-control" th:field="*{phoneNumber}" placeholder="Phone number">
<span class="error" th:if="${#fields.hasErrors('phoneNumber')}" th:errors="*{phoneNumber}"></span>
</div>
<button class="btn btn-danger mb-5">Register</button>
</form>
</div>
<div class="col"></div>
</div>
</div>
<div th:replace="/fragments/footer"></div>
</body>
</html>
I get errors everywhere I use the selection expression field.
Are you adding "user" to your model in your controller?
You need to add it to your model so Thymeleaf can access it.
addAttribute method can be used like so: model.addAttribute("user", myUser);

419 Sorry, your session has expired. Please refresh and try again.This error appears when i submit the form

I got this error even when I give {{ csrf_field() }} during form submission.
What could be the issue?
<form action="{{ route('e-account-post') }}" method="POST" id="e-account" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="row">
<div class="form-group col-lg-6 col-md-6 col-xs-12">
<div class="field-label">Full Name <span class="required">*</span></div>
<input type="text" class="form-control" name="full_name" value="" placeholder="Full Name">
</div>
<div class="col-12 text-center">
<button class="btn credit-btn mt-30" type="submit">Send</button>
</div>
</form>
below is route
Route::post('/e-account','FrontController#e_account_action')->name('e-account-post');
below is controller
public function e_account_action(Request $request)
{
dd($request->all());
}
Laravel 5.7 and the project is live.
There is no problem in local. I setup the project in live mode through GitLab.

How Can i import Code ckeditor in my laravel app?

I am making a discussion forum application in Laravel . Here I want to use Ckeditor in comment sections. When somebody comments, then the code should show like here in stackoverflow.
#if(Auth::check()!=null)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel panel-body">
<form action="/comment" method="POST">
{{ csrf_field() }}
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="form-group">
<label for="comment">Reply</label>
<textarea name="body" class="form-control" style="size: 200px"></textarea>
</div>
<input type="submit" name="com" id="com" class="btn btn-xs btn-success pull-right">
</form>
</div>
</div>
</div>
#endif
Please give me very simple steps to use ckeditor. My master file is layout.app and this file is comment.blade.php. Please guide me where I should enter what files and scripts files.
You can use laravel CKEditor Package;
How to install:
Set up package
composer require unisharp/laravel-ckeditor
Add ServiceProvider
Edit config/app.php, add the following file to Application Service Providers section.
Unisharp\Ckeditor\ServiceProvider::class,
Publish the resources
php artisan vendor:publish --tag=ckeditor
Usage
Default way (initiate by name or id) :
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'article-ckeditor' );
</script>
Or if you want to initiate by jQuery selector :
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script src="/vendor/unisharp/laravel-ckeditor/adapters/jquery.js"></script>
<script>
$('textarea').ckeditor();
// $('.textarea').ckeditor(); // if class is prefered.
</script>
github link for more
Example:
#if(Auth::check()!=null)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel panel-body">
<form action="/comment" method="POST">
{{ csrf_field() }}
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="form-group">
<label for="comment">Reply</label>
<textarea id="editor1" name="body" class="form-control" style="size: 200px"></textarea>
</div>
<input type="submit" name="com" id="com" class="btn btn-xs btn-success pull-right">
</form>
</div>
</div>
</div>
#endif
<script>
$('.editor1').ckeditor(); // if class is prefered.
</script>
<script src="{{asset('vendor/unisharp/laravel-ckeditor/ckeditor.js')}}"></script>
<script src="{{asset('vendor/unisharp/laravel-ckeditor/adapters/jquery.js')}}"></script>
#section('script')
<script>
$('textarea').ckeditor();
</script>
#endsection
and i have provided editor id

How to make Validation in Laravel 5

I am using Laravel 5. And I am a beginner.
In my OrganisationsController I have a method
public function create()
{
return view('organisations.create');
}
In my routes.php I have
Route::model('organisations', 'Organisation');
Route::resource('organisations', 'OrganisationsController');
In my create.blade.php I have a code like this
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
#extends('app')
#section('content')
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Organisation</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong>
There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<!--<form class="form-horizontal" role="form" method="POST" action="{{ url('/organisations/store') }}"> -->
<form class="form-horizontal" role="form" method="POST" action="{{ url('/organisations/store') }}" accept-charset="UTF-8">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}">
<div class="form-group">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">E-Mail</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
I need to validate email and name field
I don't know where to write a validation. Please suggest a example for this. I am using laravel 5. I have searched so many sites. But I cannot get solution for this. Please tell me where to write validation code.
You should use FormRequest for this:
http://laravel.com/docs/5.0/validation#form-request-validation

Resources