vendredi 2 juillet 2021

Property [costo] does not exist on this collection instance

i need to print the price of a service, but can't find the column with the price. maybe I'm doing something wrong with relationships, but I can't figure it out on my own

database: enter image description here

Controller:

  public function details(Request $request,$id){

    $datax = [
      'category_name' => 'apps',
      'page_name' => 'calendar',
      'has_scrollspy' => 0,
      'scrollspy_offset' => '',

  ];



  
    $evento = Eventos::find($id);
    $servicio = \App\Models\Eventos::select("servicio_id")->where('servicio_id', $evento->id)->get('servicio_id');
    $event = Eventos::find($id);
    $event->asistencia = $request->asistencia;
    $event->cancelado = $request->cancelado;
    $event->save();

    return view("evento",[
      "event" => $event,
      "servicio" => $servicio
    ])->with($datax);

  }

blade.php

  <div class="input-group mb-4">
  <div class="input-group-prepend">
    <span class="input-group-text">$</span>
  </div>
  <input type="text" value="" class="form-control col-md-3" aria-label="Amount (to the nearest dollar)">
  <div class="input-group-append">
    <span class="input-group-text"></span>
  </div>
</div>

I need to print the "costo" column in relation to service_id

help please



via Chebli Mohamed

jeudi 1 juillet 2021

Cannot connect Laravel to Pgsql - error Access denied for user 'homestead'@'localhost'

Am a beginner who is trying to connect Laravel with pgsql . I have successfully created a database in pgsql. but when tried php artisan:migrate install , i got the error Access denied for user 'homestead'@'localhost' .How to resolve this? Please help me with ur suggestions.

I have tried many things available in the internet like clearing cache & config- php artisan cache:clear php artisan config:clear php artisan config:cache, stopping & restarting artisan server, changing db variables of .env file back to the default and viceversa, renaming .env fle etc. but nothing worked. Also tried GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres; in psql, which shows GRANT msg, but still the same error persists.

Below given are the relevant lines of my .env file

DB_HOST=127.0.0.1
DB_DATABASE=flot
DB_USERNAME=postgres
DB_PASSWORD=ggg
DB_CONNECTION=pgsql


via Chebli Mohamed

generate graphic with chart.js in laravel 5.6

I´m traying to create a graphic in my app developed in Laravel 5.6.

I´m sending all my data from my controller with one array.

$callSend = array();
        
        foreach($result as $call){
            array_push($callSend, Cita::where('id_llamada', $call->id)
                                                        ->with("estado")
                                                        ->get());                                                      
        }

Cita it´s my model to get all my data this return this:

(754) [Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), …]

this it´s my return with show in console.log({!! json_encode($estados) !!})

and content of one array it´s:

[0 … 99]
0: Array(1)
0:
ciudad: "x"
cp: "x"
created_at: "2020-08-11 12:17:44"
direccion: "CALLE HERREROS, 17"
estado: {id: 5, nombre: "aplazada", desc: "APLAZADA", clase_span: "badge bg-secondary text-white", clase: "secondary"}
id: 13
id_comercial: 44
id_comercial2: null
id_estado: 5
id_llamada: 538
movil: ""
nomape: "DIEGO HIJO DE REMEDIOS JUMILLA TROLLANO"
provincia: "JAÉN"
telefono: "x"
updated_at: "2020-08-11 12:27:39"
__proto__: Object
length: 1
__proto__: Array(0)

i need get estado from this arrays estado it´s status. In my script i have this:

<script src="https://cdn.jsdelivr.net/npm/chart.js@3.4.0/dist/chart.min.js"></script>

        <script>
            console.log({!! json_encode($estados) !!});

            var ctx = document.getElementById('myChart').getContext('2d');
            var myChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: {!! json_encode($estados) !!},
                    datasets: [{
                        label: 'Estado de las llamadas pasadas a comerciales',
                        data: {!! json_encode($estados) !!},
                        backgroundColor: [
                            'rgba(255, 99, 132, 0.2)',
                            'rgba(54, 162, 235, 0.2)',
                            'rgba(255, 206, 86, 0.2)',
                            'rgba(75, 192, 192, 0.2)',
                            'rgba(153, 102, 255, 0.2)',
                            'rgba(255, 159, 64, 0.2)'
                        ],
                        borderColor: [
                            'rgba(255, 99, 132, 1)',
                            'rgba(54, 162, 235, 1)',
                            'rgba(255, 206, 86, 1)',
                            'rgba(75, 192, 192, 1)',
                            'rgba(153, 102, 255, 1)',
                            'rgba(255, 159, 64, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });

whith this {!! json_encode($estados) !!} but i can´t access to differents status. Also, i need group for differents states... My query, i think that it´s not correct to 100% i need one return so:

send: 5
commercialiced: 3
called: 1
null: 0

i need represent this in my chart but i can´t because it´s my first time with chart.js.

Thanks for help and read



via Chebli Mohamed

Laravel update function data not passing to DB but no error

Hey guys we are new to Laravel and Stack(hope this is a clear question) and recently made a post trying an update method with ajax and js but returned many problems, and since returned to a basic Laravel function. For some reason we can't quite understand why this function is not returning any data, there aren't any errors since we had parsed through them all.. sql contraints, null data, symphony handler etc etc.. as well as obviously reading other similar stack questions but with no resolution. We have tried to change the controller function, the method calls (PUT PATCH POST) Does anybody have any suggestions what is going wrong here? I'm sure its really obvious.. thank you!

Quindi.. User clicks edit post, makes edit, confirm.. page refreshes with no changes, no error and no data in database.

 <form id="form-edit-post" action="/posts//update" method="POST" data-parsley-validate>
                        
                        
 Route::patch('/posts/{id}/update', [PostsController::class, 'update'])->name('post.update');
    public function update(Request $request, Post $post)
    {       

        $this->validate($request, array(
            'content' => 'required',
            'location' => 'required',
        ));

        $post->user_id = Auth::user()->id;
        $post->content = $request['content'];
        $post->location = $request['location'];
        $post->update();

        return back()->with('success','Post Updated Successfully');
        
    }


via Chebli Mohamed

Use of undefined constant STDIN - assumed 'STDIN' when integrating google calendar api

I am integrating google calendar api and I am following their quickstart quide. But I am encountering one error which says

Use of undefined constant STDIN - assumed 'STDIN' (this will throw an Error in a future version of PHP)

Below is the code from google's quickstart guide

public function getClient()
    {
        $client = new \Google_Client();
        $client->setApplicationName('Dragon');
        $client->setScopes(\Google_Service_Calendar::CALENDAR_READONLY);
        $client->setAuthConfig(storage_path('app/google-calendar/credentials.json'));
        $client->setAccessType('offline');
        $client->setPrompt('select_account consent');

        $tokenPath = 'token.json';
        if (file_exists($tokenPath)) {
            $accessToken = json_decode(file_get_contents($tokenPath), true);
            $client->setAccessToken($accessToken);
        }
    
        // // If there is no previous token or it's expired.
        if ($client->isAccessTokenExpired()) {
            // Refresh the token if possible, else fetch a new one.
            if ($client->getRefreshToken()) {
                $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
            } else {
                // Request authorization from the user.
                $authUrl = $client->createAuthUrl();
                printf("Open the following link in your browser:\n%s\n", $authUrl);
                print 'Enter verification code: ';
                $authCode = trim(fgets(STDIN));
    
                // Exchange authorization code for an access token.
                $accessToken = $client->fetchAccessTokenWithAuthCode($name);
                $client->setAccessToken($accessToken);
    
                // Check to see if there was an error.
                if (array_key_exists('error', $accessToken)) {
                    throw new \Exception(join(', ', $accessToken));
                }
            }
            // Save the token to a file.
            if (!file_exists(dirname($tokenPath))) {
                mkdir(dirname($tokenPath), 0700, true);
            }
            file_put_contents($tokenPath, json_encode($client->getAccessToken()));
        }
        return $client;
    }

I google this error and there seems to be some solutions like below but that also didn't worked for me.

I place the below code in my artisan file of laravel directory or even tried to putting it right above where I call this constant but that also didn't worked for me.

define('STDIN',fopen("php://stdin","r"));

As you can see above code seems to be the solution all over the internet but it didn't worked.

Can anyone please tell me what I am doing wrong and missing.

Thank You.



via Chebli Mohamed

Cannot connect Laravel to Pgsql - error role "homestead" does not exist

Am a beginner who is trying to connect Laravel with pgsql . I have successfully created a database in pgsql. but when tried php artisan:migrate install , i got the error Access denied for user 'homestead'@'localhost' . Then i tried GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO homestead; in psql, which shown the error role "homestead" does not exist . When browsed the error i could see that if multiple versions of pgsql run simultaneously, this error happens. but i have only one pgsql version running in my system (pgsql -13.3) and i am using Windows os. How to resolve this? Please help me with ur suggestions.

Below given are the relevant lines of my .env file

DB_HOST=localhost
DB_DATABASE=flot
DB_USERNAME=postgres
DB_PASSWORD=abc
DB_CONNECTION=pgsql
DB_PORT=5432


via Chebli Mohamed

How to see pgsql version

I think multiple pgsql versions are simultaneously running on my system. I have tried many commands that were shown when i browsed but nothing shown the version. Can anyone help me to know my pgsql version.

enter image description here



via Chebli Mohamed