vendredi 30 septembre 2022

File upload issue using ajax in laravel 6

I am trying to store pdf along with other input value using ajax in laravel 6. Here I did not use form html element . It shows Call to a member function getClientOriginalExtension() on null . How can I send file ?

In Blade

<input name="phone" type="text" class="form-control phone">
<input type="file" name="my_doc" accept="application/pdf" class="my_doc" id="my_doc">

<button type="button" class="store_new"> Save </button>

$(document).on('click', '.store_new', function () {
   var phone= $('.phone').val();
   var my_doc= $('.my_doc').val();

   $.ajax({
        url: '',
        type: "POST",
        headers: {
             'X-CSRF-TOKEN': ''
        },
        data: {
            phone: phone,
            my_doc: my_doc,
        },
        success: function (response) {
                   
        },
        error: function (jqXHR, textStatus, errorThrown) {

        }
     });
});

In controller

use File;

public function store(Request $request)
{
  
    $image = $request->file('my_doc');
    $new_name = rand() . '.' . $image->getClientOriginalExtension();
    $image->move(public_path('final_doc'), $new_name);

}


via Chebli Mohamed

mercredi 28 septembre 2022

I want my selectEnhenced form to show a searched name with its type next to it as a hint

I have this form - for example a form for a new city - with some different selects and inputs. In one of them a user have to choose a commune - a commune for that particular city.

Before, on the select list, there was only a name of a commune, without the type - everything worked perfectly - but then I realised that to choose the right commune, the user need to know it's type too.

What I'm trying to make is something like this: when a user will type a name of a commune, it will show a list of available communes - the name of the commune with the type of that commune next to it:

see the pic

I tried to:

  • change my model - in many different ways - for example by creating a new function that would contain two others;
  • modify ajax - make something similar as in return?

But nothing works. In general I get a 500 server error because I want to put two "names" in one select. Is it possible to make it work the way I want?

Here are examples of my code:

  • FormTrait:

              $form->selectEnhanced('commune_id', trans('dict.commune'))
                  ->options(function ($id) {
                      $id = $id ? $id : old('commune_id');
                      if ($id) {
                          $commune = Commune::find($id);
                          return [$commune->id => $commune->communetranslation->name . ' (' . $commune->communetypetranslation->name . ')'];
                      }
                  })
                  ->ajax('/' . config('admin.route.prefix') . '/api/communes', 'id', 'communetranslation.name')
                  ->loadParent('district_id', '/' . config('admin.route.prefix') . '/api/districts');
    
  • Model:

     public function communetranslation()
     {
      return $this->getRelationDefinition($this->hasOne(CommuneTranslation::class, 'commune_id', 'commune_id'), 'commune_translations', 'commune_id');
     }
    
     public function communetypetranslation()
     {
      return $this->getRelationDefinition($this->hasOne('App\Models\CommuneTypeTranslation', 'commune_type_id', 'id'), 'commune_type_translations', 'commune_type_id');
     }
    


via Chebli Mohamed

mardi 27 septembre 2022

my project on laravel 5 but i can`t install dom pdf package

Problem 1 - Root composer.json requires barryvdh/laravel-dompdf 0.8.2 -> satisfiable by barryvdh/laravel-dompdf[v0.8.2]. - barryvdh/laravel-dompdf v0.8.2 requires dompdf/dompdf ^0.8 -> found dompdf/dompdf[v0.8.0, ..., v0.8.6] but it conflicts with your root composer.json require (^2.0).

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.



via Chebli Mohamed

lundi 26 septembre 2022

What is the difference between using where() clause With() and wherehas() in relationship model

I have two relationship table. I used with using where to filter records as well as i used wherehas using where to filter records. But can't find the differences between both



via Chebli Mohamed

Laravel access admin panel after Logged in flutter app

I have a Laravel web application with admin panel, now I have a flutter app , of which all the screens except login are web views. Here I need to redirect the mobile users to admin panel based on the roles after successfully logged in by mobile app, my question here , that Is it possible to redirect users to admin panel after logged in mobile device trough API, I just want to login through mobile app (API), then I need to access the admin panel without logged in again .. It will be great if any one can help me on this



via Chebli Mohamed

jeudi 22 septembre 2022

Illegal offset type in isset or empty (View: file.blade.php)

I am getting an error in my file.blade.php but every thing in file is correct

traces

FileViewFinder.php (line 71)

public function find($name)    {        
if (isset($this->views[$name])) {

Error starts from line 71 of FileViewFinder.php

any help is appreciated



via Chebli Mohamed

mardi 20 septembre 2022

ErrorException : Trying to access array offset on value of type int

i'm getting the issue of "Trying to access array offset on value of type int" when i export the data using "maatwebsite/excel": "~2.1.0" Excel package.

Excel::create('Filename', function($excel) use ($data){
  $excel->sheet('Sheetname'), function($sheet)use ($data) {
    $sheet->fromArray($data); //getting error on this line
  });
}); 



$data = 
 array:198 [
   0 => array:19 [
     "Id" => 1
     "First Name" => "John"
     "Last Name" => "Doe"
     "comments" => null
   ]
   1 => array:19 [
     "Id" => 2
     "First Name" => "James"
     "Last Name" => "Harrison"
     "comments" => null
   ]
   ...


via Chebli Mohamed