lundi 19 juin 2023

file_exists(): open_basedir restriction in effect

I am develope a laravel app. I go to the route folder myapp/routes/web.php on serve and register a new route as follows:

Route::get('/linkstorage', function () {
    Artisan::call('storage:link');
});

when i enter https://chanvay.store/linkstorage and hit enter. Error appeared

ErrorException (E_WARNING) file_exists(): open_basedir restriction in effect. File(/home/chanvays/domains/chanvay.store/public_html/public/storage) is not within the allowed path(s): (/home/chanvays/:/tmp:/var/tmp:/opt/alt/php81/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php81/lib/php/) Anybody help me ?

Anybody help me fix this issue ? I can not comman php artisan storage:link on serve.



via Chebli Mohamed

dimanche 18 juin 2023

Firebase Push Notification with Laravel 5.6

I am asking for help in push notification (especially Firebase Cloud Messaging : FCM). I already have checked the official documentation about it and it was pretty clear but i just wanna know how to have a simple summary of implementation of it using PHP Laravel 5.6 and what's the best practices on it . Thank you in advance for your help. I checked the official documentation of Firebase Cloud Messaging



via Chebli Mohamed

I Need to translate custom request validation Laravel

I Need to translate custom request validation laravel like extras.*.id.required

I Need to translate custom request validation laravel like extras.*.id.required i need to translate it without using messages() method i need the result get from translation files ,validation laravel



via Chebli Mohamed

samedi 17 juin 2023

Laravel Custom Rule Validation with Array of Form Fields

I want to access attribute values in the custom validation rule I created.

HTML

Designation Dropdown
<select name="resource[{?}][designation]>
<option value=1>First Value</option>
<option value=2>Second Value</option>
</select>

Allocation Dropdown
<select name="resource[{?}][allocation]>
<option value=1>First Value</option>
<option value=2>Second Value</option>
</select>

Controller Code

'resource.*.allocation' => ['required',new ResourceQuotation()],
'resource.*.designation' => 'required',

Laravel Custom Rule - ResourceQuotation

public function passes($attribute, $value)
{

$designation = request()->input("resource.*.designation"); <!--//I am confused here, how to access the designation array value since we might have multiple.!->

$allocations = ResourcePrice::select('allocation','fixed_allocation')->where('id',$designation)->first();

 if($allocations->fixed_allocation=1){
    $this->message = "Maximum allocation allowed is 10%";
    return false;
 }

 else{
   return true;
 }

}

public function message()
{
 return $this->message;
}

First I thought to use a loop but how to display individual message errors? I found this tutorial but they are using it for a single value comparison, not with different field attributes.



via Chebli Mohamed

vendredi 16 juin 2023

how to store form with 1500 plus fields using jquey ajax in laravel

How can I store a form with more than 1500 fields in Laravel 5.8?

Controller:

public function store(Request $request)
{
     dd($request->all());
}

View file:

@extends('main')
@section('content')

<form class="add_form" id="add_form" enctype="multipart/form-data">
@csrf
<input type="text" name="text_1" >
.
.
.
.
to 1514 parameters
<button type="button" id="submit" >Submit</button>
</form>

@endsection
@push('scripts')

<script type="text/javascript">
  $(document).ready(function(){
    $("#submit").on("click",function(e){
      e.preventDefault();
      if($("#add_form").valid()){
        $.ajax({
          type:"POST",
          url:"",
          data: new FormData($('#add_form')[0]),
          processData: false,
          contentType:false,

          success: function(data){
            if(data.status==='success'){
                  location.reload();
            }else if(data.status==='error'){
                  location.reload();
            }
          }
        });
      }else{
        e.preventDefault();
      }
    });
  });
</script>

@endsection

In my function, I'm only getting an array of 1000 fields, but in my form there are 1514 fields. How can I handle this?



via Chebli Mohamed

Wrong php version - laravel 5

I have a problem with the PHP version after running php --version. It should be the 5.6.40 PHP version, but after running this command into my Laravel (php --version), it shows PHP 8.2.40, but when I try to run phpinfo(), it shows 5.6.40 (this is the version I need, not 8.2.40). What am I going to do?

should be the 5.6.40 PHP version



via Chebli Mohamed

mardi 13 juin 2023

How can I filter on Multiple Checkbox values retrieved?

am working on a filtering system in Laravel PHP framework and I am trying to filter on products brand selected from a checkbox input.

When I try to retrieve Products lets say for example with the brand Intel which I have 3 product it works fine but when I try to filter on more then one value it's only receive the first selected checkbox item.

here is my view code:

<div id="filters-status" class="mt-3 collapse" aria-labelledby="filters-status-heading"
                            style="">
                            <ul class="space-y-6 mb-8">
                                @foreach ($prods->unique('marque') as $itme)
                                    <li>
                                        <label class="flex items-center cursor-pointer w-full">
                                            <input type="checkbox" id="terms" name="marque[]"
                                                value=""
                                                class="h-5 w-5 mr-2 rounded border-jacarta-200 text-accent checked:bg-accent focus:ring-accent/20 focus:ring-offset-0 dark:border-jacarta-500 dark:bg-jacarta-600">
                                            <span class="dark:text-white">
                                                
                                            </span>
                                        </label>
                                    </li>
                                @endforeach
                            </ul>
                            <input
                                class="cursor-pointer rounded-full bg-accent-lighter w-full py-3 px-8 text-center font-semibold text-white transition-all hover:bg-accent-dark"
                                type="submit" value="Soumettre">
                        </div>```

enter image description here This are the brands checkbox

and this is my controller code:

public function fliter(Request $request)
    {
        $brand = ($request->marque);
        $disponible = ($request->disponibilite);
        $query = DB::table('produits');
        if($brand){
            $query->where('marque', $brand);
        }
        if($disponible) {
            $query->where('disponibilite', $disponible);
        }
        $filtterProduits = $query->get();
        return response()->json($filtterProduits); 
    }

this is the Json result if i select one brand

{
"id": 3,
"sous_categorie": 1,
"fournisseur_id": 1,
"ref": "104081",
"filenames": "[\"168591280568.webp\"]",
"description": "13th Generation Intel® Core™ i5 Processors 10Coeur 16 Threads Max Turbo",
"designation": "CORE I5 13400F PROCESSOR",
"prix_achat": 35000,
"prix_gros": 36800,
"prix_vent": 40000,
"marque": "INTEL",
"disponibilite": 0,
"quantite": 10,
"created_at": "2023-06-04 21:06:45",
"updated_at": "2023-06-11 20:15:11"
},
{
"id": 4,
"sous_categorie": 1,
"fournisseur_id": 2,
"ref": "103329",
"filenames": "[\"168616970297.webp\"]",
"description": "13th Generation Intel® Core™ i7 Processors\r\nTotal Cores 16\r\nTotal Threads 24\r\nMax Turbo Frequency\r\n5.40 GHz",
"designation": "CORE I7 13700KF PROCESSOR",
"prix_achat": 45000,
"prix_gros": 50000,
"prix_vent": 56400,
"marque": "INTEL",
"disponibilite": 0,
"quantite": 10,
"created_at": "2023-06-07 20:28:22",
"updated_at": "2023-06-11 20:15:21"
},
{
"id": 5,
"sous_categorie": 1,
"fournisseur_id": 2,
"ref": "103327",
"filenames": "[\"168616985056.webp\"]",
"description": "13th Generation Intel® Core™ i9 Processors\r\nTotal Cores 24\r\nTotal Threads 32\r\nMax Turbo Frequency 5.80 GHz",
"designation": "CORE I9 13900KF PROCESSOR",
"prix_achat": 74000,
"prix_gros": 74500,
"prix_vent": 82000,
"marque": "INTEL",
"disponibilite": 0,
"quantite": 15,
"created_at": "2023-06-07 20:30:50",
"updated_at": "2023-06-11 20:15:31"
}

as u can see 3 items

when I try to retrieve more than one brand it's only gets me the first checkbox selected values.

please don't give me negative comments I am new to Laravel, thanks in advance .



via Chebli Mohamed