in total I have 3 files which contain the following functionality:
I got a navigation bar which toggles 3 different areas.
I got a table which contains data
A file which include file 1 and 2 (master file)
So now if I open the master file I can go through all 3 areas but every are should contain different data in the table.
File 1
<div class="manage-budget-nav-wrapper text-left mx-lg mx-sm-4 mx-2">
<ul class="nav nav-tabs border-0" role="tablist">
<li class="nav-item">
<a class="nav-link px-0 mr-sm-5 mr-3 ml-0 active" id="home-tab" data-toggle="tab" href="#home-1" role="tab"
aria-controls="home-1" aria-selected="true">Offenes Gesamtguthaben</a>
</li>
<li class="nav-item">
<a class="nav-link px-0 mr-sm-5 mr-3 ml-0" id="profile-tab" data-toggle="tab" href="#profile-1" role="tab"
aria-controls="profile-1" aria-selected="false">Spenden</a>
</li>
<li class="nav-item">
<a class="nav-link px-0 mr-sm-5 mr-3 ml-0" id="profile-tab" data-toggle="tab" href="#redeem-1" role="tab"
aria-controls="redeem-1" aria-selected="false">Gutschein</a>
</li>
</ul>
<hr class="mt-0">
</div>
file 2
<div class="table-responsive">
<table class="table table-striped table-hover mb-4">
<thead>
<tr>
#if (\Request::is('admin/locals/donations'))
<th scope="col">Erwerbsdatum</th>
#elseif (\Request::is('admin/locals/dashboard'))
<th scope="col">Buchungstag</th>
#endif
</tr>
</thead>
<tbody>
{{-- #foreach transaction --}}
#if (\Request::is('admin/locals/donations') class_exist)
<tr>
{{-- date of acquisition in d.m.Y --}}
<td>{24.12.2020}</td>
</tr>
#elseif (\Request::is('admin/locals/dashboard'))
<tr>
{{-- booking day in d.m.Y --}}
<td>{24.12.2020}</td>
</tr>
#endif
{{-- #endforeach transaction --}}
</tbody>
</table>
</div>
I already got some if statement but how can I check if e.g. area one is active or got class active. Inside the navigation to check #if (aria-selected="true").
how can I check if e.g. area one is active or got class active.
Inside the navigation to check #if (aria-selected="true")
I think you misunderstood the purpose of Blade Engine. Blade files, alongside their directives are parsed by the PHP on server, not by the browser. Therefore you can't check a HTML attribute, or select them using Blade the way you do with javascript.
The question which rise is: why do you want to check if aria-selected is true? If it is to insert another tag, you should do that in javascript/jQuery (which again -- is a different layer than Blade):
$('div [aria-selected="true"]').map(function(element){
$(element).append('<p>html code</p>')
})
Blade directives = server
Javascript = browser
Related
I have three tables. First is user which has an 'email' as a username. Second is customer which alos has email column. And third table is shipments. The shipment has relationship with customer table. User can login with email id which is present in User and Customer table. When user is logged in with their email I wamt to show shipments related to respective user, filterdered by email address of current logged in user. Please guide be. below is my index.blade.php
#extends('layouts.app')
#section('content')
<div class="page-titles">
<h2> Vishal {{ $pageTitle }} <small> {{ $pageNote }} </small></h2>
<h4></h4>
</div>
<div class="card">
<div class="card-body">
<div class="toolbar-nav" >
<div class="row">
<div class="col-md-4 col-4">
<div class="input-group ">
<input type="text" class="form-control form-control-sm onsearch" data-target="{{ url($pageModule) }}" aria-label="..." placeholder=" Type And Hit Enter ">
</div>
</div>
<div class="col-md-8 col-8 text-right">
<div class="btn-group">
#if($access['is_add'] ==1)
<a href="{{ url('shipments/create?return='.$return) }}" class="btn btn-sm btn-primary"
title="{{ __('core.btn_create') }}"><i class="fas fa-plus"></i> {{ __('core.btn_create') }}</a>
#endif
<div class="btn-group">
<button type="button" class="btn btn-sm btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fas fa-bars"></i> Bulk Action </button>
<ul class="dropdown-menu">
#if($access['is_remove'] ==1)
<li class="nav-item"><a href="javascript://ajax" onclick="SximoDelete();" class="nav-link tips" title="{{ __('core.btn_remove') }}">
Remove Selected </a></li>
#endif
#if($access['is_add'] ==1)
<li class="nav-item"><a href="javascript://ajax" class=" copy nav-link " title="Copy" > Copy selected</a></li>
<div class="dropdown-divider"></div>
<li class="nav-item"> Import CSV</li>
#endif
<div class="dropdown-divider"></div>
#if($access['is_excel'] ==1)
<li class="nav-item"> Export Excel </li>
#endif
#if($access['is_csv'] ==1)
<li class="nav-item"> Export CSV </li>
#endif
#if($access['is_pdf'] ==1)
<li class="nav-item"> Export PDF </li>
#endif
#if($access['is_print'] ==1)
<li class="nav-item"> Print Document </li>
#endif
<div class="dropdown-divider"></div>
<li class="nav-item"> Clear Search </li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- Table Grid -->
{!! Form::open(array('url'=>'shipments?'.$return, 'class'=>'form-horizontal m-t' ,'id' =>'SximoTable' )) !!}
<div class="table-responsive">
<table class="table table-hover table-striped " id="{{ $pageModule }}Table">
<thead>
<tr>
<th style="width: 3% !important;" class="number"> No </th>
<th style="width: 3% !important;">
<input type="checkbox" class="checkall filled-in" id="checked-all" />
<label for="checked-all"></label>
</th>
#foreach ($tableGrid as $t)
#if($t['view'] =='1')
<?php $limited = isset($t['limited']) ? $t['limited'] :'';
if(SiteHelpers::filterColumn($limited ))
{
$addClass='class="tbl-sorting" ';
if($insort ==$t['field'])
{
$dir_order = ($inorder =='desc' ? 'sort-desc' : 'sort-asc');
$addClass='class="tbl-sorting '.$dir_order.'" ';
}
echo '<th align="'.$t['align'].'" '.$addClass.' width="'.$t['width'].'">'.\SiteHelpers::activeLang($t['label'],(isset($t['language'])? $t['language'] : array())).'</th>';
}
?>
#endif
#endforeach
<th style="width: 10% !important;">{{ __('core.btn_action') }}</th>
</tr>
</thead>
<tbody>
#foreach ($rowData as $row)
<tr>
<td class="thead"> {{ ++$i }} </td>
<td class="tcheckbox">
<input type="checkbox" class="ids filled-in" name="ids[]" value="{{ $row->id }}" id="val-{{ $row->id }}" />
<label for="val-{{ $row->id }}"></label>
</td>
#foreach ($tableGrid as $field)
#if($field['view'] =='1')
<?php $limited = isset($field['limited']) ? $field['limited'] :''; ?>
#if(SiteHelpers::filterColumn($limited ))
<?php $addClass= ($insort ==$field['field'] ? 'class="tbl-sorting-active" ' : ''); ?>
<td align="{{ $field['align'] }}" width=" {{ $field['width'] }}" {!! $addClass !!} >
{!! SiteHelpers::formatRows($row->{$field['field']},$field ,$row ) !!}
</td>
#endif
#endif
#endforeach
<td>
<div class="dropdown">
<button class="btn dropdown-toggle" type="button" data-toggle="dropdown"><i class="fas fa-tasks"></i> </button>
<ul class="dropdown-menu">
#if($access['is_detail'] ==1)
<li class="nav-item"> {{ __('core.btn_view') }} </li>
#endif
#if($access['is_edit'] ==1)
<li class="nav-item"> {{ __('core.btn_edit') }} </li>
#endif
<div class="dropdown-divider"></div>
#if($access['is_remove'] ==1)
<li class="nav-item"><a href="javascript://ajax" onclick="SximoDelete();" class="nav-link tips" title="{{ __('core.btn_remove') }}">
Remove Selected </a></li>
#endif
</ul>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<input type="hidden" name="action_task" value="" />
{!! Form::close() !!}
<!-- End Table Grid -->
</div>
#include('footer')
</div>
</div>
<script>
$(document).ready(function(){
$('.copy').click(function() {
var total = $('input[class="ids"]:checkbox:checked').length;
if(confirm('are u sure Copy selected rows ?'))
{
$('input[name="action_task"]').val('copy');
$('#SximoTable').submit();// do the rest here
}
})
});
</script>
#stop
So you want to display shipments of a logged-in user? Then at this point, I'm expecting that you have already defined the Eloquent Relationships as methods on your Eloquent User and Shipment model classes and actually able to save the data.
In your Controller
use Illuminate\Support\Facades\Auth;
public function index()
{
$user = Auth::user()->load('shipments');
return view('sample.index', ['user' => $user]);
}
With the Auth::user() it checks if the current user is authenticated (returns true if the user is logged-in) via the Auth facade. Since the User model has already been retrieved, you can use Lazy Eager Loading with the load() to load the Shipment model.
And in your blade, you can display user's info and iterate over the shipment collection like so:
#foreach ($user->shipments as $shipment)
<p>{{ $shipment->field }}</p>
#endforeach
I am trying to use dynamic tabs in laravel and iam kinda new to it. Iam stuck in it for like 2 days.
I have two variables that getting data from tables in mysql.
$stations = Station::select('id', 'name')->get();
// return $staions;
$queues = Queue::withTrashed()
->oldest()
->get();
// return $queues;
The data in $schedules:
[
{
"id":1,
"name":"siinay"
},
{
"id":2,
"name":"jigjiga"
},
{
"id":3,
"name":"Idaacada"
},
{
"id":4,
"name":"Xero Awr"
}
]
And the data in the $queues:
So the problem is here in dynmaic tabs: I have wanted to display station names in the nav-tabs and queues in the tab-content. So i did it like this.
<ul class="nav nav-tabs">
#forelse ($stations as $station)
<li >
<a data-toggle="tab" href="#tab-{{ $station->id }}" >
{!! $station->name !!}
</a>
</li>
#empty
#endforelse
</ul>
<div style="margin-top: 15%" class="tab-content">
#foreach($queues as $queue)
#if($queue)
<div id="tab-{{ $queue->station_id}}" class="tab-pane fade">
<p>{!! $queue->bus_number !!}</p>
</div>
#else
<div>empty</div>
#endif
#endforeach
</div>
when i run the above code, it only showing the last queue bus_number per each sttions. every stations queue
Oldest is indeed the oldest, it's the opposite to first. Try this to get a collection:
$queues = Queue::withTrashed()
->orderBy('id', 'desc')
->get();
In the view (simplified):
<ul class="nav nav-tabs">
#foreach ($stations as $station)
<li>
<a data-toggle="tab" href="#tab-{{ $station->id }}">
{{ $station->name }}
</a>
</li>
#endforeach
</ul>
<div style="margin-top: 15%" class="tab-content">
#foreach($queues as $queue)
<div id="tab-{{ $queue->station_id }}" class="tab-pane fade">
<p>{{ $queue->bus_number }}</p>
</div>
#endforeach
</div>
No need to check for empty. Each one is a table record. Unless you want to check on bus_number or station_id.
When user accesses "http://proj.test/user/profile?user=1" he goes to a page like below that has 3 tabs, one for the user to edit his acccount, other (My Tickets) for the user to access information about his registrations in congresses and other (My Congresses) for the user to access the information of congresses created by him. The default tab when this page is acessed his the "Edit user account".
The tab1 content is for the user to edit his profile. When user click in "Update" the code goes to the UserController to update the user info.
When the user click in the tab2 (My Tickets) the content of this tab is like below. It shows the registrations in congresses of the user. Inside this tab content it appears also 2 tabs for the user to show his registrations in congresses that already finish and other tab to show his registrations in congresses that have not yet been performed.
Then there is the pagination if there are more than 5 results, when the user change to link "2" he goes to "http://proj.test/user/profile?page=2".
When the user click in the tab3 (My Congresses) the content of this tab is like below. It shows the congresses created by the user. Inside this tab content it appears also 3 tabs, one (Draft) for the user to show the congresses created by him that have the column "status" as "D", other (Published) to show the congresses created by the user that have the column "status" as "P" and other (Archived) to show the congresses created by the user that already finished.
Then there is the pagination if there are more than 5 results, when the user change to link "2" he goes to "http://proj.test/user/profile?page=2".
Doubt:
The issue with this context is that when a pagination link is clicked in some tab, for example if the user is in the tab "Draft" inside "My Congresses" tab, and clicks in the pagination link "2", the url changes to "http://proj.test/user/profile?page=2" but the tab that become active his the first one, the "Edit user account" tab. Then if the user clicks in "My Congresses" it appears the results of the page 2, but the user needs to manually click in the "My Congresses".
Do you know how to turn, in this case, the "My Congresses" tab active when a pagination page link is clicked in the "My Congresses" tab?
Full code on this page to show all the tabs:
<ul class="nav nav-pills" role="tablist">
<li class="">
<a class="nav-link active" href="#updateUserInfo" data-toggle="tab" role="tab">Edit user account</span></a>
</li>
<li class="disabled">
<a class="nav-link" href="#myCongresses" data-toggle="tab" role="tab">My Congresses</span></a>
</li>
<li class="disabled">
<a class="nav-link" href="#myTickets" data-toggle="tab" role="tab">My Tickets</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active clearfix" id="updateUserInfo" role="tabpanel" aria-labelledby="home-tab">
<form method="post" action="{{route('user.updateUserInfo')}}" class="clearfix">
{{csrf_field()}}
<div class="form-row">
<div class="form-group">
<label for="name">Name</label>
<input type="text" value="{{$user->name}}" name="name" class="form-control" id="name" >
</div>
<!--other form fields-->
<input type="submit" class="btn btn-primary btn" value="Update"/>
</form>
</div>
<div class="tab-pane clearfix fade" id="myCongresses" role="tabpanel" aria-labelledby="contact-tab">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active border" href="#draftCongresses" data-toggle="tab"
role="tab">Draft</a>
</li>
<li class="nav-item">
<a class="nav-link border" href="#publishedCongresses" data-toggle="tab"
role="tab">Published</a>
</li>
<li class="nav-item">
<a class="nav-link border" href="#archivedCongresses" data-toggle="tab"
role="tab">Archived</a>
</li>
</ul>
<div class="tab-content bg-white" id="myTabContent">
<div class="tab-pane fade active show clearfix" id="draftCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group">
#foreach($draftCongresses as $draftCongress)
#if(!empty($draftCongress))
<li class="list-group-item">
<p>{{$draftCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{$draftCongress->name}}</h5>
Edit Congress
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$draftCongresses->links(("pagination::bootstrap-4"))}}
</div>
</div>
<div class="tab-pane fade show clearfix" id="publishedCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group">
#foreach($publishedCongresses as $publishedCongress)
#if(!empty($publishedCongress))
<li class="list-group-item">
<p>{{$publishedCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{$publishedCongress->name}}</h5>
<a href="{{route('congress.edit', ['id' => $publishedCongress->id])}}"
class="btn btn-outline-primary">Edit Congress</a>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$publishedCongresses->links(("pagination::bootstrap-4"))}}
</div>
</div>
<div class="tab-pane fade show clearfix" id="archivedCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group">
#foreach($archivedCongresses as $archivedCongress)
#if(!empty($archivedCongress))
<li class="list-group-item">
<p> {{$archivedCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{$archivedCongress->name}}</h5>
<a href="{{route('congress.edit', ['id' => $archivedCongress->id])}}"
class="btn btn-outline-primary">Edit Congress</a>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$archivedCongresses->links(("pagination::bootstrap-4"))}}
</div>
</div>
</div>
</div>
<div class="tab-pane clearfix fade" id="myTickets" role="tabpanel" aria-labelledby="contact-tab">
<div class="d-flex mb-3">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active border" id="nextCongresses" href="#nextCongresses" data-toggle="tab" role="tab">Next Congresses</a>
</li>
<li class="nav-item">
<a class="nav-link border" id="pastCongresses" href="#pastCongresses" data-toggle="tab" role="tab">Past Congresses</a>
</li>
</ul>
</div>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="nextCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group" id="nextCongressesContainer">
#foreach($nextRegistrations as $nextRegistration)
#if(!empty($nextRegistration->congress || !empty($nextRegistration->congress->start_date)))
<li class="list-group-item">
<p>{{optional($nextRegistration->congress)->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{optional($nextRegistration->congress)->name}}</h5>
<p> Registration in {{optional($nextRegistration->congress)->created_at }}</p>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$nextRegistrations->links(("pagination::bootstrap-4"))}}
</div>
</div>
<div class="tab-pane fade show" id="pastCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group" id="pastCongressesContainer">
#foreach($pastRegistrations as $pastRegistration)
#if(!empty($pastRegistration->congress || !empty($pastRegistration->congress->start_date)))
<li class="list-group-item">
<p>{{optional($pastRegistration->congress)->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{optional($pastRegistration->congress)->name}}</h5>
<p> Registration in {{$pastRegistration->created_at}}</p>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$pastRegistrations->links(("pagination::bootstrap-4"))}}
</div>
</div>
</div>
</div>
</div>
UserController:
class UserController extends Controller
{
public function index(Request $request){
$pageLimit = 5;
$user = $request->user();
$pastRegistrations = $user->registrations()->with(['congress' => function ($query) {
$query->where('end_date', '<', now());
}])->paginate($pageLimit);
$nextRegistrations = $user->registrations()->with(['congress' => function ($query) {
$query->where('end_date', '>', now());
}])->paginate($pageLimit);
$draftCongresses = $user->congresses()->where('status','D')->paginate($pageLimit);
$pastCongresses = $user->congresses()->where('end_date','<', now())->paginate($pageLimit);
$publishedCongresses = $user->congresses()->where('status','P')->paginate($pageLimit);
return view('users.index',
compact('user', 'pastRegistrations','nextRegistrations', 'draftCongresses', 'pastCongresses', 'publishedCongresses'));
}
}
Example of the issue
If pagination link "2" is clicked here:
Instead of appear the page with the "My Congresses" tab active like the image above but with the pagination link "2" active instead of the pagination link "1" active, it appaers the page with the default active tab "Edit user account":
Since you're using Bootstrap tabs, you need to append the right fragment to your pagination links in order to maintain the active tab.
For exemple you can do something like this
{{ $draftCongresses->fragment('myCongresses')->links("pagination::bootstrap-4") }}
You can see the doc here
Change these:
{{$draftCongresses->links(("pagination::bootstrap-4"))}}
{{$publishedCongresses->links(("pagination::bootstrap-4"))}}
{{$archivedCongresses->links(("pagination::bootstrap-4"))}}
{{$nextRegistrations->links(("pagination::bootstrap-4"))}}
{{$pastRegistrations->links(("pagination::bootstrap-4"))}}
..to these: (i.e. add the corresponding link fragment)
{{$draftCongresses->fragment('draftCongresses')->links(("pagination::bootstrap-4"))}}
{{$publishedCongresses->fragment('publishedCongresses')->links(("pagination::bootstrap-4"))}}
{{$archivedCongresses->fragment('archivedCongresses')->links(("pagination::bootstrap-4"))}}
{{$nextRegistrations->fragment('nextCongresses')->links(("pagination::bootstrap-4"))}}
{{$pastRegistrations->fragment('pastCongresses')->links(("pagination::bootstrap-4"))}}
Then add this JavaScript/jQuery script to the page:
<script>
jQuery( function( $ ){
// List of tab IDs.
var tabs = {
// PARENT_TAB_ID: [ 'ID_OF_DIRECT_CHILD_TAB', 'ID_OF_DIRECT_CHILD_TAB', ... ]
updateUserInfo: [],
myCongresses: [ 'draftCongresses', 'publishedCongresses', 'archivedCongresses' ],
myTickets: [ 'nextCongresses', 'pastCongresses' ]
};
// Default tab's ID.
var default_tab = 'updateUserInfo';
function showTab( parent_id, child_id ) {
$( 'a[data-toggle="tab"][href="#' + parent_id + '"]' ).first().click();
if ( child_id ) {
$( 'a[data-toggle="tab"][href="#' + child_id + '"]' ).first().click();
}
}
$( window ).on( 'load hashchange', function(){
var tab_id = location.hash || '';
// Remove the hash (i.e. `#`)
tab_id = tab_id.substring(1);
if ( tab_id && tabs[ tab_id ] ) {
showTab( tab_id );
} else if ( tab_id ) {
$.map( tabs, function( child_ids, parent_id ){
if ( $.inArray( tab_id, child_ids ) > -1 ) {
showTab( parent_id, tab_id );
}
} );
} else {
showTab( default_tab );
}
} );
} );
</script>
I am trying to figure out why my pagination stops working as soon as I apply it to a user model. Here is the scenario: I am making a website which is a note takes, a user can take notes save them and all that. On a page /notes all notes made can be seen used for me to see weather each user is able to save notes. Pagination works there without a problem. Once I made a user Dashboard and I show notes they made with their user id I get this error:
Method links does not exist
…\vendor\laravel\framework\src\Illuminate\Support\Traits\Macroable.php
96
I have no clue why this is happening. When I delete the code from view: {{$notebooks->links()}} - the error goes away and so does pagination. The moment I put it in the error happens all over again.
Here is the code from my view and controllers.
DashboardController:
public function index()
{
$user_id = auth()->user()->id;
$user = User::find($user_id);
$notebooks = DB::table('notebooks', $user->notebooks)->paginate(4);
return view('dashboard')->with('notebooks', $user->notebooks);
}
}
Dashboard View (with paginate links code):
#extends('layouts.app')
#section('content')
<!-- Main component for call to action -->
<div class="container text-center">
<!-- heading -->
<h1 class="pull-xs-left">Your Dashboard</h1>
<br>
<div class="pull-xs-right">
<a class="btn btn-primary" href="/notebook/create" role="button"> New Note +</a>
</div>
<div class="pull-xs-right">
<a class="btn btn-primary" href="/contacts/create" role="button"> New Contact +</a>
</div>
<div class="pull-xs-right">
<!--the dropdown menu -->
<div class="dropdown show">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Sort Notebooks By
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="{{action('NotesController#ascendingId')}}">Note Number A - Z</a>
<a class="dropdown-item" href="{{action('NotesController#descendingId')}}">Note Number Z - A</a>
<a class="dropdown-item" href="{{action('NotesController#descendingTime')}}">Latest Time Posted</a>
<a class="dropdown-item" href="{{action('NotesController#ascendingTime')}}">Oldest Time Posted</a>
</div>
</div>
</div>
<div class="clearfix">
</div>
<br>
#if(count($notebooks) > 0)
#foreach ($notebooks as $notebook)
<div class="col-sm-3 col-md-3 col-sm-6">
<div class="card" style="width: 26rem;">
<div class="card-header" >
Client: {{$notebook->client_name}}
</div>
<div class="card-block" >
<h4 class="card-title " style="height: 5rem;"><strong><a href="/notebook/{{$notebook->id}}" >{{$notebook->name}}</a></strong></h4>
<p class="card-text" style="height: 7rem;">{{$notebook->note_description}}</p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item"><b>Last Updated:</b> {{$notebook->updated_at->format('d-m-Y')}}</li>
<li class="list-group-item">
Edit Note
</li>
</ul>
<div class="card-block">
{!!Form::open(['action' => ['NotesController#destroy', $notebook->id], 'method' => 'POST'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
</div>
</div>
</div>
#endforeach
</div>
<!-- /container -->
<hr>
<div class="container text-center">
{{$notebooks->links()}}
</div>
</div>
#else
<div>
<div class="col-lg-12 no-notes">
<p>No notes found, go ahead and make your first note! :)</p>
<a class="btn btn-primary" href="/notebook/create" role="button"> Make My First Note</a>
</div>
</div>
#endif
#endsection
Just a reminder this works perfectly without the user model. I am lost as how to fit it. Using Laravel 5.5.26.
Change the code to:
$notebooks = auth()->user()->notebooks()->paginate(4);
return view('dashboard')->with('notebooks', $notebooks);
Also, you do not need to get a user from DB since you can access auth()->user() instance in a view.
I have this blade in my view. Right now, I have 6 blocks of them in my view because I'm not sure how to refactor it.
<div class="row filemanager">
<div class="col-sm-12">
#foreach ($devices as $device)
#if( $device->vlan_id == 100 AND $device->device_activity == 'ACTIVE' )
<div class="col-xs-6 col-sm-4 col-md-2 text-center">
<div class="thmb">
<div class="btn-group fm-group" style="display: none;">
<button type="button" class="btn btn-default dropdown-toggle fm-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu fm-menu" role="menu">
<li id="device-menu">
<a class="changeDeviceNameBtn" href="#"><i class="fa fa-pencil"></i> Change Device Name </a>
</li>
</ul>
</div>
<div class="thmb-prev">
<a href="/{{$cpe_mac}}/device/{{$device->device_mac}}">
#if(isset($device->device_name))
{{-- Show base on device name --}}
<img src="/images/photos/devices/{{img($device->device_name)}}.jpg" class="draggable img-responsive" alt="">
#else
{{-- No Device Name Set --}}
#if($device->hostname != '')
{{-- Show base on hostname --}}
<img src="/images/photos/devices/{{img($device->hostname)}}.jpg" class="draggable img-responsive" alt="">
#else
{{-- Show default --}}
<img src="/images/photos/devices/no-img.jpg" class="draggable img-responsive" alt="">
#endif
#endif
</a>
</div>
<h5 class="fm-title device_name">
<a href="/{{$cpe_mac}}/device/{{$device->device_mac}}">
#if($device->hostname == '')
No Devicename
#else
{{ $device->hostname}}
#endif
</a>
</h5>
<h5 class="text-muted device_ip">{{$device->ip_address}}</h5>
<h5 class="text-muted device_mac">{{$device->device_mac}}</h5>
<?php
$status = ucfirst(strtolower($device->device_activity));
if ($status == 'Active'){
$color = '#1CAF9A';
}else{
$color = '#D9534F';
}
?>
<h5>{{ $status }}
<i class="fa fa-circle" style="color:{{$color}}; margin-left: 7px;"></i>
</h5>
</div>
</div>
#endif
#endforeach
</div>
</div>
I want to make a function containing that blade, and only replace my
$device->vlan_id, and my $device->device_activity.
Example,
public static deviceRow(100,ACTIVE){
... my blade ...
}
Now, I just that function 6 times, rather than duplicate that block of code 6 times.
Is it even possible ?
Any hints / suggestions on this will be much appreciated !
You can make a partial with your blade and send a variable as a parameter:
In your parent view do something like this:
#foreach($somelist as $item)
#include('view.partial', ['name' => $item->name])
#endforeach
And in a file called partial.blade.php, do something like this:
{{ $device->$name }}
It's the main idea. Tell me if it helps...
You could create a new view and send some parameters with it while including:
#include('my.view', ['device' => $myDevice, 'activity' => 'ACTIVE'])
The keys of the array will be available as variables in your view.
The variable $myDevice would be available as $device in the view my.view