Last active
June 9, 2024 21:10
-
-
Save stas-dovgodko/a251cbe9b37b4c981ec679820ef983c0 to your computer and use it in GitHub Desktop.
Laravel test1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Post extends Model | |
{ | |
public function comments() | |
{ | |
return $this->hasOne(Comment::class); | |
} | |
} | |
class Comment extends Model | |
{ | |
public function post() | |
{ | |
return $this->belongsTo(Post::class); | |
} | |
} | |
$posts = Post::where(['type' => 1])->get(); | |
$comments = []; | |
foreach ($posts as $post) { | |
foreach ($post->comments as $comment) { | |
comments[] = $comment; | |
} | |
} | |
$post_title = Post::find(42)->title; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment