Laravel include a template with dynamic value - laravel

I want to include a template dynamically eg: #include('{{ site('theme') }}.header')
but this throws up an error, how can I do this? (If I output {{ site('theme') }} this holds a value of test).
Thanks in advance.

Just write it like php code.
#include(site('theme').'.header')

Use this:
#include(site('theme') . '.header')

Related

Acessing property from blade view laravel

Im trying to show some data in my view and ONLY the id property is getting changed to some random number when its passed to the view. The other properties are okay.
If I try to access a property from a view like this: {{ dd($var[1]) }}, it works and I can see the id like this:
But if I try to access passing the id directly: {{ dd($var[1]['id']) }} or {{ dd($var[1]->id) }}, I just get this:
And here are some more examples from what I get accessing it directly:
If I use gettype() is this var I get Integer back, but it is actually a string as you can see in the first printscreen.
Why is my blade view doing this? And how can I fix it?
I ended up using another id I was receiving in the same array, looks like blade was decoding the string or something like that. Thanks for the answers.
in your controller please select id as new_id and try to print
$var[1]->new_id or $var[1]['new_id']
it will fix your problem
if fixed give a green tick and a thumbs up else leave a commetn will try to update you

laravel - #if won't accept database variable

How can I solve this? I've tried anything but I still can't compare the uuid from the database with a local id I created.
you don't need to use {{}}, as they internally render to echo().
The comparison is just:
#foreach($tasks as $task)
#if($task->uuid == $id)
You don't need to use {{}} in controll statements of blade temple. {{}} Is used while rendering any variable on the views.

Laravel - Public_Path is Returned as Local System Path

I have an odd issue but I believe could be readily changed with a configuration I might not know about.
So if I want to access the path of an attachment I use the following code in my blade:
{{ $volunteer->photoID->attachment}}
Which returns me this:
public/volunteers/tgjW0GOQTzSEjG7F5Wlq0G9mEdGJ7fE7TLxpKRyn.jpg
But I am trying to put the image inside of a pdf, and because of the loading requirements, I am having to format the return in the blade as such:
{{ public_path($volunteer->photoID->attachment)}}
The problem is this returns:
E:\webserver\htdocs\hopin\public\public/volunteers/tgjW0GOQTzSEjG7F5Wlq0G9mEdGJ7fE7TLxpKRyn.jpg
Which isn't usable in the img element. So is there something I am doing wrong? Or is there a better way of creating the usable path?
Try using realpath when outputting the attachment:
{{ realpath(public_path($volunteer->photoID->attachment)) }}

How to include blade tempate in another file?

I have two fiels:
landing.blade.php
And block comments.blade.php.
How can I include comments.blade.php inside landing.blade.php?
You can include one blade template into other by following syntax:
Including Sub-Views
#include('view.name')
You may also pass an array of data to the included view:
#include('view.name', array('some'=>'data'))
For more details you can follow:
https://laravel.com/docs/5.0/templates
Thanks
According to the documentation you need to #include it:
landing.blade.php:
<div>
Some content
#include('comments', ['comments' => $comments])
</div>
simple way,
if landing.blade.php and comments.blade.php are on the same directory, let's assume they are both on ressource/view
So on landing.blade.php you can write #include('comments')

How to extend layout based on database

I want to extend a layout which the folder name is retrived from database. Bellow is the code.
#extends('layout.'.{{ $layout->layout}}.'.main')
But it is not working, what is the logic behind getting layout name from database? Please let me know.
you don't need the blade brackets {{ }}. The brackets are short for
#extends('layout.' . $layout->layout . '.main')
I didn't test it but it should work.

Resources