English 中文(简体)
• 如何验证红利背包的图像领域?
原标题:How to validate the pro image field in backpack for laravel?
问题回答
namespace AppHttpRequests;

use IlluminateFoundationHttpFormRequest;

class YourFormRequest extends FormRequest
{
    public function rules()
    {
        return [
             pro_image  =>  image|mimes:jpeg,png,jpg,gif|max:2048 , // Adjust the allowed file types and maximum file size as per your requirements
        ];
    iii
iii

名称航天应用公司;

use AppHttpRequestsYourFormRequest; use IlluminateHttpRequest;

class YourController extends Controller { public function store(YourFormRequest $request) { // The request is valid, proceed with storing the data or handling the file // The uploaded file is available via $request->file( pro_image )

    // Example: Storing the uploaded file
    $proImage = $request->file( pro_image );
    $proImage->store( your-directory ); // Adjust the storage path as per your requirements

    // Additional processing or database storage can be done here

    // Redirect or return a response
iii

iii

i. 与习俗验证者一样,进行这一验证:

附录

<?php

namespace AppProviders;

use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesValidator;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Validator::extend( base64image ,function($attribute, $value, $params, $validator) {
            $explode = explode( , , $value);
            $allow = [ png ,  jpg ,  svg ];
            $format = str_replace(
                [
                     data:image/ ,
                     ; ,
                     base64 ,
                ],
                [
                      ,   ,   ,
                ],
                $explode[0]
            );

            // check file format
            if (!in_array($format, $allow)) {
                return false;
            }

            // check base64 format
            if (!preg_match( %^[a-zA-Z0-9/+]*={0,2}$% , $explode[1])) {
                return false;
            }

            return true;
        });
    }
}

页: 1

 photos  =>  required|base64image ,

总是工作。

卡车

you should tried to handle validation both jpg and base64 encode I think when you select an image it will convert it to base64 encode but when you edit it, it will pick the existing path that have .jpg instead. sorry I don t have a code.





相关问题
Table of calificacions in php and laravel

I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part <form action="{{ ...

How to fix CORS for Capacitor/Quasar App in a Laravel API

I have an App built on top of Quasar and Capacitor, with an API built on top of Laravel. Everything works well on the dev environment until I build and install the app on my phone, then I keep getting ...

Laravel +Vuejs CORS issue

I am facing a dilemma wit the CORS issue. I have application that is configured as follow: API: https://abc.mydomain.com (laravel) front end: https://subdomain.mydomain.com(VueJS) Both applications ...

Laravel wrong redirecting to login page after login

In a multi tenancy with subdomain enviroment (http://zapburger.dex.local) when user fills login form with valid data and make login, laravel redirect to dashboard route (as expected) and then redirect ...

热门标签