get data from clicked div in laravel 4.2 - php

hi i have this set of div for looped which contains data from the database here is how it looks like
here is my code to generate these divs
#foreach($NSAdata as $list)
{{ Session::put('isList' , 'true')}}
<div class="divcont">
<p>Filename : {{$list->filename}}</p>
<span>Size : {{$list->filesize}}</span>
#if($list->filetype == 'ppt' || $list->filetype == 'pptx')
<img src="{{ asset('img/ico/pptico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'doc' || $list->filetype == 'docx')
<img src="{{ asset('img/ico/wordico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'pdf')
<img src="{{ asset('img/ico/pdfico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'xls' || $list->filetype == 'xlsx')
<img src="{{ asset('img/ico/excelico.PNG') }}" class="imgicoII">
#elseif($list->filetype == 'txt')
<img src="{{ asset('img/ico/txtico.png') }}" class="imgicoII">
#elseif($list->filetype == 'csv')
<img src="{{ asset('img/ico/csvico.PNG') }}" class="imgicoII">
#endif
<br>
#if($list->thumbnail != 'n/a')
<img src="{{ asset('uploads/docs/thumb/' . $list->thumbnail ) }}" class="imgicoIII">
#else
<img src="{{ asset('uploads/docs/thumb/noThumb.png' ) }}" class="imgicoIII">
#endif
<br>
<a class="modal-trigger z-depth-1 btn dgray " href="#modFile">
Edit
</a>
<a href="{{URL::route('openfile', array($list->fileid))}}" class="btn dgray">
View
</a>
</div>
#endforeach
when the user clicked the edit button i trigger a modal with an id of modFile, it is supposed to display a modal where it contains the data from the clicked div im able to display the modal but im not displaying the correct data. here is my code for the modal
<div id="modFile" class="modal modal1size">
<div id="modal-header" class="z-depth-2 blue lighten-1">
</div>
<div class="modal-content">
<div class="row rowMarg">
<h6>Information.</h6>
#if(Session::has('isList'))
<h6>Filename : {{ $list->filename }} </h6>
<h6>File type : {{ $list->filetype }} </h6>
<?php $extension = "";?>
#if($extension == 'ppt' || $extension == 'pptx')
<img src="{{ asset('img/ico/pptico.PNG') }}" class="imgico">
#elseif($extension == 'doc' || $extension == 'docx')
<img src="{{ asset('img/ico/wordico.PNG') }}" class="imgico">
#endif
<h6>Size : {{ $list->filesize }} </h6>
<br>
#endif
</div>
</div>
<div class="modal-footer grey lighten-4">
<button type="submit" class="waves-effect waves-darkblue-1 btn-flat buttoninset">Submit</button>
Cancel
</div>
the thing is it just display wrong info any idea what i am doing wrong or how can i improve my code?

Related

Removeclass in foreach with jquery

when I click on a profile in the foreach loop, the "active" property of all "active" classes is deleted, not just the profile I clicked. How can I fix it so that only what I click is deleted? I do not want all "active" classes to be deleted, but only the active class property you clicked.
#foreach($other_user['details'] as $user)
#php
$user_id = Auth::user()->id;
$withid= $user->id;
$getunreadcount = \Models\Members::getlastconverunread($user_id,$withid);
#endphp
<a href="javascript:void(0);" data-conversation="{{$user->lastConver != null ? 'true' :'false'}}" data-id="{{ $user->username }}" #if($getunreadcount > 0) class="list-group-item list-group-item-action border-0 active userlink {{$user->lastConver != null ? ' ' :'hidden'}}" #else class="list-group-item list-group-item-action border-0 userlink {{$user->lastConver != null ? ' ' :'hidden'}}" #endif >
<div class="d-flex align-items-start">
#if($user->user_photo!='')
<img src="{{ url('/') }}/public/storage/users/{{ $user->user_photo }}" class="rounded-circle mr-1" alt="{{ $user->username }}" width="40" height="40">
#else
<img class="rounded-circle mr-1" width="40" height="40" src="{{ url('/') }}/public/img/no-user.png" alt="{{ $user->username }}" />
#endif
<div class="flex-grow-1 ml-3">
<span class="userName">
{{ $user->username }}
</span>
#if($getunreadcount > 0)
<div class="small unread"><span class="badge badge-warning">{{$getunreadcount}} Yeni Mesaj</span></div>
#endif
</div>
</div>
</a>
#endforeach
JQUERY:
$('.userlink').click(function(e) {
e.preventDefault();
var id = $(this).data("id");
var token = $("meta[name='csrf-token']").attr("content");
$('.userlink').removeClass('active');
var $this = $(this);
if (!$this.hasClass('active')) {
$this.removeClass('active');
}
});
I will be glad if you help me thank you.
$('.userlink').click(function(e) {
e.preventDefault();
...
// Like this:
$(this).removeClass('active');
});

Pictures not showins, seems considered as directories

I would like to show pictures on my website.
Here is the code of the view file :
#foreach($posts as $post)
<div class="w-full md:w-1/3 xl:w-1/4 p-6 flex flex-col">
<img src="{{asset("mvbimg/".$post->image)}}" >
<a href="/news/{{ $post->slug }}">
#if(!empty($post->image))
<img class="hover:grow hover:shadow-lg" src="{{ asset("mvbimg/".$post->image."")}}" alt="{{ $post->title }}">
#else
<img class="hover:grow hover:shadow-lg" src="https://www.example.com/img/nopic.jpg" alt="{{ $post->title }}">
#endif
<p style="text-align: center;">{{ $post->title }}</p></a>
</div>
#endforeach
And this is the frontend :
This is an URL of a picture upload on the server :
http://127.0.0.1:8000/mvbimg/202204171949lbc1.jpg
And this is my directory :

How to add a where condition with a variable to my controller?

I have a search function and I want to add a where condition for results.
Here is my view
#foreach($users as $user)
<li class="col-sm-4 col-xs-6 md-margin-bottom-30">
<div class="team-img">
#if((isset($user['profile_picture'])) && !empty($user['profile_picture']))
#if($user['facebook_id'] == 0)
<?php $img = "thumbnail/".$user['profile_picture']; ?>
#if(#getimagesize($img))
<img class="img-responsive profile-img margin-bottom-20" src="{{ url('ass/263/255?'.$img) }}" alt="">
#else
<?php $img = "assets/img/team/img10-md.jpg"; ?>
<img class="img-responsive" src="{{ url('ass/263/255?'.$img) }}" alt="">
#endif
#else
<?php $img = $user['profile_picture']; ?>
#if(#getimagesize($img))
<img class="img-responsive profile-img margin-bottom-20" src="{{ url('ass/263/255?'.$img) }}" alt="" >
#else
<?php $img = "assets/img/team/img10-md.jpg"; ?>
<img class="img-responsive" src="{{ url('ass/263/255?'.$img) }}" alt="">
#endif
#endif
#else
<?php $img = "assets/img/team/img10-md.jpg"; ?>
<img class="img-responsive" src="{{ url('ass/263/255?'.$img) }}" alt="">
#endif
<ul class="social-icons social-icons-color social-cu-icons" style="display:none;">
<div class="social-cu">
<li class="facebook_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
</li>
<li class="google_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
</li>
<li class="twitter_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
</li>
<li class="whatapp_share share_link" link="{{ url('') }}/{{ $user['username'] }}" name="{{ $user['username'] }}">
<img class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/Whatsapp.png') }}" alt="">
</li>
</div>
</ul>
<ul>
#if(Sentinel::check())
#if(!in_array($user['id'], $invitation))
<li class="sendinvitation" value="{{ $user['id'] }}" id="sendinvitation">
<a href="javascript:void(0)">
<i class="icon-custom icon-sm rounded-x fa fa-user-plus {{ $user['id'] }} " style="border-radius: 4px !important"></i>
</a>
</li>
#endif
#else
<li class="sendinvitation1" value="{{ $user['id'] }}" id="sendinvitation">
<a href="javascript:void(0)" onClick="return loginConf();">
<i class="icon-custom icon-sm rounded-x fa fa-user-plus {{ $user['id'] }} " style="border-radius: 4px !important"></i>
</a>
</li>
#endif
#if(Sentinel::check())
<li class="send-contact-message" data-username="{{ $user['username'] }}" data-user-id="{{ $user['id'] }}">
<i class="icon-custom icon-sm rounded-x fa fa-paper-plane-o" style="border-radius: 4px !important"></i>
</li>
#else
<li class="send-contact-message1" data-user-id="{{ $user['id'] }}">
<i class="icon-custom icon-sm rounded-x fa fa-paper-plane-o" style="border-radius: 4px !important"></i>
</li>
#endif
<li class="share-link"></i></li>
</ul>
</div>
<h3 style="margin-top: 20px !important;text-transform: none"><a href="{{ url('') }}/{{ $user['username'] }}">
#if($user['role'][0]['slug'] == "organizations")
<i style="font-size: 11px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
#else
<i style="font-size: 11px" class="icon-user"></i>
#endif
{{ $user['username'] }} </a></h3><p>
<strong><i class="icon-real-estate-020 u-line-icon-pro"></i> : </strong>{{ $user['country']['country'] }} <span class="{{ $user['country']['flag'] }}"></span><br>
#if(!empty($user['role']))
#if($user['role'][0]['slug'] == "organizations")
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong>{{ $user['industry']['industry'] }}<br>
#endif
#if($user['role'][0]['slug'] == "individuals")
<?php $career_path = array_reverse($user['career_path']); ?>
#if($career_path)
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong>{{ $career_path[0]['industry']['industry'] }}<br>
#else
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong><br>
#endif
#endif
#else
<strong><i class="icon-screen-tablet fa-" aria-hidden="true"></i> : </strong><br>
#endif
#if(!empty($user['role']))
#if($user['role'][0]['slug'] == "organizations")
<strong><i class="icon-frame fa-" aria-hidden="true"></i> : </strong>{{ $user['organization_type']['organization_type'] }}<br>
#elseif($user['role'][0]['slug'] == "individuals")
<?php $career_path = array_reverse($user['career_path']); ?>
#if($career_path)
#foreach($career_path as $careerpath)
<!-- <strong>Company:</strong>{{ $careerpath['company'] }}<br> -->
<strong><i class="icon-speedometer fa-" aria-hidden="true"></i> : </strong>{{ $careerpath['functions']['function'] }}
#break;
#endforeach
#else
<strong><i class="icon-speedometer fa-" aria-hidden="true"></i> : </strong>
#endif
#endif
#else
<strong><i class="icon-speedometer fa-" aria-hidden="true"></i> : </strong>
#endif
</p>
<br>
</li>
#endforeach
$users = User::with('country','industry','organization_type','career_path','career_path.industry','career_path.department','career_path.functions','role');
$private = DB::table('privacy_settings')->get();
$private = (array) $private;
$data['users'] = $users->orderBy('id', 'DESC')->skip($offset)->take($perPage)->get()->toArray();
So, with dd($private) I have an array with multiple values, but I need only value city. In my view I'm using a foreach function, and {{$private->city}} to display value of every user.
Now, I want to add something like that in $data['users'], if it's possible : where($private->city, '!=', 1) . That's should display only contacts with $private->city == 0 .
dd($data['users'])
array:12 [▼
0 => array:60 [▼
"id" => 559
"customer_stripe_id" => null
"username" => "Mihail22"
"name" => "Mihail22"
"first_name" => null
"last_name" => null
"dob" => "0000-00-00"
"city" => ""
"telephone" => ""
"address" => ""
"website1" => ""
Here city is the name of city
dd($private)
array:297 [▼
0 => {#954 ▼
+"id": "142"
+"user_id": "559"
+"email": "1"
+"website": "1"
+"phone": "1"
+"address": "1"
+"city": "1"
+"current_job": "1"
+"job_history": "1"
+"education_history": "1"
+"career_solutions": "1"
+"profile_updates": "0"
+"contacts_list": "1"
+"groups": "1"
}
1 => {#953 ▶}
Here city is for privacy ( 1 - public, 0 - private )
You can build a query that selects the user_id of all privacy_settings where city == 0. You can then add a WHERE IN to the $users query to limit it to only users with those ids by passing in the previous query being built:
$user_ids_query = DB::table('privacy_settings')
->where('city', 0)
->select('user_id');
$data['users'] = $users->whereIn('id', $user_ids_query)
->orderBy('id', 'DESC')
->skip($offset)
->take($perPage)
->get()
->toArray(); // to match what you expect
This looks like a good candidate for setting up a relationship and using what is available that way as well.
Try
$private = DB::table('privacy_settings')->where("city",0)->get();
print_r($private);
$data['users'] = $users->where("city",0)->orderBy('id', 'DESC')->skip($offset)->take($perPage)->get()->toArray();
print_r($data['users']);

Laravel make arguments optional in a File

<div class="images section clearfix">
<h4>Images</h4>
{!! Form::_image("image_id", "Logo", (isset($_tournament))? $_tournament->logo : null) !!}
{!! Form::_image("image_large_id", "Large Logo", (isset($_tournament))? $_tournament->logoLarge : null) !!}
{!! Form::_image("image_square_id", "Square Logo", (isset($_tournament))? $_tournament->logoSquare : null) !!}
#endif
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-6">
<p>
{!! Form::hidden($name, null, ["id" => $name]) !!}
#if(isset($image))
<img width=100 id="{{ $name }}" src="{!! staticFileUrl('img', imagePath($image->folder, $image->filename)) !!}" />
#else
<img width=100 id="{{ $name }}" src="" />
#endif
</p>
<p>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#media_select" data-fieldname="{{ $name }}">Select {{ $display_name }}</button>
<button type="button" class="btn btn-default" id="clear-media">Clear {{ $display_name }}</button>
</p>
</div>
</div>
<script type="text/javascript">
$("button#clear-media").click(function() {
$form_element = $(this).parents("div.form-group");
$form_element.find("input#{{ $name }}").val(null);
$form_element.find("img#{{ $name }}").attr("src", "");
});
</script>
I got a thrown into a laravel project and I have no experience in PHP so I have no idea to fix this.
I need to add a default image for these fields and I just wonder is there a way to make all arguments optional staticFileUrl('img', imagePath($image->folder, $image->filename) optional so I can write something like this staticFileUrl('img', imagePath("random string", "other random string")?
Those already are variables based on the values set in the $image model.
If all you need is a default, change the #else
#if(isset($image))
<img width="100" id="{{ $name }}" src="{!! staticFileUrl('img', imagePath($image->folder, $image->filename)) !!}" />
#else
<img width="100" id="{{ $name }}" src="http://www.example.org/your-image.jpg" />
#endif
It currently displays nothing if there is no image object. Adding the src and an image will display that as your default unless it has an image.

laravel/blade cycle in template

I need your help. Here is my template file. How can I make to work that template? Main problem is that I don't know how to change div class values. Now I can make working only <div class="thumb-left"> but I also need <div class="thumb-middle"> and <div class="thumb-right">.
Thank you.
#extends('_layouts.main')
#section('content')
<div id="content-section">
#foreach ($uploads as $upload)
<div class="thumb-left">
<img alt="{{ $upload->image_title }}" title="{{ $upload->image_title }}" src="/files/images/{{ $upload->imagefile }}" height="250" width="300">
<div class="thumb-info">
{{ $upload->image_title }}
<a class="cat" href="#">PHOTOS</a>
</div>
</div>
#endforeach
<div class="thumb-middle">
<img alt="sunset" title="Sunset HDR" src="img/thumb.jpg" height="250" width="300">
<div class="thumb-info">
{{ $upload->image_title }}
<a class="cat" href="#">PHOTOS</a>
</div>
</div>
<div class="thumb-right">
<img alt="sunset" title="Sunset HDR" src="img/thumb.jpg">
<div class="thumb-info">
City Sunset HDR
<a class="cat" href="#">PHOTOS</a>
</div>
</div>
</div>
#stop
You could do:
#foreach ($uploads as $upload)
<div class="thumb-{{ array('left', 'middle', 'right')[($loop->iteration-1)%3] }}">
<img alt="{{ $upload->image_title }}" title="{{ $upload->image_title }}" src="/files/images/{{ $upload->imagefile }}" height="250" width="300">
<div class="thumb-info">
{{ $upload->image_title }}
<a class="cat" href="#">PHOTOS</a>
</div>
</div>
#endforeach
The $loop variable is a build in blades variable - check the docs:
When looping, a $loop variable will be available inside of your loop.
This variable provides access to some useful bits of information such
as the current loop index and whether this is the first or last
iteration through the loop. For instance: $loop->iteration - the current loop
iteration (it starts at 1).
You probably want to change your foreach to also use a key, so you can know at which index in your array you are:
<div id="content-section">
#foreach ($uploads as $index => $upload)
<div class="thumb-left">
<img alt="{{ $upload->image_title }}" title="{{ $upload->image_title }}" src="/files/images/{{ $upload->imagefile }}" height="250" width="300">
<div class="thumb-info">
{{ $upload->image_title }}
<a class="cat" href="#">PHOTOS</a>
</div>
</div>
#endforeach
</div>
Now, if I understand properly, what you're looking for is to switch from thumb-left, to thumb-middle and then finally thumb-right, and then loop again. You could use modulo to assign your class name based on the current index. This is untested code but you could probably use something along the lines of:
<div id="content-section">
{{ $classnames = array("thumb-left", "thumb-middle", "thumb-right"); }}
#foreach ($uploads as $index => $upload)
<div class="{{ $classnames[$index % count($classnames)] }}">
<img alt="{{ $upload->image_title }}" title="{{ $upload->image_title }}" src="/files/images/{{ $upload->imagefile }}" height="250" width="300">
<div class="thumb-info">
{{ $upload->image_title }}
<a class="cat" href="#">PHOTOS</a>
</div>
</div>
#endforeach
</div>

Categories