Horje
Laravel 8 Factory - One To Many (Polymorphic) Relationship Code Example
Laravel 8 Factory - One To Many (Polymorphic) Relationship
<?php

namespace Database\Factories;

use App\Models\Comment;
use App\Models\Post;
use App\Models\Video;
use Illuminate\Database\Eloquent\Factories\Factory;

class CommentFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Comment::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        $commentable = $this->commentable();

        return [
            'body' => $this->faker->paragraph,
            'commentable_id' => $commentable::factory(),
            'commentable_type' => $commentable,
        ];
    }

    public function commentable()
    {
        return $this->faker->randomElement([
            Post::class,
            Video::class,
        ]);
    }
}




Php

Related
order by pre get posts Code Example order by pre get posts Code Example
Add text below product title on archive page + ACF Code Example Add text below product title on archive page + ACF Code Example
pagenavi plugin Code Example pagenavi plugin Code Example
shopware redirect ot homepage Code Example shopware redirect ot homepage Code Example
afosto/yaac error parsing certificate request Code Example afosto/yaac error parsing certificate request Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9