i am trying to loop over blade component by passing an array data. it successfully compiled but it is not showing up in the browser and also not giving an error
here is card.blade.php file
<div>
<h1>{{$name}}</h1>
<h2>{{$age}}</h2>
<h3>{{$work}}</h3>
</div>
here is main file view file
#php
$arr = [
['name'=>'1','age'=>'2','work'=>'3'],
['name'=>'4','age'=>'5','work'=>'6']
];
#endphp
#foreach ($arr as $de)
<x-card :name={{$de['name']}} :age={{$de['age']}} :work={{$de['work']}}/>
#endforeach
it also shows attached data when i click view source file
<x-card :name=1 :age=2 :work=3/>
<x-card :name=4 :age=5 :work=6/>
but i is not showing up in the browser, browser is blank
You just need to delete {{}} syntax from the attributes
<x-card :name="$de['name']" :age="$de['age']" :work="$de['work']"/>
for more info check the Component-Attributes from the docs
Related
I'm facing a problem i don't really understand it. I'm using Laravel 8 jobs to save my blade view as an html page in my public folder. In my main view I have to load another view and pass it a path to the image which stored in the public folder as follows:
#php
$path = $book->image;
//dd($path)
#endphp
#component('report/sales', ['path' => $path])
#endcomponent
the $path variable here contains something like
http://localhost/myapp/src/public/images/books/xyz.jpg In this view if i do dd($path) I get the http://localhost/myapp/src/public/images/books/xyz.jpg as expected. Now in sales view I do this:
<img src= "{{ asset("/" . $path) }}" alt="some text" width="50%">
Now in the produced html file the image is not loaded and src property has the value http://localhost/myapp/src/public The strange thing is that when I don't use jobs the html file has this picture. Another weird thing, if I hardcode the value of the variable $path in my main view as:
#php
$path = "http://localhost/myapp/src/public/images/books/xyz.jpg";
#endphp
#component('report/sales', ['path' => $path])
#endcomponent
And I use it with jobs the html file is produced with the picture and everything is fine. Could somebody please help me to understand? Thanks.
There is a feature on a Laravel/ PHP site I'm working on that allows a user to download a payment reminder letter as a PDF file- the PDF is generated based on properties belonging to the database entry that they choose to download the PDF for.
The reminder.blade.php file that is generated for the download originally looked like this:
<html>
<head>
...
</head>
<body style="....">
#foreach ($transaction as $transaction)
...
<!-- Content of the PDF here -->
#endforeach
</body>
I want to change what the PDF displays based on the number/type of transactionItems in the $transaction that is being exported to the PDF- if there is only one transactionItem in the $transaction with a $transactionItem.currentStatusId property value of 1010 (an ID of a particular value of the $transactionItem.currentStatusId field, only the first page of the PDF should be generated, otherwise, all pages should be generated (as they currently are)
To do this, I have tried to surround the <body></body> tags with an #if that checks the number of transactionItems in the $transaction that's being exported, and set the content of the PDF appropriately within each of the #if & #else statement, so the changes I made to the reminder.blade.php file mean it currently looks like this:
<html>
<head>
...
</head>
#if(($transaction->count($transaction['transactionItem']) == 1) && ($transaction['transactionItem']['currentStatusId'] == '1010'))
<body style="....">
#foreach ($transaction as $transaction)
...
<!-- First page of PDF only -->
#endforeach
</body>
#else
<body style="...">
#foreach ($transaction as $transaction)
...
<!-- Original PDF here -->
#endforeach
</body>
#endif
</html>
However, when I now export the PDF file, although the file downloads successfully, when I try to open it, I get an error that says:
Failed to load PDF document.
Anyone have any idea why I might be getting this? I assume there's something I'm doing wrong with the #if statement I'm using to generate the content dynamically, but I can't see what... Can anyone point me in the right direction? How can I alter the content of the PDF generated based on the value of a field in the database, which is being used to generate the PDF?
I have the site with the structure like:
First: master.blade.php : this contain section('content')
<body>
#include('partial.header')
#yield('content')
#include('partial.footer')
</body>
Second index.blade.php : contain section('content').
#extends('layouts.master')
#section('content')
<div id="container">
<div id="news">
#yield('news')
</div>
<div id="apartment">
#yield('apartment')
</div>
</div> <!-- ./container -->
#endsection
Third: news.blade.php : this simple to show all news
#foreach($posts as $post)
#endforeach
Final file: apartment.blade.php : this simple to show all apartment.
#foreach($apartments as $apartment)
#endforeach
My route direct to master.blade.php.
My question is:
When I include news with #yield('news') in index.blade.php. It shows correct all news in my database.
But when I delete #yield('news') in index.blade.php. It also show news from my database (but it's lost css/js for that).
Why I deleted #yield('news'), it's should don't show any news on my page?
Seem Laravel Blade not support two #yield in #section. When I add only 1 row #yield('news') into index.blade.php file. It shows list news on my index page. When I continues add #yield('apartment'). Don't have any apartment shown on the index page. I certainly it has values when foreach to get data. I also test with HTML statics but don't have anything changes.
My route direct to master.blade.php.
Index extends master, so point your route to index view.
If sections continue to be yielded, after #yield removal, I think the framework is loading a cached view.
Try clearing the view cache php artisan view:clear or use php artisan --help view:clear for help.
Also #yield yields a section in a parent child relationship.
Change yields to include like #include('partial.news') if news are in partial folder or to whatever the path. Rendering could be manipulated using #isset or #empty statements or even #forelse loops.
Blade Control Structures.
I have a header.blade.php in an includes folder, this header page is the whole webpage base. i have links on it and i have the header of the website which is included in all other web pages.
The heading part i want to retrive just the first line of the table result in it so the admin can update that line whenever possible.
The thing is that it is hard to figure out a route to give to it as it is a partial page.
The code on it is:
<div class="site-heading" data-webid="{{ $web_header->id }}>
<h1>{{ $web_header->header }}</h1>
<hr class="small">
<span class="subheading">{{ $web_header->slogan }}</span>
</div>
My home controller has the following code to display in the information on the header partial page:
public function showWebHeader()
{
$web_header = WebHeader::all()->first();
return view('include/header', [
'web_header' => $web_header
]);
}
I am lost and confused here because I keep getting undefined variable on every single page I have on my web system.
I am using laravel 5 and I have a blade templated page but {{}} doesn't work. It skips it and doesn't echo the value in it. For example. this code
<h2>Delete {{$employe->fname }} Are you sure?</h2>
Its output:
Delete are you sure?
with out the name of employee how can I fix this
the file is saved in blade extention delete.blade.php