Home > Enterprise >  Laravel 9 make html table into a blade component
Laravel 9 make html table into a blade component

Time:11-24

I want to make this simple table into a blade component. here is my code so far:

            <table >
                <thead>
                    <tr>
                        <th>User ID</th>
                        <th>Full name</th>
                        <th>Email address</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($users as $user)
                        <x-user-row :user="$user" />
                    @endforeach
                </tbody>
            </table>

the component code (user-row.blade.php):

@props(['user'])
    <tr>
        <td"><a href="{{url('user', [$user->id]);}}">{{ $user->id}}</a></td>
        <td">{{ $user->name}}</td>
        <td">{{ $user->email}}</td>
    </tr>

and the output is this :

output image

I can't figure out why the data displays first before the table tag. I am completely new to this Laravel framework. Any help will be very much appreciated. Thanks

CodePudding user response:

Looks like you are adding " inside td, please use this instead, and let me know:

<tr>
        <td><a href="{{url('user', [$user->id])}}">{{ $user->id}}</a></td>
        <td>{{ $user->name}}</td>
        <td>{{ $user->email}}</td>
</tr>
  • Related