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.
Related
I'm getting this error when clicking a button on my dashboard
And this error only happens in the customization part, in other sections everything works fine
It gives me the solution below but I don't know how to apply
$name is undefined
Make the variable optional in the blade template. Replace {{ $name }} with {{ $name ?? '' }}
Undefined variable $name (View: /home/dir/mysite.com/resources/views/admin/settings/personalization.blade.php)
#push('styles_top')
#endpush
#section('content')
<section class="section">
<div class="section-header">
<h1>{{ trans('admin/main.personalization') }} {{ trans('admin/main.settings') }}</h1>
<div class="section-header-breadcrumb">
<div class="breadcrumb-item active">{{ trans('admin/main.dashboard') }}</div>
<div class="breadcrumb-item active">{{ trans('admin/main.settings') }}</div>
<div class="breadcrumb-item ">{{ trans('admin/main.personalization') }}</div>
</div>
</div>
<div class="section-body">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
#php
$items = ['page_background','home_sections','home_hero','home_hero2','home_video_or_image_box',
'panel_sidebar','find_instructors','reward_program','become_instructor_section',
'theme_colors', 'theme_fonts', 'forums_section', 'navbar_button','cookie_settings','mobile_app',
'others_personalization'
]
#endphp
<ul class="nav nav-pills" id="myTab3" role="tablist">
#foreach($items as $item)
<li class="nav-item">
<a class="nav-link {{ ($item == $name) ? 'active' : '' }}" href="/admin/settings/personalization/{{ $item }}">{{ trans('admin/main.'.$item) }}</a>
</li>
#endforeach
</ul>
<div class="tab-content">
#include('admin.settings.personalization.'.$name,['itemValue' => (!empty($values)) ? $values : ''])
</div>
</div>
</div>
</div>
</div>
</div>
</section>
#endsection
#push('scripts_bottom')
#endpush
I've tried several solutions suggested in other posts, but none worked.
What's wrong?
IN:
/home/dir/mysite.com/resources/views/admin/settings/personalization.blade.php)
error: You have not any variable $name.
Solution:
check that into controller, you are sending variable with view file?
return view('file_path')->with("name", $valueVariable);
return view("file_path".["name" => $valueVariable]);
I have two tables name is courses and admissions. Now i want to set if user purchase the course then show admitted else show course price. please check the below code:
$courses = Course::orderby('id', 'desc')->get();
$admission = Admission::where('users_id', Auth::user()->id)->first() ?: app(Admission::class);
return view('Backend.Student.courses', compact('courses', 'admission'));
here is my condition in blade file:
#if( $course->id == $admission->courses_id )
<li class="list-inline-item">
<h5 class="p-0 m-0 text-white"> {{ __('Admitted') }}</h5>
</li>
#if( !empty($admission->status == 'active') )
<li class="list-inline-item">
<h5 class="p-0 m-0 text-white"> {{ __('Continue Course') }}</h5>
</li>
#endif
#else
<li class="list-inline-item">
<h5 class="p-0 m-0 text-white"> {{ __('Admission Now') }}</h5>
</li>
<li class="list-inline-item">{{ __('Price') }}: ৳{{ number_format( $course->price , 0 , '.' , ',' ) }} BDT</li>
#endif
This course is working but its showing only one course. When same user purchage multiple course it will show only one course is admitted. But i want if a user purchases multiple courses it should be shown admitted each course. Sorry for my bad english and thanks for your kindness.
You are fetching just the first record for admissions, hence there will be only one record.
To get all Admission records for the currently logged in user
$courses = Course::latest('id')->get();
$admissions = Admission::where('user_id', Auth::id())->get();
return view('Backend.Student.courses', compact('courses', 'admissions'));
In blade view, you loop over the user's admissions
#foreach($courses as $course)
{{-- If the user has purchased course --}}
#if(in_array($course->id, $admissions->pluck('course_id')->toArray())
#foreach($admissions as $admission)
{{-- If the course is active --}}
#if($admission->course_id === $course->id && $admission->status === 'active')
<li class="list-inline-item">
<h5 class="p-0 m-0 text-white"> {{ __('Continue Course') }}</h5>
</li>
#elseif($admission->course_id === $course->id && $admission->status !== 'active')
{{-- If the course is not active --}}
<li class="list-inline-item">
<h5 class="p-0 m-0 text-white"> {{ __('Admitted') }}</h5>
</li>
#endif
#endforeach
#else
{{-- User has not purchased the course --}}
<li class="list-inline-item">
<h5 class="p-0 m-0 text-white"> {{ __('Admission Now') }}</h5>
</li>
<li class="list-inline-item">{{ __('Price') }}: ৳{{ number_format( $course->price , 0 , '.' , ',' ) }} BDT</li>
#endif
#endforeach
I'm blocked for organize my sub-menu of my menu. As you can see,
it is decomposed into several blocks (i've use paint for delimited the block in black).
currently my code is:
<li class="dropdown yamm-fw">
{{ $category->nom }} <b class="caret"></b>
<ul class="dropdown-menu">
<li>
<div class="yamm-content">
<div class="row">
<div class="col-sm-3">
<h5>test</h5>
<ul>
<?php $count=0 ?>
#foreach ($types->whereIn('id', $category->produit->unique('type_id')->pluck('type_id')) as $type)
#if ($count <= 6)
<li>{{$type->nom}}</li>
<?php $count++ ?>
#endif
#endforeach
</ul>
</div>
<div class="col-sm-3">
<h5>teste 2</h5>
<ul>
<li>Trainers</li>
<li>Sandals</li>
<li>Hiking shoes</li>
<li>Casual</li>
</ul>
</div>
I do not know how to do that after 7 items in the actual div col-sm-3, create another div to continue the foreach and so on.
You can use the $loop variable:
#if ($loop->iteration === 7)
// Create another div here
#endif
I was working on my website and I logged out to test it and it gave me this error:
Trying to get property of non-object (View: C:\xampp\htdocs\mom\a\app\views\home.blade.php)
Here is my home.blade.php:
#extends('layout.main')
#section('title') Home #stop
#section('content')
<!-- User signed in -->
#if(Auth::check())
<!-- User is not admin -->
<p>Welcome back, {{ Auth::user()->username }}.</p>
#else
<!-- Nothing -->
#endif
#if($posts->count())
#foreach($posts as $post)
<article class="col-md-8 col-md-push-2 well well-white home-posts">
<h2 class="title">{{ $post->title }}</h2>
<hr class="post-break">
<h4 class="home-content">{{ Markdown::parse(Str::limit($post->body, 300)) }}</h4>
<div class="post-footer">
<ul class="footer-group">
<ul>
<li>Published {{ $post->created_at->diffForHumans() }}</li>
<li> Read more →</li>
</ul>
#if(Auth::user()->group ==1)
<ul class="footer-right">
<li class="red"><i class="fa fa-trash"></i> Delete</li>
<li><i class="fa fa-gear"></i> Edit</li>
</ul>
#else
<!-- Nothing -->
#endif
</ul>
</div>
</article>
#endforeach
#endif
<div class="col-md-8 col-md-push-2 ">{{ $posts->appends(array())->links() }}</div>
#stop
If someone could help me find out what property is of the non object is being called and help me fix it. That would be great. Much appreciated.
You should put this line
<div class="col-md-8 col-md-push-2 ">{{ $posts->appends(array())->links() }}</div>
in your if statement
EDIT:
Try to change line:
#if(Auth::user()->group ==1)
to
#if(Auth::check() && Auth::user()->group ==1)
I am building a menu on laravel.
In blade layout i have:
#foreach ($menu1 as $menu1)
{{$menu1->nome}}
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
<span class="glyphicon glyphicon-chevron-down"></span>
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
<ul class="list-unstyled">
#foreach ($menu2 as $menu2)
<li> {{$menu2->nome}} </li>
#endforeach
</ul>
</div>
</div>
</div>
#endforeach
in my controller i pass 2 query.
public function menu($lingua)
{
return View::make('index', ['menu1'=>DB::table('cat_nome')->join('lingua', 'cat_nome.id_lingua', '=', 'lingua.id') ->where('lingua.lingua','=',$lingua)->get(array('cat_nome.nome')),
'menu2' => DB::table('campo_nome')->join('lingua', 'campo_nome.id_lingua', '=', 'lingua.id') ->where('lingua.lingua','=',$lingua)->get(array('campo_nome.nome'))]
);
}
I tried to UNnest the foreach and everything works fine. When i try to nest the foreach i get
Trying to get property of non-object
#foreach ($menu2 as $menu2)
That line is most likely the culprit. You cannot use the same variable name twice in a foreach loop like that and expect good results. The second one is supposed to be what each entry in $menu2 will be scoped to during each iteration of the loop.
See the foreach documentation
Try changing the loop to look more like this:
#foreach ($menu2 as $innerMenu)
<li> {{$innerMenu->nome}} </li>
#endforeach
I would suggest doing the same thing for your outer menu as well.