Laravel blade template inheritance vs Laravel component [closed]
Asked Answered
B

0

6

I'm wondering if it is worth moving from this code.

@extends('layouts.app')
 
@section('title', 'Page Title')
 
@section('content')
    @foreach ($tasks as $task)
        {{ $task }}
    @endforeach
@endsection

To this one.

<x-layout>
    <x-slot:title>
        Custom Title
    </x-slot>
 
    @foreach ($tasks as $task)
        {{ $task }}
    @endforeach
</x-layout>

I mean is it better to use Laravel components instead of just using @extend, @yeild, and @section etc..

Bechtold answered 3/3, 2022 at 12:11 Comment(5)
for @foreach you are still following blade pattern which is inconsistent to the vue template. so, IMO it's not wise now to move it from blade to vue. when all the directives are available in vue component, you can slowly migrate to those.Reduced
Thank you for replying first. but, Actually I'm not using vue and I don't know about it even. my question is about laravel component which was introduce in laravel 7Bechtold
But you should stick to single type of code. It's good to have consistent quality code. either switch to blade-x or blade. but check which one has all the directives. so, you don't have to mix-up stuffs between themReduced
yeah, but just to ensure that I got you right. you're saying that it doesn't matter which one I choose but don't mix between them... one last thing, you sad 'but check which one has all the directives' what does this meansBechtold
blade templates is pretty old and has all the required and handy directives (the @functions()) but for blade-x, i dont think all the directives are available as it's quite recent (<x-directives>) and also, blade-x is not supported for type hinting and code suggestions in most of the IDEsReduced

© 2022 - 2024 — McMap. All rights reserved.