public function districts(){ return $this->hasMany(District::class); } public function user(){ return $this->belongsTo(User::class); } public function users(){ return $this->belongsToMany(User::class,'roles_devisions','area_id' ,'user_id'); } public function products(){ return $this->belongsToMany(Product::class, 'finished_products','packaging_id','product_id')->withPivot('quantity'); } class Clash extends Model { use HasFactory; public function subject(){ return $this->belongsTo(Subject::class); } public static function totalClashs(){ $clashs = Clash::select('*') ->orderBy('id', 'DESC') ->get(); return $clashs; } } @foreach(App\Models\Clash::totalClashs() as $clash)
{{$clash->title}}
{{$clash->subject->title}}
@endforeach use Illuminate\Database\Eloquent\Profile; class Profile extends Model { protected $fillable = [ 'name', 'image', ]; protected $table = 'profile'; public function setHobbyAttribute($value) { $this->attributes['hobby'] = json_encode($value); } public function getHobbyAttribute($value) { return $this->attributes['hobby'] = json_decode($value); } public function user(){ return $this->hasOne(User::class); } } hasOne|hasMany|belongsTo Resource public function toArray($request) { return [ 'id' => $this->id, 'title' => $this->title, 'author' => $this->author, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; } DATABASE 1000 BYTE PROBLEM config.database.php 'mysql' => [ 'engine' => 'InnoDB ROW_FORMAT=DYNAMIC', ]