<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class Post extends Model
{
/**
* Get the comments for the blog post.
*/
public function comments()
{
return $this->hasMany(Comment::class);
//return $this->hasMany(Comment::class, 'foreign_key');
//return $this->hasMany(Comment::class, 'foreign_key', 'local_key');
}
}
// Other
use AppModelsPost;
$comments = Post::find(1)->comments;
foreach ($comments as $comment) {
//
}
// Other
$comment = Post::find(1)->comments()
->where('title', 'foo')
->first();
Code Example |
---|
Php :: php array_walk |
Php :: php artisan route list does not show all my routes |
Php :: wpml get site url |
Php :: php array pop by value |
Php :: filesize in php |
Php :: php sprintf |
Php :: append data in csv file php |
Php :: get google map api |
Php :: contact form 7 checkbox2 |
Php :: json to html php table |
Php :: wordpress custom post type query |
Php :: header php location |
Php :: __invoke in laravel |
Php :: carbon create from format |
Php :: Converting timestamp to time ago in PHP |
Php :: post loop |
Php :: composer autoload |
Php :: get date after 1 dayphp |
Php :: excerpt with Laravel |
Php :: how to send mail in laravel |
Php :: ci constructor |
Php :: all resource routes laravel 8 |
Php :: php append n time pattern to string |
Php :: laravel collection times |
Php :: seprate day and year from laravel to timestamp |
Php :: datatable filters |
Php :: use smarty variable in php |
Php :: connect rabbitMQ |
Php :: laravel hash |
Php :: laravel simplexmlelement not found |