TimeParadox
TimeParadox

Reputation: 318

Laravel when should I extend or include or write double code?

I'm working on a Laravel application and in the view I have a few lines of code that I need in multiple views. So is it better to extend or include this in a layout or should I write the code multiple times?

the codes that I need to include are:

    <meta name="csrf-token" content="{{ csrf_token() }}">
    <script type="text/javascript" src="/js/app.js"></script>
    <link rel="stylesheet" href="/css/app.css">

and a few more meta tags and texts.

So what is the best way to do it performance wise and Laravel structure wise?

Upvotes: 0

Views: 52

Answers (2)

Dino Numić
Dino Numić

Reputation: 1452

How I usually handle this. I would create a head.blade.php file and put styles, scripts, meta tags, etc. Then I would include it into my layout.

In app.blade.php I would do @include('frontend.includes.head')

For the rest of the view files, I would extend the app layout.

@extends('frontend.layouts.app')
...

Upvotes: 1

Pavel Lint
Pavel Lint

Reputation: 3527

These lines usually go to the layout

Upvotes: 2

Related Questions