Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel has many

 public function comments()
 {
   return $this->hasMany(Comment::class);
 }
Comment

laravel has many

<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;

class Post extends Model
{
    /**
     * Get the comments for the blog post.
     */
    public function comments()
    {
        return $this->hasMany('AppModelsComment');
    }
}
Comment

laravel has many with ids

class Post extends Model
{
  public function comments()
  {
  	return $this->hasMany(Comment::class, 'foreign_key', 'local_key');
 // local id is the main id Of post table such as : id
 // foreign id is the post table which is inside comment table such as: post_id
    //return $this->hasMany(Comment::class, 'post_id', 'id');  
    //return $this->hasMany(Comment::class, 'post_id'); 


  }
}
Comment

PREVIOUS NEXT
Code Example
Php :: merge array in php 
Php :: round to 0.5 php 
Php :: php list *files 
Php :: alias to change php version on ubuntu 
Php :: php pdo 
Php :: sort php 
Php :: Displaying Custom Navigation Menus in WordPress Themes 
Php :: acf looping through post types 
Php :: enable extensions in php.ini 
Php :: laravel multiple copy record 
Php :: find object in array php 
Php :: wp_customize image 
Php :: php extract number from string without comma 
Php :: php, Africa timezones 
Php :: Write a php program to print hello world 
Php :: signup api in laravel 
Php :: header() php 
Php :: drop foreign key laravel eloquent 
Php :: laravel relationship delete all 
Php :: how to create php message 3 
Php :: laravel PageController.php 
Php :: api resource create in laravel 
Php :: defining constant in config laravel 
Php :: how to loop by index in php 
Php :: laravel vreeze 
Php :: command to create middleware in laravel 
Php :: codeigniter 3 image upload 
Php :: sha256 php cantidad caracteres 
Php :: wp php blog info image 
Php :: PHP OOP - Destructor 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =