How to save foreach to variable in laravel? - php

I want to display these elements:
$category->getFullNameAttribute()
$category->id
$category->email
$category->image
Here is my view:
<div class="col-md-12">
<div class="card" style="padding: 20px; overflow: auto;">
<ul id="ul-data" style="display:none;">
#foreach ($categories as $category)
<li class="user-{{ $category->id }}">
{{ $category->getFullNameAttribute() }}
{{ $category->id }}
{{ $category->email }}
{{ $category->image }}
{{-- {{$category->representative}} --}}
#if (count($category->childes))
#include('management.orgchart.manageChild',['childs' => $category->childes])
#endif
</li>
#endforeach
</ul>
<div id="chart-container"></div>
However, when I display them in this way they are all going into the same div title or text.
I am getting big problems because I need it separate into more div because I want to display email at the bottom, the name at the top, id next to image and various other styling choices.
Does anyone know how I can put elements (id, email, image...) into different variables so I can easily manipulate them.
I appreciate your help and I will do everything to fix issues.
If I didn't explain something properly please ask me in comments and I will try my best to explain it in more detail.
Edit: This is controller for that method:
<?php
namespace App\Http\Controllers;
use App\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
class OrgController extends Controller
{
/**
* Display the OrgChart.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
Carbon::setLocale(App::getLocale());
if (Session::get('locked') === true) {
return redirect('/lock');
}
$categories = User::where('supervisor_id', '=', null)->get();
return view('management.orgchart.index', compact('categories'));
}
}
This is the model window which appears when pressing the right title of the names.
I want to put data into this div (first name, last name, email etc...):
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Profile Window</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="text-center">
<div class="img-container">
<img src="img/default-avatar.png" class="img-circle" id="circleImage" alt="Cinque Terre" />
</div>
</div>
<div class="text-center">
<div id="first_name" style="display: inline-block;">First name</div> <br>
<div id="last_name" style="display: inline-block;">Last name</div>
<div id="birthday">00.10.2020</div>
<div id="customer_email">hello#k-tronik.de</div>
<div id="representative_id">Representive Person</div>
<br>
</div>
<p id="contentWin">
{{-- #foreach($categories as $category)
<li class="user-{{ $user->id }}">
{{ $user->getId }}
#if (count($user->childes))
#include('management.orgchart.manageChild',['childs' => $category->childes])
#endif
</li>
#endforeach --}}
Using dummy content or fake information in the Web design process can result in products with unrealistic assumptions and potentially serious design flaws. A seemingly elegant design can quickly begin to bloat with unexpected content or break under the weight of actual activity. Fake data can ensure a nice looking layout but it doesn’t reflect what a
Lorem Ipsum actually is usefull in the design stage as it
Kyle Fiedler from the Design Informer feels that distracting copy is your fault:
If the copy becomes distracting in the design then you are doquestions about lorem ipsum don’t.
Summing up, if the copy is diverting attention from the design it’s because it’s not up to task.
Typographers of yore didn't come up with the concept ot on it. They will be drawn to it, fiercely. Do it the wrong way and draft copy can derail your design review.
Asking the client to pay no attention Lorem Ipsum ing you can't win. Whenever draft copy comes up in a meeting confused questions about it ensue.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
{{--<button type="button" class="btn btn-primary">Save changes</button>--}}
</div>
</div>
</div>
</div>

This might help you,
<div class="col-md-12">
<div class="card" style="padding: 20px; overflow: auto;">
<ul id="ul-data" style="display:none;">
#foreach($categories as $category)
<li class="user-{{ $category->id }}">
<span class="getFullNameAttribute">
{{ $category->getFullNameAttribute()}}
</span>
<span class="id">
{{ $category->id}}
</span>
<span class="email">
{{$category->email}}
</span>
<span class="image">
{{$category->image}}
</span>
<span class="representative">
{{--{{$category->representative}}--}}
</span>
#if(count($category->childes))
#include('management.orgchart.manageChild',['childs' => $category->childes])
#endif
</li>
#endforeach
</ul>
<div id="chart-container"></div>
</div>
You can change markup according to your needs,
and if you want to assign single category variable to other variable you can do this,
#php
$your_variable = $category;
#endphp

Related

how to add button on .php file by editing it

{!! view_render_event('bagisto.shop.layout.header.account-item.before') !!}
<login-header></login-header>
{!! view_render_event('bagisto.shop.layout.header.account-item.after') !!}
<script type="text/x-template" id="login-header-template">
<div class="dropdown">
<div id="account">
<div class="welcome-content pull-right" #click="togglePopup">
<i class="material-icons align-vertical-top">perm_identity</i>
<span class="text-center">
#guest('customer')
{{ __('velocity::app.header.welcome-message', ['customer_name' => trans('velocity::app.header.guest')]) }}!
#endguest
#auth('customer')
{{ __('velocity::app.header.welcome-message', ['customer_name' => auth()->guard('customer')->user()->first_name]) }}
#endauth
</span>
<span class="select-icon rango-arrow-down"></span>
</div>
</div>
<div class="account-modal sensitive-modal hide mt5">
<!--Content-->
#guest('customer')
<div class="modal-content">
<!--Header-->
<div class="modal-header no-border pb0">
<label class="fs18 grey">{{ __('shop::app.header.title') }}</label>
<button type="button" class="close disable-box-shadow" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" class="white-text fs20" #click="togglePopup">×</span>
</button>
</div>
<!--Body-->
<div class="pl10 fs14">
<p>{{ __('shop::app.header.dropdown-text') }}</p>
</div>
<!--Footer-->
<div class="modal-footer">
<div>
<a href="{{ route('customer.session.index') }}">
<button
type="button"
class="theme-btn fs14 fw6">
{{ __('shop::app.header.sign-in') }}
</button>
</a>
</div>
<div>
<a href="{{ route('customer.register.index') }}">
<button
type="button"
class="theme-btn fs14 fw6">
{{ __('shop::app.header.sign-up') }}
</button>
</a>
</div>
</div>
</div>
#endguest
#auth('customer')
<div class="modal-content customer-options">
<div class="customer-session">
<label class="">
{{ auth()->guard('customer')->user()->first_name }}
</label>
</div>
<ul type="none">
<li>
{{ __('shop::app.header.profile') }}
</li>
<li>
{{ __('velocity::app.shop.general.orders') }}
</li>
<li>
{{ __('shop::app.header.wishlist') }}
</li>
<li>
{{ __('velocity::app.customer.compare.text') }}
</li>
<li>
{{ __('shop::app.header.logout') }}
</li>
</ul>
</div>
#endauth
<!--/.Content-->
</div>
</div>
</script>
#push('scripts')
<script type="text/javascript">
Vue.component('login-header', {
template: '#login-header-template',
methods: {
togglePopup: function (event) {
let accountModal = this.$el.querySelector('.account-modal');
let modal = $('#cart-modal-content')[0];
if (modal)
modal.classList.add('hide');
accountModal.classList.toggle('hide');
event.stopPropagation();
}
}
})
</script>
#endpush
I have a php file for creating login page
it look like this page view
how to add a new login button like login with google by editing in it.
Please be detail while giving your answer, it is very helpful for those who are new in php.
It is better to provide general answers that is helpful for those who are working in other domain related to php.
This code belong to bagisto framework which is base on laravel.Bagisto is greate framework for creating ecommerce sites.
This is the repo of bagisto https://github.com/bagisto/bagisto.git
I am new to stackoverflow so feel free to improve my question for more clarity friends if need.
We have added social login in our master branch, you may take a pull from there. Below is the provided PR link
https://github.com/bagisto/bagisto/pull/3367
PS - as the user asked the questions regarding the platform bagisto that's why I am answering for that purpose.

expand / toggle div with display none from foreach with $ id

I have this:
#foreach($portfolios as $portfolio)
<div id="item-portfolio-expand{{$portfolio->id}}" class="item-portfolio-expand expand">
<div class="container">
<div class="row">
<div class="col-md-8">
col-md-8
</div>
<div class="col-md-4">
{{ __('Name')}}: {{ $portfolio->name }}
</div>
</div>
</div>
</div>
#endforeach
And this:
#foreach ($portfolios as $portfolio)
<div class="portfolio-item {{ $portfolio->tag }} " data-category="transition">
<img src="{{ $portfolio->image_show }}">
<a href="#item-portfolio-expand{{$portfolio->id}}" data-toggle="collapse" data-target="#item-portfolio-expand{{$portfolio->id}}" data-parent="#item-portfolio-expand{{$portfolio->id}}">
<div class="portfolio-item-overlay">
<p class="name-item-overlay">{{ $portfolio->name }}</p>
</div>
</a>
</div>
#endforeach
And when I press the in the first foreach, I want to toggle the second foreach at <div id = "item-portfolio-expand {{$ portfolio-> id}}" class = "item- portfolio-expand expand "> I just don't succeed at anything, I use bootstrap and jquery in the project. .item-portfolio-expand has display: none;
And at the same time when one is open and another is selected, to close the one already open and to appear the one selected with toggle.

Laravel 5.4 Displaying editing options in modal from view?

I have succesfully created an application within Laravel which allows users to edit posts for a item. The current method is by redirecting user to different page where they are able to make changes. However to increase the user expirence I was planning to add 'modal' within the page. Meaning that editing posts will happen within the same page. This method for me partly works. In a aspect that the last or the latest post is only editable post. If I click on any of the posts it makes me only make changes to the latest post. Any help, suggestions or examples are trully appreciated.
Below I have attached my show.blade.php which shows the item infromation and posts.
<ul class="list-group">
#foreach ($car->reviews as $review)
<li class="list-group-item">
<strong>
Created by: {{ $review->user->name}} {{ $review->created_at->diffForHumans() }}:
<br>
Updated by: {{ $review->user->name}} {{ $review->updated_at->diffForHumans() }}:
</strong>
<a href="/reviews/{{ $review->id }}/edit" data-toggle="modal" data-target="#myModal1" >{{ $review->reviewbody }}</a>
<a style="float:right;" href="/reviews/{{$review->id}}/delete">Delete</a>
#endforeach
The Modal
<div class="container">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal1">TEST</button>
<!-- Modal -->
<div class="modal fade" id="myModal1" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="review-edit">
<div class="review-edit-block">
{{ $review->reviewbody }}
<form action="/reviews/{{$review->id}}" method="POST">
{{ csrf_field() }}
{{ method_field('patch') }}
<div class="form-group">
<textarea style="position:relative;left:10%;width:375px;"name="reviewbody" class="form-control">{{ $review->reviewbody }}</textarea>
</div>
<div>
<button type="submit" class="btn btn-primary">Update Review</button>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
If the modal is included after the foreach loop, the variable $review will still be set to the value of the last item in the array.
An option is to use Javascript to handle the clicked link, set the specific data into the modal fields and then make the modal visible.
Example

Laravel 5.5 Method Links does not exist (Pagination) when applied to user model

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.

Forelse loop inside a <div> tag

I'm trying to make a container with a list of images and attributes, but when I add a tag around the array, the array simply go outside my container, I had searched this type of question but didn't find it.
This is the code:
#if(count($elitePublications) > 0)
<div style="border:2px gold solid">
#forelse($elitePublications as $key => $publication)
#include('publications.small', compact('publication'))
#empty
<p></p>
#endforelse
</div>
#endif
It only make the container but the list is outside
The code of publications.small:
<div class="col-sm-4 book">
<a href="{{ route('users.publications.show', ['publications'=>$publication->id, 'users'=>$publication->user->username]) }}">
<div class="book-cover">
{{ $publication->image }}
<div class="inner-book-content">
<h4>{{ $publication->published_book_title }}</h4>
<strong class="book-price">
</strong>
</div>
</div>
</a>
</div>
Thanks in advance.
The issue here is about Bootstrap. Some kind of problem with the columns and the rows (who guest the results), so I just added a class in my div called "row" it act as a container for my array.
Like:
<div class="row">
<h4 style="font-style: italic;"> Recomendados </h4>
#forelse($elitePublications as $key => $publication)
#include('publications.small', compact('publication'))
#empty
#endforelse
</div>

Categories