show the section based on page - php

I have created filter section with filter.blade.php.I have 5 selectbox in that page.I want to display only four in page1 and 5 selectbox section in page2.
In web.php
Route::get('/page1',array('middleware'=>'checksession',function(){return View('layouts.page1');}));
Route::get('/page2',array('middleware'=>'checksession',function(){return View('layouts.page2');}));
I want to display below selectbox only in page2
<div class="col-md-12">
<!-- Card header -->
<div class="card-header" role="tab" id="headingFive5">
<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx" href="#collapseFive5"
aria-expanded="false" aria-controls="collapseFive5">
<h5 class="mb-0">
<div id="username_view">Username</div>
<img src="img/chevron-down.png" class="fa-angle-down rotate-icon">
</h5>
</a>
</div>
</div>

There are several ways of doing it like you are able to pass pass your current route variable as the second argument of your view.
Route::get('/page2',array('middleware'=>'checksession',function(){
$route = Route::current();
return View('layouts.page2',, compact('route'));
}));
after this pass condition over the route variable to satisfy your need.
another way is you are able to check this in your blade template directly by this:
#if(Request::url() === 'your url here')
// code
#endif
i hope this guide you. Read this for more understanding Accessing The Current Route

Related

Typo3 : display detail data in a modal pop up

I created a list of users in clickable cards, and when we click on the card, a modal popup appear.
I want now to display the detail of the user in theses popup but I don't really know how I have to do for displaying on the popup, the data of the user on which I click.
there is my List code :
<div class="container employees">
<div class="row">
<f:for each="{users}" as="user">
<div class="card card-annuaire">
<div class="card-body">
<h5 class="card-title">{user.firstname} {user.lastname}</h5>
<div class="links">
<ul>
<li class="loc">{user.address}</li>
<li class="tel">{user.telephone}</li>
<li class="service">{user.title}</li>
<li class="loc">{user.address}</li>
</ul>
</div>
</div>
</div>
</f:for>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<ul>
<li class="mail"></li>
<li class="tel"></li>
<li class="service"></li>
<li class="loc"></li>
<li class="comp"></li>
</ul>
</div>
</div>
controller :
public function listAction()
{
$users = $this->frontendUser->findAll();
$this->view->assign('users', $users);
}
Is my request possible with my current code?
My modal works perfectly, I just need to add my data
Someone have an Idea to how can I do it ?
Update : solved with some Jquery code to copy my data already existing :
<script>
const modal = $('#exampleModal');
$('.card-annuaire').click(function () {
const divAnnuaire = $(this);
$('.modal-title', modal).text($('.card-title', divAnnuaire).text());
$('li.tel', modal).text($('.tel', divAnnuaire).text());
$('li.service', modal).text($('.service', divAnnuaire).text());
$('li.loc', modal).text($('.loc', divAnnuaire).text());
})
</script>
The handling of the modal is a question of javascript.
If you have all data in each block of the user list you can add some javascript to each block which copies this data from the current block (this) into your modal and then unhide the modal.
On hiding the modal you don't need to do anything to the included data, as the next click (which also can occur if the modal already is visible) will fill in the data from the clicked data block.
If in your modal more data should be visible than you stored in your list you need to do something more:
you need the ID of the data to get the whole user-record by ajax call.
but otherwise the handling is the same: on each list block you have an eventhandler, which is triggered by a click and which uses data from the block (all fields, or just the uid for an ajax-call to get all data) and insert this data into the modal.

Laravel 8 - reusable code block, change variable depending on a page for charts?

I want to display multiple charts in a single page or different pages. How can I reuse the blade file instead of repeating/retyping the code?
I created a plain blade file _chart-widget.blade.php and I want the variable value to change depending on the page, or depending on what I want to set the variable in each <section> of a page
<!--begin::Charts Widget 1-->
<div class="card {{ $class ?? '' }}">
<!--begin::Header-->
<div class="card-header border-0 pt-5">
<!--begin::Title-->
<h3 class="card-title align-items-start flex-column">
<span class="card-label fw-bolder fs-3 mb-1">Recent Statistics</span>
<span class="text-muted fw-bold fs-7">More than 400 new members</span>
</h3>
<!--end::Title-->
<!--begin::Toolbar-->
<div class="card-toolbar">
<!--begin::Menu-->
<button type="button" class="btn btn-sm btn-icon btn-color-primary btn-active-light-primary" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end">
{!! theme()->getSvgIcon("icons/duotune/general/gen024.svg", "svg-icon-2") !!}
</button>
{{ theme()->getView('partials/menus/_menu-1') }}
<!--end::Menu-->
</div>
<!--end::Toolbar-->
</div>
<!--end::Header-->
<!--begin::Body-->
<div class="card-body">
<!--begin::Chart-->
<div id="kt_charts_widget_1_chart" style="height: 350px"></div>
<!--end::Chart-->
</div>
<!--end::Body-->
</div>
<!--end::Charts Widget 1-->
How can I make the code above dynamic and reusable when I #include it?
You can include views in Laravel blade template.
here you can read more.
Just use like this:
<div>
#include('_chart-widget')
</div>
If you need to pass data to your widget component, just give parameters as an array to your component:
#include('view.name', ['status' => 'complete'])
If you want variables to be different in each page simply pass vairables from Controller.If you are on the same page and including same blade multiple times this can help you:
#include('view.name', ['code' => 'complete'])
This will set different values for $code variable in different sections.
Check out documentation here.

Laravel 7.14 loading social links with for each loop on header

I have a datatable for social links. a user can edit the link whenever he wants.
Just link any other crud it is very simple. I am trying to load all the links in blade view with icons in header of my app. I created as function and added a for each loop in the snippets.
here's my controller:
public function socials()
{
$socials = Social::all();
return view('inc.subheader')->with('socials', $socials);
}
Here's blade snippent:
<div class="col-md-3 justify-content-center social-links">
<ul class="nav d-flex justify-content-center">
#foreach ($socials as $social)
<li class="">
<i class="{{ $social->icon }} fa-2x"></i>
</li>
#endforeach
</ul>
</div>
The error I'm getting is "$socials is undefined" and when I go on localhost/inc/social I only see three dots and no icons with links.
Change this line:
return view('inc.subheader')->with('socials', $socials);
to this:
return view('inc.subheader', compact('socials'));
You can try all combination :
return view('inc.subheader', compact('socials'));
return view('inc.subheader', [ 'socials'=> $socials]);

Setting a value for global variable in view that can be used in Controller Laravel 5.5

I am a beginner of Laravel. I reading the discussions on implementing global variables. But in my case, I want to set the value of the global variable from the view that can be used in the controller.
My sample code in button from adminHome.blade.php
<!--CAMPUS BUTTON-->
#foreach($campuses as $campus)
<div class="col-md-4">
<div class="card card-user box">
<div class="image" style="background-color:#00D27F;"></div>
<div class="content bg">
<div class="author">
<br><br><br><br><br><br>
<img class="" src="{{ asset('images/icon-school.png') }}" alt="..."/><br><br><br>
<h4 class="title"><b>{{$campus->campus_name}} Campus</b></h4>
{{--SOMEWHERE HERE I'LL SET THE VALUE OF THE GLOBAL VARIABLE. THE VALUE I SHOULD SET IS {{$campus->id}}--}}
<h5>{{$campus->name}} Campus</h5>
<hr>
<h5 class="title text-center">
</h5>
<a href="{{ route('dashboard') }}">
<p>VIEW</p>
</a>
</div>
</div>
</div>
</div>
#endforeach
As my code shown above, when I click that button, it would also set the value of the global variable so that in order to proceed on the next page, all the data related on that campus will only be shown. How can I do this? Thanks
May I got your Point#
there have no way to access variable from view to controller.
you can put variable in session. so that you can use from anywhere.
session(['your_key' => 'your_value']);
I think what you're looking for is when the user presses VIEW it opens the campus details yes?
In that case you can do:
{{ route('dashboard',['campus_id' => $campus->id]) }}
You are using a named route dashboard and you can pass in vars to that route with the above code.
Source: Laravel Named Routes Docs
You could either create and submit a form that will store the value in the back-end, in a database for example and later send the variable to the next view return view( 'next_page', ['variable' => $campus_id] );.
Or, you could just get the value from the form with some JS or jQuery magic and use GET variables to send it to the next page. http://example.com/next-page?variable=campus_id and echo it with {{ $_GET['variable'] }}

correct tab is not open when page is loaded

I am using codeigniter to make a web application, When the user registers with invalid credentials I am trying to reload my registration tab which is located on my authentication view, when the authentication view reloads my log in tab is displayed first because by default this is set to the active tab.
authentication view
<div class="row">
<div class="medium-12 columns">
<ul class="tabs" data-tabs id="authentication_tab">
<li class="tabs-title is-active">Login</li>
<li class="tabs-title">Sign Up</li>
</ul>
<div class="tabs-content" data-tabs-content="authentication_tab">
<div class="tabs-panel is-active" id="panel1">
<?php $this->load->view('authentication/login');?>
</div>
<div class="tabs-panel" id="panel2">
<?php $this->load->view('authentication/reg');?>
</div>
</div>
</div>
</div>
<?php $this->load->view('templates/footer');?>
loading my authentication view after validation has taken place
public function reg()
{
$data['title'] = 'Home Page';
$this->load->view('templates/header',$data);
$this->load->view('authentication/authentication#panel2');
}
In whatever controller you are using just decide (depending on the actions taken) which tab you want opened. Let us say the tab you want is 'thisOne', then pass a variable to your view, something like $open_tab='thisOne'.
In your view, before each tab, simply check the variable to see if it equals the current tab, and then set a class.
Use this:
<?php echo ('name_of_tab' == $open_tab) ? 'is_active' : ''; ?>
In your tab LI
<li class="tabs-title <?php echo ('name_of_tab' == $open_tab) ? 'is_active' : ''; ?>">Blah Blah</li>
In your controller you can set the default tab first, then overide that depending on users posts or actions etc.
Hope that helps,
Paul.

Categories