DEV Community

Cover image for Laravel 9 - Use Fake data in blade File without Create Factory
saim
saim

Posted on • Originally published at larainfo.com

Laravel 9 - Use Fake data in blade File without Create Factory

In this section, we will see how to incorporate fake data directly into Blade files without the need to create a factory file. Utilizing the fake() helper method, you can swiftly prototype designs and populate them with simulated data.

<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
    <thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
        <tr>
            <th scope="col" class="px-6 py-3">
                ID
            </th>
            <th scope="col" class="px-6 py-3">
                Name
            </th>
            <th scope="col" class="px-6 py-3">
                Email
            </th>
            <th scope="col" class="px-6 py-3">
                Edit
            </th>
            <th scope="col" class="px-6 py-3">
                Delete
            </th>
        </tr>
    </thead>
    <tbody>
        @for ($i = 0; $i < 8; $i++) 
        <tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
            <th scope="row" class="px-6 py-4 font-medium text-gray-900 dark:text-white whitespace-nowrap">
                {{ fake()->unique()->uuid() }}
            </th>
            <td class="px-6 py-4">
                {{ fake()->unique()->name() }}
            </td>
            <td class="px-6 py-4">
                {{ fake()->unique()->safeEmail() }}

            </td>
            <td class="px-6 py-4">
                <button class="p-2 text-sm text-white bg-blue-600">Edit</button>
            </td>
            <td class="px-6 py-4">
                <button class="p-2 text-sm text-white bg-red-600">Delete</button>
            </td>
        </tr>
        @endfor
    </tbody>
</table>
Enter fullscreen mode Exit fullscreen mode

laravel 9 fake data blade

Top comments (1)

Collapse
 
sreno77 profile image
Scott Reno

Why laravel 9 when 11 is the current?