laravel task

 <?php

class Car extends Model { } class Color extends Model { } $vehicleColors = Car::find(5)->colors(); ?>

what find prints

write a relation ship[

// Car.php use Illuminate\Database\Eloquent\Model; class Car extends Model { public function colors() { return $this->hasMany(Color::class); } } // Color.php use Illuminate\Database\Eloquent\Model; class Color extends Model { public function car() { return $this->belongsTo(Car::class); } }


// Retrieve a car with id 5 and eager load its colors $car = Car::with('colors')->find(5); // Access the colors related to the car $vehicleColors = $car->colors;



No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...