Im using dompf trying to generate a pdf and save it to the storage folder and a database, the problem is when i try to generate the pdf, it never load, when i use the sample code in github it work, it shows "test", but when i try to load a view it takes forever. this is the code i'm using
$pdf = PDF::loadView('emails.myView',$myData);
return $pdf->stream();
I have tried using the download and the save methods, but doens't work and the page load forever but the pdf is never generated.
and the view just show 4 or 6 elements with 1 main call $hist, returning the view is rendered without problems.
<style type="text/css">
Bunch of css.
</style>
<table class="center-block">
<tr>
<td colspan="3">
<img src="{{ asset('images/boletin/btn_cabeza.jpg') }}" class="img-responsive center-block">
</td>
</tr>
<tr>
<td rowspan="4" class="aside">
<a href="{{ URL::to('contacto/donaciones') }}">
<img src="{{ asset('images/boletin/btn_dona.jpg') }}" class="img-responsive center-block" >
</a>
<div class="social-container">
<h3>Siguenos en:</h3>
<hr>
<ul>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-instagram"></i></li>
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-youtube-play"></i></li>
</ul>
</div>
<h2 class="text-blue">Historias Epékeinas</h2>
<br>
#if(count($hist->imagenes) > 0)
<img src="{{ asset('images/news/'.$hist->imagenes->first()->image) }}" class="img-responsive img-boletin" alt="{{ $hist->titles->first()->text }}">
#endif
<div class="bg-green padding-20">
<h2 class="boletin-title">
{{ $hist->titles->first()->text }}
#if(!is_null($hist->subtitle))
{{ $hist->subtitle->titles->first()->text }}
#endif
</h2>
</div>
<hr>
<div class="text-justify">
{{ substr(strip_tags($hist->descriptions->first()->text), 0, 1600) }}[...]
<br>
Leer más
</div>
</td>
</tr>
<?php $k = 0;?>
#foreach($article as $a)
#if($k == 0 || $k%2 == 0)
<tr>
#endif
#if(!empty($principal))
#if($a->slugs->first()->text != $principal->id)
<td class="news fixedHeight bg-{{ $colors[$j] }}">
#if(count($a->imagenes) > 0)
<img src="{{ asset('images/news/'.$a->imagenes->first()->image) }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#else
<img src="{{ asset('images/logo.png') }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#endif
<h2 class="boletin-title">{{ $a->titles->first()->text }}</h2>
<p class="text-justify">{{ substr(strip_tags($a->descriptions->first()->text), 0, 300) }} [...]</p>
<a target="_blank" href="{{ URL::to('noticias/'.$a->slugs->first()->text) }}" class="btn btn-default btn-xs pull-right">Leer más</a>
<div class="clearfix"></div>
</td>
<?php $k++; ?>
#endif
#else
<td class="news fixedHeight bg-{{ $colors[$j] }}">
#if(count($a->imagenes) > 0)
<img src="{{ asset('images/news/'.$a->imagenes->first()->image) }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#else
<img src="{{ asset('images/logo.png') }}" class="img-responsive center-block img-boletin" alt="{{ $a->titles->first()->text }}">
#endif
<h2 class="boletin-title">{{ $a->titles->first()->text }}</h2>
<p class="text-justify">{{ substr(strip_tags($a->descriptions->first()->text), 0, 300) }} [...]</p>
<a target="_blank" href="{{ URL::to('noticias/'.$a->slugs->first()->text) }}" class="btn btn-default btn-xs pull-right">Leer más</a>
<div class="clearfix"></div>
</td>
<?php $k++; ?>
#endif
<?php $j++; ?>
#if($j == 4)
<?php $j=0; ?>
#endif
#if(($k != 0 && $k%2 == 0) || $k == count($article))
</tr>
#endif
#endforeach
<tr>
<td colspan="3" class="text-center">
<h3>© Derechos Reservados Funda Epékeina 2016.</h3>
</td>
</tr>
</table>
<div class="container center-block">
<div class="bg-square bg-blue"></div>
<div class="bg-square bg-yellow"></div>
<div class="bg-square bg-green"></div>
<div class="bg-square bg-pink"></div>
</div>
<div class="clearfix"></div>
what could be wrong? is there any other choice for generating pdf.
Check those points in order:
For Laravel 4.* I suggest you to use this DOMPDF wrapper https://github.com/barryvdh/laravel-dompdf/tree/0.4
Maybe your view is trying to render content out of the page, try to add dinamic page break, you can do so by styling an element with page-break-before: always; or page-break-after: always.; Try to delete the foreach and adding 1 or 2 static element rendering it in one page
Check for errors in the view by rendering it in html with return View::make('emails.myView',$myData)->render();.
Check php and html sintax, dompdf doesn't work if some html tags are
not well closed
Consider to use Knp-snappy library for Laravel https://github.com/barryvdh/laravel-snappy/tree/0.1
Related
I'm trying to create a bootstrap carousel album thumbnail.
My code is here...
<div class="col-lg-9 mb-3">
<div id="myCarousel" class="carousel slider d-flex justify-content-center" data-bs-ride="carousel">
<div class="carousel-inner">
#foreach($galleries as $gallery)
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img src="{{ asset('storage/'.$gallery->image) }}" class="img-fluid rounded" alt="{{ $product->title }}">
</div>
#endforeach
</div>
<ol class="carousel-indicators list-inline bottom-12">
#foreach($galleries as $gallery)
<li class="list-inline-item {{ $loop->first ? 'active' : '' }}">
<a id="carousel-selector-{{ $gallery->id }}" class="{{ $loop->first ? 'selected' : '' }}" data-bs-slide-to="{{ $gallery->id }}" data-bs-target="#myCarousel">
<img src="{{ asset('storage/'.$gallery->image) }}" class="img-fluid rounded" alt="{{ $product->title }}">
</a>
</li>
#endforeach
</ol>
</div>
</div>
But when I click on the carousel's indicators, I receive this error from bootstrap.min.js:
Now my question is what is wrong with my code/solution?
I am having two events in my component one is changing the layout and another one is sorting. Changing a layout basically it only replace a layout component inside a parent component. Now when i am calling a sorting then livewire giving me a error 'initialdata is null '.
I am looking for to create a sorting order with this same component. And my code is
<div class="dropdown px-2 d-none d-lg-block">
<div class=" text-dark fw-bold dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="px-1">
<img class="" src="{{ Vite::image('icons/classic.png') }}" alt="" />
</span>
<span>
<img class="" src="{{ Vite::image('icons/filter-down.png') }}" alt="" />
</span>
</div>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item text-primary #if($show == 1)text-primary #else text-dark #endif fw-bolder" href="javascript:void(0)" wire:click="$set('show', '1')">
<img src="{{ Vite::image('icons/compact.png') }}" alt="" class="ps-2" /> Card </a>
<a class="dropdown-item uni-border #if($show == 2)text-primary #else text-dark #endif fw-bolder " href="javascript:void(0)" wire:click="$set('show', '2')">
<img src="{{ Vite::image('icons/classic.png') }}" alt`your text`="" class="ps-2" />Classic </a>
<a class="dropdown-item uni-border #if($show == 3) text-primary #else text-dark #endif fw-bolder" href="javascript:void(0)" wire:click="$set('show', '3')">
<img src="{{ Vite::image('icons/com.png') }}" alt="" class="ps-2" />Compact </a>
</div>
</div>
{{-- sorting option --}}
<div class="d-flex justify-content-between pt-2 align-items-center d-none d-lg-block ">
<div class="d-flex align-items-center justify-content-between">
<div>
<span class="m-0">Selected Filters:</span>
<span class=" mx-3 boat-span2 align-items-center rounded-1">
<span>$500 </span>
<span>
<img src="{{ Vite::image('icons/cross.png') }}" alt="" class="" />
</span>
</span>
<span class=" boat-span2 align-items-center rounded-1">
<span> Skipper </span>
<span>
<img src="{{ Vite::image('icons/cross.png') }}" alt="" class="" />
</span>
</span>
</div>
<div class="">
<h6 class="m-0 text-secondary fw-500 ">
<u> Clear Filters</u>
</h6>
</div>
</div>
</div>
#if($show == 2)
{{-- classic layout --}}
#livewire('frontend.boat.listing.layout.classic',['product' => $product])
#elseif($show == 1)
{{-- card layout --}}
#livewire('frontend.boat.listing.layout.card',['product' => $product])
#elseif($show == 3)
{{-- compact layout --}}
#livewire('frontend.boat.listing.layout.compact',['product' => $product])
#endif
</div>
<?php
namespace App\Http\Livewire\Frontend\Boat\Listing;
use App\Models\Product;
use Livewire\Component;
class Listing extends Component
{
// Mount , boot , hydrate component
public $filter_option_recommend = "recommended";
public $show = "2";
// public $filter_option = "name";
// public $product;
public function detail($id, $title)
{
return redirect()->route('website.boat.detail', [$id, $title]);
}
public function render()
{
$product = Product::join('product_time_assign', 'product_time_assign.product_id', '=', 'products.id')
->where([
'products.type_id' => 1, // boat
'products.status' => 'Active',
])
->select(
'products.id as productid',
'product_time_assign.id as timeassignid',
'products.name',
'products.capacity',
'products.price_starts',
'product_time_assign.skipper',
'product_time_assign.product_time_assign_id',
'products.review_rating',
'products.image',
'products.description',
'products.discount_price'
)
->orderBy($this->filter_option_recommend, 'asc')->get();
return view('livewire.frontend.boat.listing.listing', ['product' => $product]);
}
}
ERROR: Trying to get property 'title' of non-object (View: C:\xampp\htdocs\core\resources\views\user\signal-all.blade.php)
Dear, help me please, I can't find the error, it was working fine.
signal-all.blade.php
#extends('layouts.user')
#section('content')
<div class="page-body">
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-header">
<h5>Historial - Ideas de Trading</h5>
<div class="card-header-right">
<ul class="list-unstyled card-option">
<li><i class="fa fa-chevron-left"></i></li>
<li><i class="fa fa-window-maximize full-card"></i></li>
<li><i class="fa fa-minus minimize-card"></i></li>
<li><i class="fa fa-times close-card"></i></li>
</ul>
</div>
</div>
<div class="card-block">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="sample_1">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Titulo</th>
<th>Mercado - Par - Tipo</th>
<th>TF - Estado</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
#php $p = 0 #endphp
#if (\Illuminate\Support\Facades\Auth::user()->expire_time != 1 and \Carbon\Carbon::parse(\Illuminate\Support\Facades\Auth::user()->expire_time)->isPast())
<tr>
<td colspan="7"><h6 class="text-center">Su plan esta expirado, actualice su plan Actualizar Plan</h6></td>
</tr>
#elseif (\Illuminate\Support\Facades\Auth::user()->plan_status == 0)
<tr>
<td colspan="7"><h6 class="text-center">Tablero de señales desactivado. PAGO PENDIENTE</h6></td>
</tr>
#else
#php $p = 0 #endphp
#foreach($signal as $k => $p)
<tr>
<td>{{ $k + $signal->firstItem() }}</td>
<td>{{\Carbon\Carbon::parse($p->created_at)->format('d/m/Y - h:i:s A')}}</td>
<td>{{ $p->signal->title }}</td>
<td>{{ $p->signal->asset->name }} - {{ $p->signal->symbol->name }} - {{ $p->signal->type->name }}</td>
<td>{{ $p->signal->frame->name }} - {{ $p->signal->status->name }}</td>
<td>
<i class="fa fa-eye"></i> Ver
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</div>
#if ($p)
{{$signal->links('basic.pagination')}}
#endif
</div>
</div>
</div>
</div>
</div>
#endsection
I also add layouts.user.php
#php
$planId = Auth::user()->plan_id;
$allSignal = App\SignalPlan::wherePlan_id($planId)->count();
#endphp
<div class="pcoded-main-container">
<div class="pcoded-wrapper">
<nav class="pcoded-navbar">
<div class="sidebar_toggle"><i class="icon-close icons"></i></div>
<div class="pcoded-inner-navbar main-menu">
<div class="pcoded-navigation-label">Panel de Control</div>
<ul class="pcoded-item pcoded-left-item">
<li class="{{ Request::is('user-dashboard') ? 'active' : '' }}">
<a href="{{ route('user-dashboard') }}">
<span class="pcoded-micon"><i class="ti-home"></i><b>D</b></span>
<span class="pcoded-mtext">Inicio</span>
<span class="pcoded-mcaret"></span>
</a>
</li>
</ul>
<div class="pcoded-navigation-label">Ideas de Comercio</div>
<ul class="pcoded-item pcoded-left-item">
<li class="{{ Request::is('user/all-signal') ? 'active' : '' }}">
<a href="{{ route('user-all-signal') }}">
<span class="pcoded-micon"><i class="ti-stats-up"></i><b>D</b></span>
<span class="pcoded-mtext">Señales</span>
<span class="pcoded-badge label label-primary ">{{ $allSignal }}</span>
<span class="pcoded-mcaret"></span>
</a>
</li>
</ul>
<div class="pcoded-navigation-label">Administrar Ganancias</div>
<ul class="pcoded-item pcoded-left-item">
<li class="">
<a href="{!! route('logout') !!}" onclick="event.preventDefault();document.getElementById('logout-form').submit();">
<span class="pcoded-micon"><i class="ti-share-alt"></i><b>D</b></span>
<span class="pcoded-mtext">Salir</span>
<span class="pcoded-mcaret"></span>
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</div>
</nav>
<div class="pcoded-content">
<div class="pcoded-inner-content">
<div class="main-body">
<div class="page-wrapper">
#if($errors->any())
#foreach ($errors->all() as $error)
<div class="alert alert-warning icons-alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<i class="icofont icofont-close-line-circled"></i>
</button>
<p>{!! $error !!}</p>
</div>
#endforeach
#endif
#yield('content')
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#if(Auth::user()->plan_status == 1 and Auth::user()->plan->telegram_status == 1)
{!! $basic->chat !!}
#endif
<script>
#if(Session::has('message'))
var type = "{{ Session::get('type', 'info') }}";
switch(type){
case 'info':
toastr.info("{{ Session::get('message') }}");
break;
case 'warning':
toastr.warning("{{ Session::get('message') }}");
break;
case 'success':
toastr.success("{{ Session::get('message') }}");
break;
case 'error':
toastr.error("{{ Session::get('message') }}");
break;
}
#endif
</script>
#yield('scripts')
Controller
public function AllSignal()
{
$data['page_title'] = 'All Signal';
$data['signal'] = SignalPlan::wherePlan_id(Auth::user()->plan_id)->orderBy('id','desc')->paginate(10);
return view('user.signal-all',$data);
}
when I try to execute it throws ERROR: Trying to get property 'title' of non-object
and use plan_status == 1 It works perfect
The syntax of foreach($signal as $k => $p) means, for each element in the array of $signal as a key value pair, which means $p already represents a single $signal object from the array, and $k is the array index. Within a single object of $singal, you have the property title. In order to refer to that attribute, you just need to do $p->title. If you are unsure, you could perform a dd($signal) or a dd($p) somewhere on your blade to verify what it contains
i am using laravel 5.4 ,, i use filter by serial number, i want to when the serial number is not save in database, show the allert "no data" , but when i filter data serial number is not save to database, the page is not show the allert,,
this is my blade..
#extends('layouts.master')
#section('content')
......................................
<div class="panel panel-default">
#if (!$instrumentType->instruments->isEmpty())
<table class="table">
#foreach ($instruments as $instrument)
<tr>
<td>
Serial Number : {{ $instrument->serial_number }}
#if($instrument->customer !== NULL)
<div class="text-muted"><i class="fa fa-hospital-o" aria-hidden="true"></i> {{ $instrument->customer->name }}</div>
#endif
#if($instrument->contractType !== NULL)
<div class="text-muted"><i class="fa fa-compress" aria-hidden="true"></i> {{ $instrument->contractType->name }}</div>
#endif
</td>
<td>
<div class="pull-right">
<a type="button" href="{{ route('instrument.edit', ['instrumentType' => $instrumentType->id, 'instrument' => $instrument->id]) }}"
class="btn btn-success ">
<i class="fa fa-pencil"></i> Edit
</a>
#if($instrument->customer == NULL || $instrument->contractType == NULL)
<a href="{{ route('instrument.destroy', ['instrumentType' => $instrumentType->id, 'instrument' => $instrument->id]) }}"
data-method="delete" data-confirm="" class="btn btn-danger">
<i class="fa fa-trash"></i> <span class="hidden-xs">Delete</span>
</a>
#endif
</div>
</td>
</tr>
#endforeach
</table>
<div class="paginator text-center">{{ $instruments->links() }}</div>
#else
<div class="panel-body">
<div class="alert alert-warning text-center">No data.</div>
</div>
#endif
</div>
#endsection
.
you can get count of array with :
count($instrumentType->instruments)
add this code as your statement :
#if(count($instrumentType->instruments))
//
#else
//
#endif
I want to convert my php code into vuejs2 code as I'am changing my adminpanel as vue application(only ui).
I'am following this documentation, https://v2.vuejs.org/v2/guide/conditional.html
This is my art.vue component
<template>
<div class="col-md-8">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Latest Artworks</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<div class="table-responsive">
<table class="table no-margin">
<thead>
<tr>
<th>ID</th>
<th>Art</th>
<th>Artist</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr v-for="item in art">
<td>
ART-{{ $art->.id }}
</td>
<td>{{ item.title }}</td>
<td>{{ item.artist.name }}</td>
<td>
<span class="label
<?php
if(item.status == "Pending")
echo 'label-warning';
elseif($art['status'] == "Approved")
echo 'label-success';
else
echo 'label-danger';
?>
">{{$art['status']}}</span> </td>
<td>
<div class="sparkbar" data-color="#00a65a" data-height="20"><canvas width="34" height="20" style="display: inline-block; width: 34px; height: 20px; vertical-align: top;"></canvas></div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="box-footer clearfix">
View All
</div>
</div>
</div>
</template>
<script>
export default {
computed : {
latest(){
return this.$store.state.art.latest
}
}
}
</script>
I have seen v-if condition statement, but in my case i have multiple conditions
I want to change this code
<span class="label
<?php
if($art['status'] == "Pending")
echo 'label-warning';
elseif($art['status'] == "Approved")
echo 'label-success';
else
echo 'label-danger';
?>
">{{$art['status']}}</span>
You can achieve multiple conditional views easily using v-else-ifs. Refer to the documentation here.
EDIT: Looking at the code sample it felt that there is no need for v-ifs. To add classes to an element can be done by the means of property binding.
<span class="label
<?php
if(item.status == "Pending")
echo 'label-warning';
elseif($art['status'] == "Approved")
echo 'label-success';
else
echo 'label-danger';
?>
">{{$art['status']}}</span>
can be written like:
<span :class='{label: true, "Pending": item.status === 'value', "label-warning": item.status === 'someOtherValue'}'>{{$art['status']}}</span>
in vuejs for the same effect, read more.
<span v-if="item.status === 'Pending'" class="label label-warning">
{{ item.status }}
</span>
<span v-else-if="item.status === 'Approved'" class="label label-success">
{{ item.status }}
</span>
<span v-else class="label label-danger">
{{ item.status }}
</span>
This solved my issue