Laravel captcha_img() in blade not found 404 - laravel

Today I install package Laravel Captcha (https://github.com/mewebstudio/captcha)
But in Blade not working {!! captcha_img() !!}.
Register Blade
<div class="form-group mb-2">
<div class="captcha">
{!! captcha_img() !!}
<button type="button" class="btn btn-danger" class="reload" id="reload">
↻
</button>
</div>
</div>
<div class="form-group mb-2">
<div class="captcha">
<input id="captcha" type="text" class="form-control" placeholder="Enter Captcha" name="captcha">
</div>
</div>
Browser show html
Error in Console
GET http://simfind.loc/captcha/default?Ff3XLM4u 404 (Not Found)
I don’t understand why the capcher doesn’t show. Any help. (Laravel 8).

This package not optimized for Laravel version 8, I remove this package and install https://github.com/anhskohbo/no-captcha google no-captcha. Its fine work! Thanks all.

Related

Livewire - File Uploads - Temporary Preview URL's Error - Serialization of 'Livewire\TemporaryUploadedFile' is not allowed

I am creating multiple steps form with livewire. In the third step, I am uploading the image via livewire and also previewing the image on the image selected.
After previewing the image, when I move to the first or second step it returns the error - [Serialization of 'Livewire\TemporaryUploadedFile' is not allowed]
Please help me, with how I can solve this issue.
<div class="form-row pl-2 pr-2 reward-engagement mt-3">
<div class="col-md-9 mb-3">
<label for="validationDefault01"><small>UPLOAD IMAGE</small></label>
<div class="input-group input-group-merge">
<input type="file" class="form-control form-control-sm " id="amount5" wire:model="photo" />
</div>
</div>
<div class="col-md-3 mt-4 mb-2 pt-1">
<button type="button" class="btn btn-sm btn-success btn-icon" wire:click="mission_description"> <span>Continue</span> </button>
</div>
</div>
<div wire:loading wire:target="photo">Uploading...</div>
#if($photo)
<img src="{{ $isUploaded ? $photo->temporaryUrl() : asset('public/'.$photo) }}" width="150" height="150">
#endif
ScreenShot:
Front View Screenshot
It is a temp file and Livewire can't serialize it on subsequent requests. You have to store the file
https://laravel-livewire.com/screencasts/s5-intro
Do you by any chance have multiple components for each step?

How to use laravel shweshi/OpenGraph

Here how to use it according to its GitHub
I already install the package:
Use Opengraph
$data = OpenGraph::fetch("http://www.addemyplus.com/blogs/my-faith-for-your-love");
that may return an array:
{"type":"website","title":"My Faith For Your Love","description":"","image":"http:\/\/www.addemyplus.com\/images\/frontend_images\/blogs\/medium\/57670.jpg"}
My problem is how can I use it on my blade that whenever I type a link in the form it will fetch the Og data of that site.
and show below the image and description
I have this code on form:
<form action="{{route('store_post_path')}}" method="POST">
{{csrf_field()}}
<div class="form-group">
<label class="sr-only" for="title">title</label>
<input type="text" class="form-control" name="title" placeholder="Your Post Title or Question">
</div>
<div class="form-group">
<label class="sr-only" for="post">post</label>
<textarea class="form-control" name="post_content" id="post_content" rows="3" placeholder="Briefly explain your question or Your Post Content"></textarea>
</div>
<div class="tab-pane fade" id="images" role="tabpanel" aria-labelledby="images-tab">
<div class="form-group">
<div class="custom-file">
</div>
</div>
<div class="py-4"></div>
</div>
<div class="btn-toolbar justify-content-between">
<div class="btn-group">
<button type="Submit" class="btn btn-primary">Share your Post</button>
</div>
</div>
</form>
How can I use the code to fetch the Og property of the link? I want to view the image and title of the link below before submitting my post.. Please show some tutorial sites for this.
Get the link from the form in post content. You can do it using regex.
function getUrl($string)
{
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $string, $match);
return ($match);
}
$url = getUrl($string)
If there are any links in post content you will get array of links.
Use OpenGraph::fetch($url) to fetch the OG data of the url. That you can show in the view.

Strange view error on Laravel

I have some cotroller like this:
Route::get('/article/create', 'ArticlesController#create');
and here's my ArticlesController#create:
public function create(){
return view('articles.create',
[
'title'=>'Add Artikel',
'username'=>'Whatever Myname',
'status' => 'Offline'
]
);
}
when i trying to access blog.dev/article/create i got this strange errors:
"Trying to get property of non-object (View: E:\xampp\htdocs\blog\resources\views\articles\single.blade.php)"
how come i can get this kind of error when my view is pointing at articles.create but the error is at single.blade.php which it suppose for ArticlesController#view?
this is what in create.blade.php:
#extends('admin.layout')
#section('content')
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Horizontal Form</h3>
</div>
#include('admin.formerrors')
<form method="post" class="form-horizontal" action="/articles">
{{ csrf_field() }}
<div class="box-body">
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input class="form-control" id="title" name="title" placeholder="Judul Artikel">
</div>
</div>
<div class="form-group">
<label for="content" class="col-sm-2 control-label">Content</label>
<div class="col-sm-10">
<textarea class="form-control" rows="3" id="content" name="content"></textarea>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
#endsection
and here's in my single.blade.php :
#extends('admin.layout')
#section('content')
<h1>{{ $article->title }}</h1>
<p>{{ $article->content }}</p>
<hr>
#foreach($article->comments as $comment)
<blockquote>
<p>{{ $comment->comment }}</p>
<small>{{ $comment->created_at->diffForHumans() }}</small>
</blockquote>
#endforeach
#include('admin.formerrors')
<form method="post" class="form-horizontal" action="/article/{{ $article->id }}/comment">
{{ csrf_field() }}
<div class="box-body">
<div class="form-group">
<label for="comment" class="col-sm-2 control-label">Comment</label>
<div class="col-sm-10">
<textarea class="form-control" rows="3" id="comment" name="comment"></textarea>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
#endsection
and here's my router:
Route::get('/articles', 'ArticlesController#index')->name('home');
Route::post('/articles', 'ArticlesController#save');
Route::get('/article/{id}', 'ArticlesController#view');
Route::get('/article/create', 'ArticlesController#create');
Route::post('/article/{article}/comment', 'CommentsController#save');
Route::get('/register', 'RegistrationController#create');
Route::post('/register', 'RegistrationController#store');
I try to change the create function by pointing into another view, but still it showing same error and pointing at single.blade view.
I delete all code at single.blade and write 'test' text, i don't get any errors. but i'm pointing my controller for viewing into create.blade not sigle.blade
After seeing you routes the problem is in this two routes :
Route::get('/article/{id}', 'ArticlesController#view');
Route::get('/article/create', 'ArticlesController#create');
In this case Laravel will consider the create in your path blog.dev/article/create as an id parameter of the view route here => /article/{id}.
So as a solution you should simply inverse the two routes :
Route::get('/article/create', 'ArticlesController#create');
Route::get('/article/{id}', 'ArticlesController#view');
You need to find what's in the file by reading more than just that line. Maybe you're including that file in the articles.create? Maybe you're accessing a variable that doesn't exist whenever you load the page. Edit your answer with more of the error and what's inside both blades and we can pinpoint what's wrong.

laravel 5.2 greggilbert/recaptcha : array_merge(): Argument #1 is not an array

I installed greggilbert/recaptcha in my laravel 5.2 project. I followed the direction accordingly described here:https://github.com/greggilbert/recaptcha
But when I opened the form where I used recaptcha, I found the above message.
I read the source code but understand nothing.
Can anybody help me in this regard to find any solution?
Thanks in advance.
Here is my form HTML Code
#section('form')
{{ Form::open(array('url' => 'contact')) }}
<div class="panel-body">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-comment blue"></i></span>
<textarea name="InputMessage" rows="6" class="form-control" required placeholder="Message"></textarea>
</div>
</div>
{!! Recaptcha::render() !!}
<div class="">
<button type="submit" class="btn btn-info pull-right">Send <span class="glyphicon glyphicon-send"></span></button>
<button type="reset" value="Reset" name="reset" class="btn">Reset <span class="glyphicon glyphicon-refresh"></span></button>
</div>
</div>
{{Form::close()}}
#endsection
The Problem is solved.
The problem was:
php artisan vendor:publish --provider="Greggilbert\Recaptcha\RecaptchaServiceProvider"`
command did nothing.
So recaptcha.php file was not copied to root config folder.
I copied the recaptcha.php file from
vendor > greggilbert > recaptcha > src > config > recaptcha.php`
to config folder and the problem disappears.
After vendor publishing you need to clear config cache using command
php artisan config:cache

Laravel 5 TokenMismatchException on login

I developed an application with laravel locally with homestead and now I try to get it running on a shared host. As soon as I hit the login button I get the exception: TokenMismatchException in VerifyCsrfToken.php line 53
I read that many people have problems with the TokenMismatchException but all of the proposed solutions didn't work for me. I deleted all files in the storage/framework/sessions folder (and the folder has 777 permissions). I deleted all cookies and since I use {!! Form:open !!} the hidden _token field exists (I also posted the source code).
My whole app expects the user to be logged in, so immediately after visiting the page I get redirected to the login form.
auth/login.blade.php
#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">Login</div>
<div class="panel-body">
{!! Form::open(array('url' => '/auth/login', 'class' => 'form-horizontal')) !!}
<div class="form-group">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
{!! Form::email('email', null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
{!! Form::password('password', ['class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
{!! Form::checkbox('remember', '1', false, ['id' => 'remember']) !!}
{!! Form::label('remember', 'Remember Me') !!}
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
{!! Form::submit("Login", ['class' => 'btn btn-block btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
#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
</div>
</div>
</div>
</div>
</div>
#endsection
This is how the source code looks like:
<input name="_token" type="hidden" value="HoSZ4shS8b1avwrkJZzGiUQCWRZL0VPtj3mfvJmI">
<div class="form-group">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input class="form-control" name="email" type="email">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input class="form-control" name="password" type="password" value="">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<input id="remember" name="remember" type="checkbox" value="1">
<label for="remember">Remember Me</label>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<input class="btn btn-block btn-primary" type="submit" value="Login">
</div>
</div>
</form>
Part of my routes.php
Route::get('auth/login', 'Auth\AuthController#getLogin');
Route::post('auth/login', 'Auth\AuthController#postLogin');
Route::get('auth/logout', 'Auth\AuthController#getLogout');
I'm not sure which code is necessary to see to be able to help me with this, please let me know if I need to post some more.
Thanks to everyone who cares about my question.
Is the URL in the <form> tag correct? Is the host name the same as the one where you're visiting the page?
I'll explain:
Imagine you're developing a site at http://www.mypage.com and while you're developing, you're visiting http://localhost.
If you visit http://localhost/auth/login and the form tag looks like this:
<form action="http://www.mypage.com/something">
You're going to get the TokenMismatchException when you submit a form.
Why? It's all about cookies.
When you visit a page at http://localhost, Laravel creates a session and saves the session ID to your browser in a cookie. Cookies are (generally) only accessible to pages from the same host, so if you visit http://localhost/page1 and http://localhost/page2, the server knows that those two visits are part of the same session because the cookie is accessible on both page visits.
If, on the other hand, you visit http://localhost/page1, then you visit http://www.mypage.com/page2, the server has no way of knowing that those two visits are part of the same session, because the cookie that was set when you visited page1 is not available when you visit page2 (because the host name is different).
So, that's what I think is happening:
you visit http://localhost/auth/login while you're developing.
Laravel sets up a CSRF token and adds it to the form on the page
Laravel also inserts the action for the form tag as http://www.mypage.com/auth/login (or whatever the default value is).
You click submit and the request is sent to http://www.mypage.com/auth/login (because that's what's in the form tag)
Laravel gets a token which does not match what it saved for your session at http://www.mypage.com (if a session even exists) because it doesn't have the session ID that it assigned to the session visiting http://localhost
The solution is to check your config & ensure that you're doing all the development via visits to a single hostname.
I somehow solved this now. I installed Laravel from scratch on the server and tried to copy as little as possible and make most changes manually. Don't know what lead to this Exception though.
Here is the thread that led me to the solution: https://laracasts.com/discuss/channels/code-review/request-session-token-not-equal-token/

Resources