PHP code example of rackbeat / laravel-morph-where-has
1. Go to this page and download the library: Download rackbeat/laravel-morph-where-has library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rackbeat / laravel-morph-where-has example snippets
class Invoice extends Model {
// Old morph relation
public function owner() {
return $this->morphTo('owner');
}
// New solution
public function customer() {
return $this->morphTo('owner')->forClass(App\Customer::class);
}
public function supplier() {
return $this->morphTo('owner')->forClass(App\Supplier::class);
}
}
php
Invoice::whereHas('supplier', function($query) {
$query->whereName('John Doe');
})->get();