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 :: if exists in string count php 
Php :: php define array first 10 number 
Php :: wordpress autoload composer 
Php :: autoloader php 
Php :: laravel blade fontawesome 
Php :: yajra laravel datatables rawcolumn 
Php :: Advanced Custom Fields get sub field image 
Php :: enum in migration laravel 
Php :: laravel with and where 
Php :: string between two strings 
Php :: laravel crud generator 
Php :: php functions parameters 
Php :: associative array in php have same value join them 
Php :: Cambiar la imagen por defecto en producto WooCommerce 
Php :: route() and with() in laravel 
Php :: laravel select where with total sum query to get all data with sum 
Php :: like %% inside the string php 
Php :: move img to public folder in laravel 
Php :: laravel collection partition 
Php :: update cart subtotal woocommerce 
Php :: laravel 8 validation unique 2 columns 
Php :: get data from csv file in php and print in table 
Php :: php insert to mysql 
Php :: Method IlluminateDatabaseEloquentCollection::delete does not exist. 
Php :: create auto image path folder in laravel 8 
Php :: display data from two dimensional array in vew laravel 
Php :: php localhost 
Php :: use php artisan command through controller 
Php :: wordpress get wp roles 
Php :: flatten in array php 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =