dompdf laravel on live server, can't download pdf and return error 500 - laravel

I hosted my Laravel Project to 000webhost, my project can make report in pdf format. I use dompdf to do all pdf things. When in my localhost server (xampp), dompdf works fine with no error and rendering html very well. In live server i got error 500 "Whoops, something went wrong on our servers.". I can't find any solution, i thought it was execution time, i rise it to 2000 seconds still got 500.
here is my controller
public function retur_preport(Request $request)
{
ini_set('max_execution_time', '2000');
ini_set('memory_limit','512M');
$tgl1 = date('Y-m-d', strtotime($request->input('tanggal_mulai')));
$tgl2 = date('Y-m-d', strtotime($request->input('sampai_tanggal')));
if($tgl1 > date('Y-m-d') || $tgl2 > date('Y-m-d')){
return redirect('upper/laporan/retur')->with('error','Tanggal yang diinput tidak bisa lebih besar dari '.date('d M Y').' (hari ini)');
}elseif($tgl2 != '1970-01-01' && $tgl1 > $tgl2){
return redirect('upper/laporan/retur')->with('error','Tanggal mulai tidak bisa lebih besar dari inputan tanggal sampai');
}elseif($tgl1 == '1970-01-01' && $tgl2 == '1970-01-01'){
return redirect('upper/laporan/retur')->with('error','Salah satu dari kedua tanggal harus diisi');
}elseif($tgl1 == '1970-01-01'){
$r = \App\Retur::whereDate('tgl_retur',$tgl2)->orderBy('tgl_retur','desc')->get();
$pdf = PDF::loadview('pimpinan/laporan/retur/report', compact('r','tgl1','tgl2'))->setPaper('a4','landscape');
return $pdf->download('laporan retur tanggal '.date('d-M-Y', strtotime($tgl2)).'.pdf');
}elseif($tgl2 == '1970-01-01'){
$r = \App\Retur::whereBetween('tgl_retur',[$tgl1, date('Y-m-d')])->orderBy('tgl_retur','desc')->get();
$pdf = PDF::loadview('pimpinan/laporan/retur/report',compact('r','tgl1','tgl2'))->setPaper('a4','landscape');
return $pdf->download('laporan retur tanggal '.date('d-M-Y', strtotime($tgl1)).' sampai tanggal '.date('d-M-Y').'.pdf');
}else{
$r = \App\Retur::whereBetween('tgl_retur',[$tgl1,$tgl2])->orderBy('tgl_retur','desc')->get();
$pdf = PDF::loadview('pimpinan/laporan/retur/report', compact('r','tgl1','tgl2'))->setPaper('a4','landscape');
return $pdf->download('laporan retur tanggal '.date('d-M-Y', strtotime($tgl1)).' sampai tanggal '.date('d-M-Y', strtotime($tgl2)).'.pdf');
}
}
and here is my html that rendered from controller
<html>
<head>
<link rel="stylesheet" href="{{ asset('assets') }}/bower_components/bootstrap/dist/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="{{ asset('assets') }}/bower_components/font-awesome/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="{{ asset('assets') }}/bower_components/Ionicons/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="{{ asset('assets') }}/dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="{{ asset('assets') }}/dist/css/skins/_all-skins.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
<style>
.no-gutters {
margin-right: 0;
margin-left: 0;
> .col,
> [class*="col-"] {
padding-right: 0;
padding-left: 0;
}
}
table, td, th, tr, thead, tbody {
border: 1px solid black !important;
}
</style>
</head>
<body>
<div class="content-header row text-center">
<img src="{{ asset('uploads') }}/kadatuan_logo/logo.jpg" width="120" height="120"><br>
Jl. Karawitan No. 48, Bandung
</div>
<section class="content">
<div class="box box-primary box-solid">
<div class="box-header">
Laporan Retur
#if($tgl1 == '1970-01-01')
Tanggal <strong>{{ date('d-M-Y', strtotime($tgl2)) }}</strong>
#elseif($tgl2 == '1970-01-01')
Tanggal <strong>{{ date('d-M-Y', strtotime($tgl1)) }}</strong> Sampai <strong>{{ date('d-M-Y') }}</strong>
#else
Tanggal <strong>{{ date('d-M-Y', strtotime($tgl1)) }}</strong> Sampai <strong>{{ date('d-M-Y', strtotime($tgl2)) }}</strong>
#endif
<div class="pull-right">Dicetak pada tanggal <strong>{{ date('d-M-Y') }}</strong></div>
</div>
<div class="box-body">
<div class="d-flex justify-content-center">
<table class="table text-center">
<thead>
<tr>
<th>No</th>
<th>ID Pemesanan</th>
<th>ID Retur</th>
<th>Tanggal Retur</th>
<th>Nama Mitra</th>
<th>Barang Retur</th>
<th>Jumlah Retur</th>
<th>Status Retur</th>
<th>Keterangan</th>
</tr>
</thead>
<tbody>
#foreach ($r as $row)
<tr>
<td rowspan="{{ \App\DRetur::where('id_retur',$row->id_retur)->count() }}">{{ !empty($i) ? ++$i : $i = 1}}</td>
<td rowspan="{{ \App\DRetur::where('id_retur',$row->id_retur)->count() }}">{{ $row->id_pemesanan }}</td>
<td rowspan="{{ \App\DRetur::where('id_retur',$row->id_retur)->count() }}">{{ $row->id_retur }}</td>
<td rowspan="{{ \App\DRetur::where('id_retur',$row->id_retur)->count() }}">{{ date('d-M-Y', strtotime($row->tgl_retur)) }}</td>
<td rowspan="{{ \App\DRetur::where('id_retur',$row->id_retur)->count() }}">{{ $row->mitra->nama_mitra }}</td>
#foreach (\App\DRetur::where('id_retur',$row->id_retur)->limit(1)->get() as $row2)
<td>{{ \App\TPemesanan::join('t_dpemesanan','t_tpemesanan.id_dpemesanan','=','t_dpemesanan.id_dpemesanan')->join('t_stock','t_dpemesanan.id_stock','=','t_stock.id_stock')->where('t_tpemesanan.id_tpemesanan',$row2->id_tpemesanan)->first()->nama_stock }}</td>
<td>{{ $row2->jumlah_dretur }}{{ \App\TPemesanan::join('t_dpemesanan','t_tpemesanan.id_dpemesanan','=','t_dpemesanan.id_dpemesanan')->join('t_stock','t_dpemesanan.id_stock','=','t_stock.id_stock')->where('t_tpemesanan.id_tpemesanan',$row2->id_tpemesanan)->first()->satuan }}</td>
#if( $row2->status_dretur == 1 )
<td>Menunggu Diperiksa</td>
#elseif( $row2->status_dretur == 2 )
<td>Diterima</td>
#elseif( $row2->status_dretur == 3 )
<td>Ditolak</td>
#endif
<td>{{ $row2->keterangan }}</td>
</tr>
#foreach(\App\DRetur::where('id_retur',$row->id_retur)->get() as $row3)
#if($row2->id_dretur != $row3->id_dretur)
<tr>
<td>{{ \App\TPemesanan::join('t_dpemesanan','t_tpemesanan.id_dpemesanan','=','t_dpemesanan.id_dpemesanan')->join('t_stock','t_dpemesanan.id_stock','=','t_stock.id_stock')->where('t_tpemesanan.id_tpemesanan',$row3->id_tpemesanan)->first()->nama_stock }}</td>
<td>{{ $row3->jumlah_dretur }}{{ $row2->jumlah_dretur }}{{ \App\TPemesanan::join('t_dpemesanan','t_tpemesanan.id_dpemesanan','=','t_dpemesanan.id_dpemesanan')->join('t_stock','t_dpemesanan.id_stock','=','t_stock.id_stock')->where('t_tpemesanan.id_tpemesanan',$row3->id_tpemesanan)->first()->satuan }}</td>
#if( $row3->status_dretur == 1 )
<td>Menunggu Diperiksa</td>
#elseif( $row3->status_dretur == 2 )
<td>Diterima</td>
#elseif( $row3->status_dretur == 3 )
<td>Ditolak</td>
#endif
<td>{{ $row3->keterangan }}</td>
</tr>
#endif
#endforeach
#endforeach
#endforeach
</tbody>
</table>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
Sistem Informasi Supply
<div class="pull-right">
Hormat Saya, <strong>Reyhan (Admin)</strong>
</div>
</div>
<!-- /.box-footer-->
</div>
<!-- /.box -->
</section>
<!-- jQuery 3 -->
<script src="{{ asset('assets') }}/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="{{ asset('assets') }}/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="{{ asset('assets') }}/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="{{ asset('assets') }}/bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="{{ asset('assets') }}/dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="{{ asset('assets') }}/dist/js/demo.js"></script>
<script>
$(document).ready(function () {
$('.sidebar-menu').tree()
})
</script>

Related

search function for laravel 5.8

guys somehow this search function not working.i been following a tutorial for search function in laravel 5.8 can you help me im still a total beginner at this. if i ask this question wrong please forgive me.. this is my first time asking... and if im being rude im truly sorry...
pegawaicontroller.php
public function search(Request $request)
{
// menangkap data pencarian
$search = $request->search;
// mengambil data dari table pegawai sesuai pencarian data
$pegawai = DB::table('pegawais')
->where('nama_pegawai','LIKE',"%".$search."%")
->paginate();
// mengirim data pegawai ke view index
return view('pegawai.index',['pegawais' => $pegawai]);
}
pegawai.php (Model)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Pegawai extends Model
{
protected $fillable = ['kategori', 'jabatan', 'nama_pegawai', 'alamat', 'gambar_pegawai', ];
}
index.blade.php
#extends('template.adminlte')
#section('content')
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Menu Pegawai</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active">pegawai</li>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<form action="/pegawai/search" method="GET">
<input type="text" name="search" placeholder="Cari Pegawai .." value="{{ old('search') }}">
<input type="submit" value="Search">
</form>
<section class="content">
<div class="container-fluid">
<a href="{{ route('pegawai.create') }}" class="btn btn-info btnsm float-right">
<i class="fas fa-plus-circle"> Tambah Menu</i>
</a><br><br>
#if ($message = Session::get('message'))
<div class="alert alert-success martop-sm">
<p>{{ $message }}</p>
</div>
#endif
<table class="table martop-sm">
<thead>
<th>No</th>
<!-- <th>ID</th> -->
<th>Kategori</th>
<th>Jabatan Pegawai</th>
<th>Nama pegawai</th>
<th>Alamat</th>
<th>Foto Pegawai</th>
<th>Aksi</th>
</thead>
<tbody>
#foreach ($pegawais as $key => $pegawai)
<tr>
<td>{{ $pegawais->firstItem() + $key }}</td>
<!-- <td>{{ $pegawai->id }}</td> -->
<td>{{ $pegawai->kategori }}</td>
<td>{{ $pegawai->jabatan }}</td>
<td>{{ $pegawai->nama_pegawai }}</td>
<td>{{ $pegawai->alamat }}</td>
<td><img src="{{ asset('storage/images/' . $pegawai->gambar_pegawai) }}" alt="" width="100"></td>
<td>
<form action="{{ route('pegawai.destroy', $pegawai->id) }}" method="post">
{{csrf_field()}} {{ method_field('DELETE') }}
Ubah
<button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Apakah anda yakin ingin menghapusnya?');">Hapus</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
{{ $pegawais -> links() }}
</div>
</section>
</div>
#endsection
web.php (my route)
Route::get('/pegawai')->name('pegawai.index')->uses('pegawaicontroller#index');
Route::get('/pegawai/search')->uses('pegawaicontroller#search');
Expectation:
Function Working As Intended
Reality:
404 PAGE NOT FOUND

#yield working on home page, but not on other pages using same layout

Really scratching my head on this one. I'm hoping a fresh pair of eyes can spot my error.
I've got a section heading on each page, but the heading is only showing on home.blade.php but not other pages.
master.blade.php
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="csrf-token" content="{{ csrf_token() }}" />
<title>#yield('title')</title>
#stack('styles')
</head>
<body class="bg-light">
<div class="container-fluid h-100">
#yield('app')
</div>
#include('sweetalert::alert')
{{ Session::forget('alert') }}
#stack('scripts')
</body>
</html>
app.blade.php
#extends('layout.master')
#prepend('styles')
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<link rel="stylesheet" type="text/css" href="{{ URL::asset('css/overrides.css') }}" />
#endprepend
#section('app')
<div class="row">
<div class="col-12 no-padding">
#include('layout.includes.header')
</div>
</div>
<div class="row h-100">
<div class="col-12">
<!-- Begin nav/content row -->
<div class="row h-100">
<div id="sidebar-wrapper" class="visible">
#include('layout.includes.nav')
</div>
<!-- Begin main column -->
<div class="col content" style="overflow-x:auto;">
#if (Request::path() === '/')
<div class="row no-padding">
<div class="col d-none d-sm-block">
<h4>#yield('content-heading')</h4> <!-- [my #yield directive is here] -->
</div>
<div class="col flex-grow-1">
#include('layout.includes.searchform')
</div>
</div>
#endif
<div class="row no-padding inner-box shadow p-3 mb-5 bg-white rounded">
#yield('content')
</div>
</div>
<!-- END main column-->
</div>
<!-- END nav/content row-->
</div>
</div>
#endsection
#prepend('scripts')
#include('layout.js.footer-js')
#yield('form-js')
#endprepend
home.blade.php
#extends('layout.app')
#section('title', 'Asset Management')
#section('content-heading', 'View All Assets') //This works
#section('content')
<div class="table-responsive">
<table class="table table-striped text-nowrap">
<caption>Recently Added Assets</caption>
<thead>
<tr>
<th scope="col">Tag #</th>
<th scope="col">Type</th>
<th scope="col">Device</th>
<th scope="col">Serial #</th>
<th scope="col">Assigned</th>
<th scope="col">To</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
#foreach ($assets as $asset)
<tr>
<td>{{ $asset->asset_tag }}</td>
<td>{{ $asset->cat_name }}</td>
<td>{{ $asset->man_name }} {{ $asset->model_name }}</td>
<td>{{ $asset->serial }}</span></td>
<td>{{ \Carbon\Carbon::parse($asset->assign_date)->format('D M d, Y g:iA') }}</td>
<td>{{ $asset->name }}</td>
<td>{{ $asset->status }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endsection
#section('form-js')
#endsection
#push('scripts')
#endpush
My other pages are all laid out the same as home.blade.php, e.g:
#extends('layout.app')
#section('title', 'Checkout Asset')
#section('content-heading', 'Checkout Asset') //Does not output to template
#section('content')
Content here...
#endsection
#push('scripts')
#endpush
Why is <h4>#yield('content-heading')</h4> only working on home.blade.php?
The code which displays #yield('content-heading') is wrapped in:
#if (Request::path() === '/')
...
#endif
which is restricting the display to just that url.
:)

Dompf load forever laravel 4.2

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

Import data into database and show it on html table in laravel

I want to create a view in laravel that has a function to import an excel file into the database and show it in a table inside a view.
I created a controller and it imports the excel data in database but fails to show it in view.
Please Help solve my issue.
Many Thanks in advance.
Best Regards,
Dian
I am using laravel 5.5 and maatwebsite excel
public function importFileIntoDB(Request $request){
if($request->hasFile('sample_file')){
$path = $request->file('sample_file')->getRealPath();
$data = Excel::load($path, function($reader) {})->get();
if($data->count()){
foreach ($data as $key => $value) {
$arr[] = ['name' => $value->name, 'details' => $value->details];
}
if(!empty($arr)){
\DB::table('products')->insert($arr);
dd('Insert Record successfully.');
}
}
}
return back()->with($arr);
}
this is my view
#extends('frontpage')
#section('title', 'Dashboard')
#section('content_header')
<h1>Upload File From Excel Into Database</h1>
#stop
#section('content')
<div class="panel panel-primary">
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title" style="padding:12px 0px;font-size:25px;"><strong>Test - import export csv or excel file into database example</strong></h3>
</div>
<div class="panel-body">
#if ($message = Session::get('success'))
<div class="alert alert-success" role="alert">
{{ Session::get('success') }}
</div>
#endif
#if ($message = Session::get('error'))
<div class="alert alert-danger" role="alert">
{{ Session::get('error') }}
</div>
#endif
<h3>Import File Form:</h3>
<form style="border: 4px solid #a1a1a1;margin-top: 15px;padding: 20px;" action="{{ URL::to('importExcel') }}" class="form-horizontal" method="post" enctype="multipart/form-data">
<input type="file" name="import_file" />
{{ csrf_field() }}
<br/>
<button class="btn btn-primary">Import CSV or Excel File</button>
</form>
<br/>
<h3>Import File From Database:</h3>
<div style="border: 4px solid #a1a1a1;margin-top: 15px;padding: 20px;">
<button class="btn btn-success btn-lg">Download Excel xls</button>
<button class="btn btn-success btn-lg">Download Excel xlsx</button>
<button class="btn btn-success btn-lg">Download CSV</button>
</div>
<h3>Table Import List </h3>
<div style="border: 4px solid #a1a1a1;margin-top: 15px;padding: 20px;" >
print_r($arr->count());
#if(!empty($arr))
<table class="table table-striped table-hover table-reflow">
#foreach($arr as $key=>$value)
<tr>
<th ><strong> {{ $key }}: </strong></th>
<td> {{ $value }} <td>
</tr>
#endforeach
</table>
#endif
</div>
</div>
</div>
</div>
#stop
#section('css')
<link rel="stylesheet" href="/css/admin_custom.css">
#stop
#section('js')
<script> console.log('Hi! this is frontpage'); </script>
#stop
As conveyed by #gbalduzzi you need to return the data to the view as
return back()->with(['arr' => $arr]);
and access in your view as
#if(session()->has('arr'))
<table class="table table-striped table-hover table-reflow">
#php $arr = session('arr'); #endphp
#foreach($arr as $key => $value)
<tr>
<th ><strong> {{ $value['name'] }}: </strong></th>
<td>{{ $value['details'] }} <td>
</tr>
#endforeach
</table>
#endif
Docs
Change
return back()->with($arr);
with
return back()->with(['arr' => $arr]);
return back()->with('arr', $arr); // Should be equivalent
return back()->compact($arr); // Should be equivalent
The with method doesn't accept only a single value: you need to specify an array, a key and a value or use the compact method

Vuejs2 multiple if condition

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

Resources