Problem with avatar must be an image. In laravel 5.8 - laravel

Before posting this question of mine I checked the similar problems but it doesn't solved my problem.
On my form I have the encrypt type
<form action="{{ route('user.update_avatar') }}" method="post" enctype="multipart/form-data">
...
</form>
Here's my validator
$request->validate([
'avatar' => 'required|image|mimes:jpeg,png,jpg,gif,svg'
]);
Here's the properties of the image which my form is accepting
Here's the image that gives the error
it puzzles me because they're both PNG but the other has an issues even though the PNG is included in my validator. The Error says,
Please help me solve this puzzle. Thank you so much in advance!

You should check your php.ini settings. Default is that uploads can only be 2M max
You need to check upload_max_filesize and post_max_size and make sure they are large enough to accommodate your uploads
Note that in php.ini, sizes are expressed as 4M, 5M etc (don't add the B)

Related

how to ignore iframe on blade Laravel

#Asking
Help me for my problem, when i built a website with Laravel
i am render my post with syntax like this :
<div>
<p>{!! $post->content !!}</p>
</div>
but i have problem, when i insert a i frame inside post, because the html has been removed with {!! !!}.
i have to try use {{ $post->content }}, but all content rendered with HTML
Any solution to this problem? ?
Thanks very much
With {!! you paste content "as is", in other words you become vulnerable to all types of issues like allowing <script> tags to be placed into your templates.
The {{ syntax will escape any HTML thus what you see is the actual html characters without actually parsing it (i.e. doing {{ '<b>bold</b>' }} will not result in a bold font but in the text <b>bold</b>).
Now with your problem: there are some cumbersome ways to filter out any html tags yourself and leave the <iframe>'s in there (something like {!! only_iframe($content) !!}), but it is quite difficult and will likely not result in a safe solution.
Your own answer which stated that you used {!!html_entity_decode($post->content)!!} simply means that your HTML was encoded to start with, which is not something I can deduct from your question. Note that you are now vulnerable to malicious code injection if you are not certain you can control the contents of $post->content.

Dispay Laravel blade content to user as is

I have laravel template.blade.php
<div class="classone">
<div class="classtwo">
text
</div>
<div class="classtwo">
text
</div>
</div>
And I would like to display the code to the user as it is. Incluing new line and indents.
I was playing around with {!! !!}, nl2br(view()->render() even Blade::compileString but was unable to find an elegant solution. Everytime I was able to make it work it was difficult to maintain and every small change to the displayed code was laber intense.
I would like to ask for a suggeston how to display more complex html/css/js code to user. I though it will be fairy often topic but was unable to find anything which would help me.
Thank you in advance.
I tried some things out. They may seem a little bit 'hacky' but I think they will suit your purpose. I used a freshly created Laravel 8 application as an example.
<pre>{{ file_get_contents( resource_path('views/welcome.blade.php')) }}</pre>
You can use the Blade facade to compile your blade file to plain php if you want:
<pre>{{ Blade::compileString(file_get_contents( resource_path('views/app.blade.php'))) }}</pre>
I put <pre></pre> tags around the output to show line breaks. It makes the code more readable.

Why isn't my view redirecting to a controller?

I have a html form inside one of my views that is supposed to get an image the user uploads and save it, the form is below:
<form class="col-lg-12" action="/banner/store/">
The form itself is quite large, but later on there's a to end it. It was supposed to redirect me to the banner/store where my Banner controller have a dd() function so I can confirm everything is okay. But instead, I get a blank white screen and the url goes banner/store/?.
The routes to the BannerController seems to be correct since banner/create works, the problem is when I go from create to store, but anyways, here's how I set the Routes:
Route::resource('banner', 'BannerController');
Any ideas why my banner/store won't work? And why is there a question mark on the end of the url? Sorry if this may be a dumb error, I'm still learning coding.
Your action is is wrong. When you use the resource static method then the store-url is the same as the GET url.
You can achive your goal with:
<form class="col-lg-12" action="{{ route('banner.store') }}" method="POST">
See more information in documentation.
When you updating your banner, you can't use the browser native form with PUT.
See in this document how laravel will handle that for you.

How to put image path in html::image() from database

I wanna put an image path in may laravel code like this
{!!Html::image({{$mdata->company_logo}},'logo',['width'=>60,'height'=>55])!!}
but {{$mdata->company_logo}} gives an error to html::image. I'm sure that image path from $mdata->company_logo has a valid data, namely the image path, because I can see it by using dd($data->company_logo).. But why html::image can't show the image...??
Thanks in advance.. :)
You shouldn't put the {{ }} around the $mdata->company_logo.
You are already inside a php block by using {!! !!} around Html::image().
Try {!!Html::image($mdata->company_logo,'logo',['width'=>60,'height'=>55])!!}.

Dropzone.js sends empty files

I'm using Dropzone with Laravel and no other threads about this problem have solved my issue.
Currently I load dropzone.js from a cdn.
And, as told in their doc, I just use these lines where I had to include the token with Laravel:
<form
action="{{ route('store_photo_path',['zip' => $flyer->zip, 'street' => $flyer->street]) }}"
class="dropzone"
>
{{ csrf_field() }}
</form>
On my PhotoController, the token arrives right so data is being recieved, but file is totally empty, so I can't manipulate the images. Here is the AJAX response (Laravel's Request object type):
{"_token":"Ng24JDmKn3ylX6p5sFmFvgDcsLp983BZ8IL7pXIN","file":{}}
I'm not using any kind of jQuery method or extending Dropzone behaviour, just trying to make it work in the most simple way Dropzone says it should work. I've checked including enctype does not work because removes the file object and Dropzone does not include it in their documentation, and you shouldn't include more input fields based on their documentation again.
Also, $_POST var has the same information (just the token and the file object empty).
Thanks.
Try adding the attribute enctype="multipart/form-data" to the form, which allows file uploads.

Resources