“Laravel di mana memiliki hubungan” Kode Jawaban

Laravel di mana

use Illuminate\Database\Eloquent\Builder;

// Retrieve posts with at least one comment containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
})->get();

// Retrieve posts with at least ten comments containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
}, '>=', 10)->get();
Alberto Peripolli

hubungan hasone di Laravel

//Model Function
public function hasOneFunction(){
        return $this->hasOne('App\Models\ModelName', 'targetedId');
    }
//in controller function
$data = ModelName::with('hasOneFunction')->get();
Isaac

bagaimana mendapatkan data jika memiliki hubungan dalam laravel

Doctor::has('DoctorMessage')->with('DoctorMessage')->get()
Mohamad

Laravel bagaimana menanyakan hubungan milik

$movies = Movie::whereHas('director', function($q) {
    $q->where('name', 'great');
})->get();
Fragile Flatworm

Laravel di mana memiliki hubungan

// Laravel 8+ or above
$projects = Project::whereRelation('projectOffers', ['teacher_id'=>'Naveed', 'status_id'=>'Approved'])->where('status_id', "In Progress")->get();

// Laravel 8 below
$projects = Project::whereHas('projectOffers', function ($offer) {
            $offer->where('teacher_id', "Naveed");
            $offer->where('status_id', "Approved");
        })->where('status_id', "In Progress")->get();
Naveed Shahzad

Jawaban yang mirip dengan “Laravel di mana memiliki hubungan”

Pertanyaan yang mirip dengan “Laravel di mana memiliki hubungan”

Lebih banyak jawaban terkait untuk “Laravel di mana memiliki hubungan” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya