fail to show allert " No data" when data is does not in database - laravel

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

Related

live.ERROR: Trying to get property 'title' of non-object (View: C:\xampp\htdocs\core\resources\views\user\signal-all.blade.php)

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

Failed to load excel\laravel-excel

I want to export only filtered data in view blade. I am using Laravel 7 and maatwebsite/excel 3.1 and PHP 7.4.2.
I went through the documentation and applied this:
View
<a href="{!! route('users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
web.php
Route::get('/users/export-filter', 'Admin\UserController#filter')->name('users.export-filter');
UserController.php
public function filter()
{
return Excel::download(new FilterUserExport, 'filter.xlsx');
}
FilterUserExport.php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use Modules\User\Entities\User;
use Illuminate\Contracts\View\View;
class FilterUserExport implements FromView, ShouldAutoSize, WithEvents
{
/**
* #return View
*/
public function view(): View
{
$users = app(User::class)->newQuery();
if ( request()->has('search') && !empty(request()->get('search')) ) {
$search = request()->query('search');
$users->where(function ($query) use($search) {
$query->where('first_name', 'LIKE', "%{$search}%")
->orWhere('last_name', 'LIKE', "%{$search}%")
->orWhere('email', 'LIKE', "%{$search}%")
->orWhere('mobile', 'LIKE', "%{$search}%");
});
}
return view('users.index', compact('users'));
}
/**
* #return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
},
];
}
}
index.blade.php
#extends("admin-panel.layouts.master")
#section("content")
<div class="content-body">
<section class="grid-with-inline-row-label" id="grid-with-inline-row-label">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">
<a data-action="collapse">
<i class="ft-plus mr-1"></i>
ثبت فیلتر
</a>
</h4>
<a class="heading-elements-toggle"><i class="ft-align-justify font-medium-3"></i></a>
<div class="heading-elements">
<ul class="list-inline mb-0">
<li><a data-action="collapse"><i class="ft-plus"></i></a></li>
<li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
<li><a data-action="close"><i class="ft-x"></i></a></li>
</ul>
</div>
</div>
<div class="card-content collapse #if( $errors->any() ) show #endif">
<div class="card-body">
<form action="{!! route('admin::users.index') !!}" method="get">
<div class="form-body">
<div class="row">
<div class="col-6 form-group">
<label for="search">جستجو</label>
<input type="text" name="search" id="search" class="form-control"
placeholder="جستجو..."
aria-label="جستجو" value="{{ request()->query('search') }}">
</div>
<div class="col-6 form-group">
<label for="user_type">گروه کاربری</label>
<select id="user_type" name="user_type" class="form-control">
<option value="" {{ (request()->query('user_type') == '')? "selected" : "" }}>-</option>
<option value="is_special" {{ (request()->query('user_type') == 'is_special')? "selected" : "" }}>کاربر ویژه</option>
<option value="is_user" {{ (request()->query('user_type') == 'is_user')? "selected" : "" }}>کاربر عادی</option>
<option value="is_admin" {{ (request()->query('user_type') == 'is_admin')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-6 form-group">
<label for="target">فیلتر کاربران</label>
<select id="target" name="target" class="form-control">
<option value="" {{ (request()->query('target') == '')? "selected" : "" }}>-</option>
<option value="active" {{ (request()->query('target') == 'active')? "selected" : "" }}>کاربر ویژه</option>
<option value="orderedAtLeastOnce" {{ (request()->query('target') == 'orderedAtLeastOnce')? "selected" : "" }}>کاربر عادی</option>
<option value="orderedInLastMonth" {{ (request()->query('target') == 'orderedInLastMonth')? "selected" : "" }}>مدیریت سیستم</option>
<option value="neverOrdered" {{ (request()->query('target') == 'neverOrdered')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-md-6 form-group">
<label for="categoryId">دسته بندی</label>
{!! Form::select('categoryId', \Modules\Category\Entities\Category::whereNull('parentId')->get()->pluck('title', 'id')->toArray(), null, [
'class' => 'form-control',
'id' => 'categoryId',
'placeholder' => 'انتخاب دسته بندی',
]) !!}
</div>
</div>
<div class="d-flex justify-content-between form-actions pb-0">
<div>
<button type="submit" class="btn btn-primary">ارسال <i class="ft-send position-right"></i>
</button>
<button type="reset" class="btn btn-warning">ریست <i class="ft-refresh-cw position-right"></i>
</button>
</div>
<div>
<a href="{!! route('admin::users.export-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صادر
</a>
<a href="{!! route('admin::users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
<a href="{!! route('admin::users.export-special-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صدور کاربران ویژه
</a>
<a href="{!! route('admin::users.import-excel') !!}" class="btn btn-primary">
<i class="la la-cloud-download"></i>
آپلود
</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div id="recent-transactions" class="col-xl-12 col-12">
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md">
<div class="row justify-content-between align-items-center mr-md-1 mb-1">
<div class="col-sm">
<h4 class="card-title mb-2 mb-sm-0">فهرست کاربران</h4>
</div>
</div>
</div>
<div class="col-auto">
<a href="{!! route('admin::users.create') !!}" class="btn btn-info">
<i class="la la-plus"></i>
ایجاد کاربر جدید
</a>
</div>
</div>
</div>
<div class="card-content">
#if( $users->count() > 0 )
#includeWhen( Module::find('notification') && request()->has('search'), 'user::admin.users._notification' )
<div class="table-responsive">
<table id="recent-orders" class="table table-hover table-xl mb-0">
<thead>
<tr>
<th class="border-top-0"># شناسه</th>
<th class="border-top-0">نام و نام خانوادگی</th>
<th class="border-top-0">موبایل</th>
{{-- <th class="border-top-0">ایمیل</th>--}}
<th class="border-top-0">کد ملی</th>
<th class="border-top-0">مدیر</th>
<th class="border-top-0">وضعیت</th>
<th class="border-top-0">ویژه</th>
<th class="border-top-0">آخرین ورود</th>
<th class="border-top-0">عملیات</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td class="text-truncate">
<i class="la la-dot-circle-o success font-medium-1 mr-1"></i>
{{ $user->id }}
</td>
<td class="text-wrap">
{{ $user->first_name.' '.$user->last_name }}
</td>
<td class="text-wrap">
{{ $user->mobile }}
</td>
{{--<td class="text-wrap">
{{ $user->email }}
</td>--}}
<td class="text-wrap">
{{ $user->national_id }}
</td>
<td class="text-wrap">
#if( $user->is_admin )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( !$user->disabled_at )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->is_special_user == 1 )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->last_login_at )
{{ getShamsiDate($user->last_login_at) }}
#else
—
#endif
</td>
<td>
<div class="row flex-nowrap">
<a href="{{ route('admin::users.show', $user) }}" class="mr-1">
<i class="ft-eye text-grey text-shadow-custom font-medium-5 font-weight-normal"></i>
</a>
<a href="{{ route('admin::users.edit', $user) }}" class="mr-1">
<i class="ft-edit text-grey text-shadow-custom font-medium-4 font-weight-normal"></i>
</a>
<form action="{{ route('admin::users.destroy', $user) }}"
method="post"
#submit.prevent="confirmDelete">
#method('delete')
#csrf
<button type="submit" class="btn btn-default p-0">
<i class="ft-trash-2 text-grey font-medium-5 font-weight-normal"></i>
</button>
</form>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pagination-flat">
{{ $users->links() }}
</div>
</div>
#else
<div class="text-center my-2">
<p>نتیجه‌ای برای نمایش وجود ندارد.</p>
</div>
#endif
</div>
</div>
</div>
</div>
</section>
</div>
#endsection
I get this error
The export submit button is sending everything to Excel. How do I make it to send only the filtered data. Thanks
You need to get rid of the other HTML in your view such as forms, inputs, and buttons. Keep the view only to a minimum of the table that needed for your Excel.

Laravel query return wrong data

QUERY:
$recent_posts = Blog::join("categories",'categories.id', '=', 'blogs.category_id')
->where('categories.status', 1)
->orderBy('blogs.id', 'desc')
->take(3)
->get();
Both tables had a created_at column.
At frontend im using this to retrieve the data:
<div class="row justify-content-center">
#foreach ($recent_posts as $recent_post)
<div class="col-md-6 col-lg-4 latest-blog-resp">
<div class="blog-item">
<div class="blog-img">
<a href="{{ url('blog/'.$recent_post->slug) }}">
#if ($recent_post->blog_image == '')
<img src="{{ asset('fibonacci/adminpanel/assets/img/dummy/no_image.jpg') }}" class="img-fluid round-item" alt="blog image">
#else
<img src="{{ asset('fibonacci/adminpanel/assets/img/blog/thumbnail1/'.$recent_post->blog_image) }}" class="img-fluid round-item" alt="blog image">
#endif
</a>
</div>
<div class="blog-inner">
<div class="blog-meta">
<span class="mr-2">
<i class="mdi mdi-calendar-account-outline"></i>{{ __('frontend.by_admin') }}
</span>
<span>
<i class="mdi mdi-calendar-range"></i>{{Carbon\Carbon::parse($recent_post->created_at)->isoFormat('MMMM')}} {{Carbon\Carbon::parse($recent_post->created_at)->isoFormat('DD')}}
</span>
</div>
<h5 class="blog-title">
{{ $recent_post->title }}
</h5>
<p class="blog-desc">{{ $recent_post->short_description }}</p>
<a href="{{ url('blog/'.$recent_post->slug) }}" class="blog-more-link">
{{ __('frontend.read_more') }} <i class="fa fa-angle-right ml-2"></i>
</a>
</div>
</div>
</div>
#endforeach
#if (count($recent_posts) === 3)
<div class="col-12 text-center margin-top-30">
<div class="btn-group">
<a href="{{ url('blog') }}" class="default-button">
{{ __('frontend.view_all') }}
</a>
</div>
</div>
#endif
</div>
THE PROBLEM:
$recent_post->created_at returns the category table creation (created_at) date but we expect to receive the blog table result as created_as (like a post creation data).
Thanks in advance!
Specify your fields in a select clause.
$recent_posts = Blog::select(
'blogs.slug',
'blogs.blog_image',
'blogs.title',
'blogs.short_description',
'blogs.created_at'
)
->join('categories', 'categories.id', 'blogs.category_id')
->where('categories.status', 1)
->orderByDesc('blogs.id')
->take(3)
->get();

Paginate two collections + infiniteScroll

i'm having a trouble trying to paginate a view with 2 collections, i will explain.
i am using infiniteScroll (infinite-scrollDOTcom)
i don't have code on controller that i can reutilize to show i try with arrays but for infiniteScroll only with ajax and adding a route for it, but i dont like that ideia.
im trying to do something like this (pseudocode)
data = CollectionA + CollectionB
//if i can do it, try to orderBy (but not the most important now)
data->orderBy('something')
data->paginate(x)
return view()->with('data', data)
Controller (this is only to work with the infinite scroll for now):
public function getGarantias()
{
$data = GarantiaCasa::all()->toBase()->merge(GarantiaCarro::all()->toBase())->sortBy('nome');
$data = new Paginator($data, 1, 1);
//dd($data);
return view('administrador.garantias')
->with('garantias', $data);
}
infiniteScroll:
function infiniteScroll(message) {
var loading_options = {
finishedMsg: "<div class='end-msg'>"+message+"</div>",
msgText: "<div class='center'></div>",
img: '/img/loading.gif'
};
$('#items').infinitescroll({
loading : loading_options,
navSelector : "#data .pagination",
nextSelector : "#data .pagination li.active + li a",
itemSelector : "#items tr.item"
});
}
View (the 2 foreach is only for now until new solution
<div class="col-md-10 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body" id="data">
<div class="pull-right" onload="">
#foreach(Auth::user()->getAllSeguros() as $tiposeguro)
<div class="btn-group">
<span type="button" class="btn btn-default btn-filter" data-target="{{ $tiposeguro }}" >{{ ucfirst($tiposeguro) }}</span>
</div>
#endforeach
<div class="btn-group">
<button type="button" class="btn btn-default btn-filter" data-target="all">Todos</button>
</div>
</div>
<div class="table-container">
<table class="table table-filter">
<tbody id="items">
#foreach($garantiasCarro as $garantia)
<tr class="item" data-status="{{ $garantia->tipo }}" style="width: 500px">
<td>
<a href="#" class="pull-left">
<img src="{{ URL::to('/') }}/img/buttons/edit.png" class="media-photo">
</a>
</td>
<td>
<a href="#" class="pull-left">
<img src="{{ URL::to('/') }}/img/buttons/delete.png" class="media-photo">
</a>
</td>
<td>
<div class="media">
<div class="media-body">
<h4 class="title">
{{ $garantia->nome }}
<span class="pull-right tipo">({{ $garantia->tipo }})</span>
</h4>
<p class="summary">{{ $garantia->descricao }}</p>
</div>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<div hidden="hidden">{{ $garantias->links() }}</div>
</div>
</div>
</div>
UPDATE: now with the new Paginator i have sort of what i need but cant paginate, the infinitescroll doesnt work i think is probably because the links..
Thanks.

DataTables Custom Search in Laravel

I'm using laravel to create a contact page, and this is my view code:
<table id="example">
<thead>
<tr>
<th class="no-sort"></th>
</tr>
</thead>
<tbody>
<?php $idx = 1; ?>
#foreach($users as $result)
#if($idx == 1) <tr> #endif
<td class="col-md-4 col-sm-4 col-xs-12 animated fadeInDown">
<div class="well profile_view">
<div class="col-sm-12">
<h4 class="brief"><i>Digital Strategist</i></h4>
<div class="left col-xs-7">
<h2>{!! $result->first_name !!}</h2>
<p><strong>Username: </strong> {!! $idx !!} </p>
<ul class="list-unstyled">
<li>{!! $result->email !!}</li>
</ul>
</div>
<div class="right col-xs-5 text-center">
#if($result->image)
{!! Html::image('packages/calibre/images/profile/'.$result->image, '', array("class"=>"img-circle img-responsive")) !!}
#else
{!! Html::image('packages/calibre/images/profile/none.png', '', array("class"=>"img-circle img-responsive")) !!}
#endif
</div>
</div>
<div class="col-xs-12 bottom text-center">
<div class="col-xs-12 col-sm-12 emphasis">
<button type="button" class="btn btn-success btn-xs pull-left"><i class="fa fa-check"></i> Active</button>
<button type="button" class="btn btn-primary btn-xs pull-right"><i class="fa fa-search"></i> View Profile </button>
</div>
</div>
</div>
</td>
#if($idx == 3) </tr> #endif
<?php if($idx == 3) $idx = 1; else $idx++; ?>
#endforeach
</tbody>
</table>
the layout is not like common tables, it's using tag from it's template.
How to enable it using DataTables to search and paging? anyone could help me?

Resources