Tag Archives: alert

[Solved] Model Error: must return a relationship instance

Model Error: must return a relationship instance

There is a method in the model as follows:

public function adjustbills()
    {
        if($this->user_combined == '1'){
            $invoiceNumberArr = ['xxx'];
            return Adjustbill::whereIn('invoice_number',$invoiceNumberArr)->where('user_id', $this->user_id);
        }else{
            return $this->hasMany(Adjustbill::class, 'invoice_number', 'invoice_number')->where('user_id', $this->user_id);
        }
    }

When the calling method is model -> When adjustbills,

  1. If it goes to the following judgment, no error will be reported
  2. If it goes to the above judgment, it will report an error must return a relationship instance, because laravel uses the following hasMany relationship by default, if not, it will report an error.

Solution:

  1. Find a way to modify the above logic to the following way of relationship
  2. Called as :model->adjustbills->get()

Vant configures multiple sites, and new sites 404 error [How to Solve]

1.configure the homestead.yaml file
Add folder mapping, domain name directory mapping (note the layer mapped to the entry file)

2. Configure hosts file

3. Reload vagrant (reload the modified configuration file)

vagrant provision&&vagrant reload

#After reloading the configuration, open vagrant
vagrant up && vagrant ssh

4. Restart nginx

service nginx restart

5. Successfully open the newly added site

Error 0 when adding SSL access to laravel project

Problem Description: project development framework DCAT, server management tool pagoda, configure SSL. Log in and report error 0. Check the nginx error log and find that it is not written. When the browser opens the debugging function, the console reports an error fastcgi send in stderr: “PHP message: PHP fatal error: allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in, the configuration file. Env configuration HTTPS and JS base file HTTPS have been changed.

Solution:
find config/admin.php and change the HTTPS configuration item to true

Undefined index: name error in composer [How to Solve]

I made this mistake when:

Laravel version 5.8, need to introduce tcpdf, in the run

composer require tecnickcom/tcpdf

I found two answers, both of which were caused by the composer upgrade, but I don’t remember that I was promoted. I learned from one of the methods and successfully introduced the tcpdf extension. Now I integrate the two methods:

1. Change the source code

Positioning error:

vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php

122 line prompt does not have the key name, according to the code prompt to find

/vendor/laravel/framework/src/Illuminate/Support/Collection.php

Of   Mapwithkeys method. Add a compatible method to cover the original method

 public function mapWithKeys(callable $callback)
    {
        $result = [];
        $item = $this->items;
        if(isset($item['packages'])){
            $item = $item['packages'];
        }
        foreach ($item as $key => $value) {
            $assoc = $callback($value, $key);
 
            foreach ($assoc as $mapKey => $mapValue) {
                $result[$mapKey] = $mapValue;
            }
        }
 
        return new static($result);
    }

2. Composer level

# composer Downgrade (if you can't downgrade, you can try to run with root privileges)
composer self-update --1
 
# Re-install and It's Done!!!
composer install 

The above two methods are effective