jeudi 26 mars 2020

Laravel mongodb package installation problem

when I am writing this in cmd "composer require jenssegers/mongodb" or "composer require jenssegers/mongodb --ignore-platform-reqs" this error is showing:

Using version ^3.6 for jenssegers/mongodb ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

Problem 1 - Conclusion: don't install jenssegers/mongodb v3.6.3 - Conclusion: don't install jenssegers/mongodb v3.6.2 - Conclusion: don't install jenssegers/mongodb v3.6.1 - Conclusion: remove laravel/framework v5.5.48 - Installation request for jenssegers/mongodb ^3.6 -> satisfiable by jenssegers/mongodb[v3.6.0, v3.6.1, v3.6.2, v3.6.3]. - Conclusion: don't install laravel/framework v5.5.48 - jenssegers/mongodb v3.6.0 requires illuminate/events ^5.8|^6.0 -> satisfiable by illuminate/events[v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.2, v6.18.3, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0]. - don't install illuminate/events v5.8.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.11|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.12|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.14|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.15|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.17|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.18|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.19|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.2|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.20|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.22|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.24|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.27|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.28|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.29|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.3|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.30|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.31|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.32|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.33|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.34|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.35|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.36|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.4|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.8|don't install laravel/framework v5.5.48 - don't install illuminate/events v5.8.9|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.0.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.0.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.0.2|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.0.3|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.0.4|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.1.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.10.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.11.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.12.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.13.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.13.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.14.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.15.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.15.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.16.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.17.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.17.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.18.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.18.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.18.2|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.18.3|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.2.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.3.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.4.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.5.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.5.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.5.2|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.6.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.6.1|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.6.2|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.7.0|don't install laravel/framework v5.5.48 - don't install illuminate/events v6.8.0|don't install laravel/framework v5.5.48 - Installation request for laravel/framework (locked at v5.5.48, required as 5.5.*) -> satisfiable by laravel/framework[v5.5.48].

Installation failed, reverting ./composer.json to its original content.

What am I doing wrong? Laravel version is 5.5 mongoDB version is v4.2.3



via Chebli Mohamed

Accessing a hasMany relation function via Collection

I am trying to get all of the users notifications, and depending on if the user is a buyer or seller (can be both). I have made two functions in my notifications table to filter each other out. My goal is to ultimately run:

$notifications = Auth::user()->notifications()->getBuyerNotifications();

or

$notifications = Auth::user()->notifications()->getSellerNotifications();

I am running into an issue: Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany

User Model:

public function notifications() {
   return $this->hasMany('App\Notification', 'user_id', 'id');
}

Notifications Model:

public function user() {
  return $this->belongsTo('App\User', 'id', 'user_id');
}

public static function getBuyerNotifications() {
  return self::whereNotNull('buyer_id')
              ->whereNull('deleted_at')
              ->get();

}

public static function getSellerNotifications() {
      return $this->whereNotNull('seller_id')
                    ->whereNull('deleted_at')
                    ->get();
}

The command I want to run to get all of the users notifications if they're a buyer: $notifications = Auth::user()->notifications()->getBuyerNotifications();



via Chebli Mohamed

Laravel Raw query convert into Eloquent ORM format

can anyone help me to convert this query

SELECT 
   employees.username, 
   employees_attendance.employees_id, 
   SUM(employees_attendance.worked_hours) 
FROM 
   employees_attendance 
LEFT JOIN 
   employees ON 
   employees_attendance.employees_id=employees.id 
WHERE 
   timein LIKE '2020-03-26 %' 
GROUP BY 
   employees_attendance.employees_id

into laravel eloquent ORM 2020-03-27 today date.

I wrote like this but syntax voilation error

DB::table('employees_attendance')
          ->leftJoin('employees', 'employees_attendance.employees_id', '=', 'employees.id')
          ->where('employees_attendance.employees_id', '=', 'employees.id')
          ->whereDate('timein', Carbon::today())
          ->select('employees.id as emp_id','employees.username as name')
          ->groupBy('employees_attendance.employees_id')
          ->get();


via Chebli Mohamed

Laravel Auto-resolve (Auto DI) not the same as registered provider

In my Laravel 5.7 project, I'm trying to auto-inject a Guzzle instance in to any controller or service that needs it. It's simply enough to just type-hint the class and have it inject automatically, but I don't have control over its initial state. I want some presets on Guzzle before each constructor receives it.

I created a GuzzleServiceProvider that registers like so: (note: verify=false)

            $this->app->bind('\GuzzleHttp\Client', function () {
                $stack = HandlerStack::create();
                $stack->push(Middleware::retry($this->decider(), $this->delay()));

                return new Client(['handler' => $stack, 'verify' => false]);
            });

This works fine if I use it in a constructor like so:

$client = app()->make('\GuzzleHttp\Client');

It is proven to be an instance of the one registered in the provider because I can dump the $client and see that verify=false. Guzzle defaults to true so this is working.

However when injected as a dependency, verify=true and the handler stack initial settings I made don't have any effect. This is because it's a different instance of Guzzle.

Is there any way for the dependency injection to use the registered instance, rather than creating a new one?

Thanks!



via Chebli Mohamed

Eloquent whereHas Relationship with constraint on particular related Entity

Consider having two models User, and Book the last one has a status column that can obtain different string values active, inactive, deleted, so the user can have multiple books and the book belongs to the user.

how could I get only users that have their last book status = 'inactive'?

The SQL Query for the behavior is given below:

SELECT
    *
FROM
    `users`
WHERE EXISTS
    (
    SELECT
        *
    FROM
        `books`
    WHERE
        `books`.`user_id` = `users`.`id` AND `books`.`status` = 'inactive' AND `books`.`id` =(
        SELECT
            nested.`id`
        FROM
            `books` AS nested
        WHERE
            nested.`user_id` = `users`.`id`
        ORDER BY
            nested.`created_at` DESC
        LIMIT 1
    )
)

I'm using Laravel 5.6



via Chebli Mohamed

Join 3 tables in Laravel to get one attribute from each one

I have three tables

warehouses
PK warehouse_id
warehouse_name

good_quantities
PK good_quantity_id
FK good_id
FK warehouse_id
quantity

goods
PK good_id
good_name

And i wrote their models with the relationships with each others

Good Model

class Good extends Model
{
/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'goods';

/**
 * Get the Good Quantity for this Good.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','good_id');
}

}

Warehouse Model

class Warehouse extends Model
{
/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'warehouses';


/**
 * Get the Goods Quantity for this Warehouse.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','warehouse_id');
}

}

Good_Quantity Model

class Good_Quantity extends Model
{
/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'good_quantities';

/**
 * Get the Good's Info.
 */
public function good()
{
    return $this->belongsTo('App\Models\Good','good_id');
}

/**
 * Get the Good Quantity's Warehouse.
 */
public function warehouse()
{
    return $this->belongsTo('App\Models\Warehouse','warehouse_id');
}

}

So i'm trying to get all the good quantities records in a certain warehouse, And want to display it in a View like this:

| good_name | warehouse_name | quantity |

What is the right query to get this result with Eloquent?



via Chebli Mohamed

Laravel Ajax - Uncaught ReferenceError: KWS1389776 is not defined at HTMLButtonElement.onclick

I have an AJAX call to fetch a record in model and display values in a modal that must popup after GET request is done.

The javascript console is returning Uncaught ReferenceError: KWS1389776 is not defined at HTMLButtonElement.onclick

It looks some issue in how the variable is passed to javascript function in onClick event.

This is the code developed:

<button type="button" class="btn btn-label-primary btn-lg btn-upper" 
data-toggle="modal" data-target="#kt_modal_4_2" 
onClick="getPropertyDetails()">
</button>
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Property;

class PropertyController extends Controller
{
    public function details($id)
    {
        $property = Property::where('prop_id', $id)->first();
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }
}
function getPropertyDetails(prop_id) {
    console.log(prop_id);

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        method: 'GET',
        url: '/property/details/' + prop_id,

        success: function (data) {
            console.log(data);

            if (data.status != 200) {

                console.log(data.status);
                swal.fire({
                    "title": "",
                    "text": "Ocurrió un error, contactar al administrador",
                    "type": "error",
                    showConfirmButton: !1,
                    timer: 3000,
                    onClose: () => {
                        window.location.reload();
                    }
                });

            }
            $('#kt_modal_4_2').modal("show");


        }
    });
}



via Chebli Mohamed