vendredi 27 mars 2020

Log ERRORs html form post to external url

My API brings the client to my domain, this API request contains a parameter called return_url, where after process is complete on my domain we will post on client's return_url along with response parameter.

To do this, redirect to return_url, I have code as following:

<form action="http://client-return-url.com" method="post" name='returnform'>
    <input type="hidden" name="request_id">
    <input type="hidden" name="status">
</form>
<script>
    window.onload = function(){
      document.forms['returnform'].submit();
    }
</script>

This works fine.

Is there a way I can save a log if there is error, for example the return url is incorrect URL that doesn't exist, or there is a 500 error due to some code issue on return_url.

Again, return_url is not in my control, the moment I do a form post control is away from me, but I want to inform my clients of any error when I do form post on their return_url.

Thanks,

K



via Chebli Mohamed

force encoding to work on request made for laravel api by web browser

I am maintaning an API that have some requests made by a front-end app. When I call it from postman, all work well, including its encoding. The response is:

{ "message": "Esse nome de usuário está disponível" }

However, when I make it from browser, I receive:

{"message":"Esse nome de usu\u00e1rio est\u00e1 dispon\u00edvel"}

I already made this tutorial, that creates an middleware forcing the encoding, and on my project I set it like this, unlike the code it sugests:

$request->headers->set('Accept', 'application/json; charset=UTF-8');
$request->headers->set('Charset', 'utf-8');

In postman, I saw that these headers were not setted in the response of the request.

Also, I already tried to set in my controller response:

return response()->json([
                'message' => __('auth.nickname_available'), 
            ], 200, ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8']);

I followed this tip. But neither worked.

How can I can make this work well?



via Chebli Mohamed

Using MPDF version 6.0

Previously i used mpdf version 8.6.For that i used laravel framework 5.4, Top of controller

use mPDF\mPdf;

In Controller constructor,

 $mpdf = new mpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);

In function used

 $mpdf = new mpdf();                   

  $mpdf->SetHTMLHeader($this->header($data),'1', true);

  $mpdf->SetHTMLFooter($this->footer());

  $mpdf->AddPage('p','','','','',10,10,37,20,10,10);

   $mpdf->WriteHTML($html);

   $mpdf->Output();

Due to my server version 5.6 i have to use mpdf 6.1.0 version. For that version using the same code i get error



via Chebli Mohamed

Property or method is not defined on the instance but referenced during render while passing data from Laravel to Vue

I tried to pass data(or variable) from Laravel controller to Vue component via blade but i faced this error.

app.js

Vue.component('vue-home', require('./components/HelloWorld.vue').default);

const app = new Vue({
    el: '#app',
});

My controller

        $slider = DB::table('sliders')->orderBy('place')->get();

        return view('main/index',compact('slider'));

index.blade.php

<!-- /resources/views/main/index.blade.php -->
@extends('layouts.app')
@section('content')
    <div id="app">
        
        <vue-home slider=""></vue-home>
    </div>
@endsection

HelloWorld component script

<script>
    export default {
        name: 'HelloWorld',
        props: ['slider'],

        data: function () {
            return {
                slider:this.slider,
            }
        },
        mounted(){
            console.log(this.slider)
        }
    }
</script>

But nothing shown in my page besides design and i want to pass my data . How can i achieve that?
Btw , Vue dev tools say that VueHome has attrs and i can see data in here .



via Chebli Mohamed

Laravel Bootstrap Modal - Show modal on click event with AJAX call data

I have been reading many questions and I didn't find a clear example on how to popup a bootstrap modal for each record in a table. Click event on a button for each record will popup a bootsrtap modal and fill it with data that comes from an AJAX get request to laravel. Each record can have different modals, so I believe also it's necessary to set a unique id attribute for each row. Frontend and backend is developed in laravel.

Is there any basic example as a starter?

Regards



via Chebli Mohamed

How to download file when function in queue in laravel?

I have two function first get files and second make zip file and download it. I make jobs for both of these functions queue is working correct. it is making zip file not downloading it. i think because it is in queue . here i am posting second function which is in queue

queue

 Consignment::withChain([
      new ConsignmentDownload($id)
  ])->dispatch($id);

in ConsignmentDownload here is function consignmentDownload

 public static function consignmentDownload($id)
  {

    $manifestId = $id;
    $manifests =  Manifest::find($manifestId);
    $zipper = new \Chumper\Zipper\Zipper;

    $path = public_path('manifest_pdfs/manifest_' . $manifestId);

    foreach ($manifests->consignments as $allConsignment) {

      $filepath = $path . '/cosignment_' . $allConsignment->id . '_pod.pdf';

      //add/create pdf zip 
      $zipper->make($path . '/manifest_' . $manifestId. '.zip')->add($filepath);
    }

    $zipper->close();


    return response()->download($path . '/manifest_' . $manifestId . '.zip');

  }

return response()->download is not working i want to download that zip file.



via Chebli Mohamed

can't add user photo with vuejs

i have built a profile components to my projects (laravel+vuejs) when i try to show the user photo in her place it didn't show i try many ways but no solution .when i check the DB i find it but there is a problem that i can find it..Any help guys??? this the code belongs to how i want to sow the user photo:

       <div class="row">
      <div class="col-md-3"  v-for="user in users"  v-if=" user.id == key "  :key="user.id">


        <!-- Profile Image -->
        <div class="card card-primary card-outline"  >
          <div class="card-body box-profile">
            <div class="text-center">
              <img class="profile-user-img img-fluid img-circle" :src="getProfilePhoto()" 
               alt="User profile picture" >
            </div>

and this the main script :

<div class="form-group row">
                                <label for="photo" class="col-sm-3 col-form-label">Profile Picture</label>
                          <div class="col-sm-10">
                                    <input type="file"  name="photo"  @change="updateProfile" class="form-input">
                                </div>

                            </div>

                  <div class="form-group row">
                    <div class="col-sm-10">
                      <button   @click.prevent="updateInfo"  type="submit" class="btn btn-danger">Submit</button>
                    </div>
                  </div>
                </form></div>
              </div>
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
          </div><!-- /.card-body -->
        </div>
        <!-- /.nav-tabs-custom -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  <!-- /.container-fluid -->
   <!-- /.content -->
         </div>

          </div>
       </div>
    </div>


  </template>

    <script>
export default {
    data(){
     return{
    form : new Form({
    location:'',
    eucation:'',
    photo:'',
    skills:'',
    email:'',
    password:''

   }),

         key : this.$route.params.id,
          users:[],
            roles:{},
            role:{
                id:'',
              role:''
            },
            user:{

            },

     }
    },
    methods:{
          afficherMembre(){
               axios.get('/api/membre').then(({ data }) =>(this.users = data.data));
          },
         getProfilePhoto(){

            let photo = (this.form.photo.length > 200) ? this.form.photo : "/img/profile/"+ 
        this.form.photo ;
            return photo;
        },

        updateInfo(){
        this.form.put('/api/profile')
            .then(()=>{
                this.form.reset();                 })
            .catch(() => {
                               });
        },
        updateProfile(e){
            let file = e.target.files[0];
            let reader = new FileReader();

            let limit = 1024 * 1024 * 2;
            if(file['size'] > limit){
                swal({
                    type: 'error',
                    title: 'Oops...',
                    text: 'You are uploading a large file',
                })
                return false;
            }

            reader.onloadend = (file) => {
                this.form.photo = reader.result;
            }
            reader.readAsDataURL(file);
        },
        afficherProjet(){
        axios.get("/api/getProjectsUserConnecte").then(({ data }) => (this.projets = data));
        },
    },


created(){
   this.afficherMembre();
},
    mounted() {
        console.log('Component mounted.')
    }


  }


via Chebli Mohamed