How Jump to with collections of data in laravel - laravel-5

I'm implementing the Jump to... functionality in my project. What I want is:
If the user is in the first item the left button is NOT included.
If the user is in the last item the right button is NOT included.
The left button should have a link same with the link before the current/selected item.
The right button should have a link same with the link after the current/selected item.
Please see my code below:
Controller
$course = Course::with([
'assignments' => $undeleted,
'quizzes' => $undeleted,
'add_links' => $undeleted
])->findOrFail($id);
$course_items = collect($course->assignments);
$course_items = $course_items->merge(collect($course->quizzes));
$course_items = $course_items->merge(collect($course->add_links));
$course_items = $course_items->sortBy('item_number');
View
<div class="jump-to">
<div class="pull-right">
<div class="btn-group" role="group">
#foreach($course->topics as $topic)
#foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortBy('item_number') as $first_item)
#if($first_item->id != $assignment->id)
<a href="#" class="btn btn-primary">
<i class="fa fa-angle-left"></i>
</a>
#endif
<?php break 2; ?>
#endforeach
#endforeach
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Jump to <div class="caret"></div>
</button>
<ul class="dropdown-menu" role="menu">
#foreach($course->topics as $topic)
<li class="jdivider">
Topic {{ $topic->topic_number }}
</li>
#foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortBy('item_number') as $topic_item)
<li>
#if($topic_item->item_type() == 'assignment')
<a title="Assignment: {{ $topic_item->name }}" class="regular-link" href="{{ route('assignment.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}">
<i class="fa fa-tasks"></i> {{ str_limit($topic_item->name, 15) }}
</a>
#elseif($topic_item->item_type() == 'quiz')
<a title="Quiz: {{ $topic_item->name }}" class="regular-link" href="{{ route('quiz.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}">
<i class="fa fa-file-text"></i> {{ str_limit($topic_item->name, 15) }}
</a>
#elseif($topic_item->item_type() == 'add_link')
<a href="#">
#if(!empty($topic_item->file_location) && in_array(strtolower(last(explode('.', $topic_item->file_location))), ['pdf', 'docx', 'doc']))
<i class="fa fa-file-pdf-o"></i>
#elseif(empty($topic_item->file_location))
<i class="fa fa-globe"></i>
#else
<i class="fa fa-file-text-o"></i>
#endif
{{ str_limit($topic_item->name, 15) }}
</a>
#endif
</li>
#endforeach
#endforeach
</ul>
</div>
<a href="#" class="btn btn-primary">
<i class="fa fa-angle-right"></i>
</a>
</div>
</div>
</div>
Example
dropdown links:
Assignment1
Assignment2
Quiz1
QUiz2
Reviewer1
If I clicked Assignment2, the left button, has the id or link to Assignment1. If I clicked Reviewer1, the right button disappears and the left button has the id or link to Quiz2 and same with the other links.

Related

laravel set locate currently from web routes

why I can't setlocale from file web.php routes, this's code:
Route::get('language/{lang}', function ($lang) {
App()->setLocale($lang);
session()->put('locale', $lang);
return redirect()->back();
})->name('langroute');
and this one is menu select:
<li class="nav-item btn-rotate dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLang" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img width="25" src="{{ asset('assets_front/images/'.App::getLocale().'.png') }}" class="img-responsive img-bandera" alt="#lang('idioma') #lang('navigation.languages-'. App::getLocale())">
<p>
<span class="d-lg-none d-md-block">{{ trans_choice('words.idioma', 1) }}</span>
</p>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLang">
#foreach (Config::get('app.languages') as $language)
#if ($language != App::getLocale())
<a class="dropdown-item" href="{{ route('langroute', $language) }}">
<img width="25" src="{{ asset('assets_front/images/'.$language.'.png') }}" class="img-responsive img-bandera" alt="#lang('idioma') #lang('navigation.languages-'. App::getLocale())">
#lang('navigation.languages-'. $language)
</a>
#endif
#endforeach
</div>
</li>
what I'm wrong?

Laravel - How to Display Submit Edit and Delete based on is_approved

I have this code in my Laravel-5.8
public function index()
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$identities = DB::table('appraisal_identity')->select('id')->where('company_id', $userCompany)->where('is_current', 1)->first();
$goals = AppraisalGoal::where('employee_id', $userEmployee)->where('appraisal_identity_id', $identities->id)->get();
return view('appraisal.appraisal_goals.index')->with('goals', $goals);
}
view
<td>
#if ($goal->is_approved == 3)
<span class="badge bg-success" >Approved</span>
#elseif ($goal->is_approved == 2)
<span class="badge bg-danger">Not Approved</span>
#elseif ($goal->is_approved == 1)
<span class="badge bg-info">Awaiting Approval</span>
#else
<span class="badge bg-black">Draft</span>
#endif
</td>
<td>
#can('appraisal_goal_show')
<a class="btn btn-xs btn-primary" href="{{ route('appraisal.appraisal_goals.show', $goal->id) }}">
{{ trans('global.view') }}
</a>
#endcan
#can('appraisal_goal_edit')
<a class="btn btn-xs btn-info" href="{{ route('appraisal.appraisal_goals.edit', ['id'=>$goal->id]) }}">
{{ trans('global.edit') }}
</a>
#endcan
#can('appraisal_goal_delete')
<button class="btn btn-xs btn-danger" type="submit" onclick="deleteTag({{ $goal->id }})">
Delete
</button>
<form id="delete-form-{{ $goal->id }}" action="{{ route('appraisal.appraisal_goals.destroy',$goal->id) }}" method="POST" style="display: none;">
#csrf
#method('DELETE')
</form>
#endcan
</td>
<div class="col-12">
<i class="fas fa-arrow-right"></i> Submit
</div>
I want to apply this conditions.
Edit should only be visible when is_approved = 1 or 2 or 3
Delete should only be visible when is_approved = 0 or 2
Submit button should only be visible when is_approved = 1 or 2
How do I achieve these?
Thanks
You may nest each of your buttons inside an #if and check is_approved value with in_array function:
#if(in_array($goal->is_approved, [1, 2, 3]))
#can('appraisal_goal_edit')
<a class="btn btn-xs btn-info" href="{{ route('appraisal.appraisal_goals.edit', ['id'=>$goal->id]) }}">
{{ trans('global.edit') }}
</a>
#endcan
#endif
You may do the same for delete and submit buttons and just change the 2nd argument of in_array.

Set class on Parent and Sub-Menu in Laravel Bade View

I want to set m-menu__item--open class on parent menu <li> and m-menu__item--active class on sub-menu item <li> in my Laravel bade based on current page. Below is the HTML extracted from the bade template.
<li class="m-menu__item m-menu__item--open" aria-haspopup="true" m-menu-submenu-toggle="hover">
<a href="javascript:;" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-layers"></i>
<span class="m-menu__link-text">FAQ</span>
<i class="m-menu__ver-arrow la la-angle-right"></i>
</a>
<div class="m-menu__submenu " m-hidden-height="840">
<span class="m-menu__arrow"></span>
<ul class="m-menu__subnav">
<li class="m-menu__item m-menu__item--active" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/1" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">English</span>
</a>
</li>
<li class="m-menu__item m-menu__item" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/2" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">Korean</span>
</a>
</li>
<li class="m-menu__item m-menu__item" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/3" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">Chinese</span>
</a>
</li>
</ul>
</div>
</li>
as I understand, you want to change your menu classes by the current url..
laravel has is() method in Request class. You may want to use it.
class="{{Request::is('category/products') ? 'm-menu__item--active' : 'm-menu__item--open'}}"
if your current url base-url/category/products then you're gonna get the 'm-menu__item--active' class

bllim / laravel4-datatables-package -> get the id from the query

I'm trying to get the ID from the query when I use edit_column but I get it only for the 'id' column, when I try to get it for the 'operations' column I get the html markup of the 'id' column.
Here is the code:
public function ajaxGetAllPages()
{
$pages = Page::select(array('id','title','updated_at','status'));
return Datatables::of($pages)
->edit_column('id', '<input type="checkbox" class="checkboxes tooltips" value="{{ $id }}" data-placement="left" data-original-title=" אינדקס # {{ $id }} " />')
->edit_column('title','{{ $title }}')
->edit_column('updated_at', '{{ date("d-m-Y | H:i",strtotime($updated_at)) }}')
->edit_column('status', '{{ $status }}')
->edit_column('operations',
'<i class="fa fa-pencil"></i>
<i class="fa fa-trash-o"></i>
<i class="fa fa-times"></i>
<div class="btn-group">
<button class="btn default btn-xs dropdown-toggle" type="button" data-toggle="dropdown">עוד <i class="fa fa-angle-down"></i></button>
<ul class="dropdown-menu pull-right" role="menu">
<li>פעולה</li>
<li>פעולה</li>
</ul>
</div>'
)
->make();
}
Markup result - http://screencast.com/t/nIefrpqc8
Am I doing something wrong or is it a bug?
Thanks,
Chen
According to Bllim docs:
If you use double quotes while giving content of add_column or edit_column, you should escape variables with backslash () else you get error. For example:
edit_column('id',"- {{ \$id }}")
Use backslash before $id.
->edit_column('operations',
'<i class="fa fa-pencil"></i>
<i class="fa fa-trash-o"></i>
<i class="fa fa-times"></i>
<div class="btn-group">
<button class="btn default btn-xs dropdown-toggle" type="button" data-toggle="dropdown">עוד <i class="fa fa-angle-down"></i></button>
<ul class="dropdown-menu pull-right" role="menu">
<li>פעולה</li>
<li>פעולה</li>
</ul>
</div>'
)

Laravel 4 base/master view

I've recently gotten some problems. There is an model from which I pull some data and things. There is a menu link that I want to be on every page I enter, so I've put it into the base/master view. But the problem is, I need to enter ->with blabla thing on every public function in every controller. How could I not do that? I mean is there anyway around it? I don't want to do that with thingy on every controller method/function. Here's my code:
#if ( Auth::guest() )
<li style="float: right;padding-right: 0">
<ul class="nav">
<li>
<a href="{{ URL::to('register') }}">
<i class="icon-black icon-plus">
</i>
<strong>
Register
</strong>
</a>
</li>
<li>
<a href="{{ URL::to('login') }}">
<i class="icon-black icon-lock">
</i>
<strong>
Log in
</strong>
</a>
</li>
</li>
</li>
</ul>
#else
<li class="divider-vertical">
</li>
<li style="float: right;padding-right: 0">
<div class="btn-group">
<div class="btn btn-primary">
<i class="icon-user">
</i>
{{ (Auth::user()->name) }}
</div>
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
<span class="icon-caret-down">
</span>
</a>
<ul class="dropdown-menu">
<li>
<a href="{{ URL::to('account/managment') }}">
<i class="icon-user">
</i>
Account Managment
</a>
</li>
<li>
<a href="{{ URL::to('account/managment/change_credentials') }}">
<i class="icon-lock">
</i>
Change Password
</a>
</li>
<li class="divider">
</li>
<li>
<a href="{{ URL::to('account/logout') }}">
<i class="icon-off">
</i>
Log out
</a>
</li>
</ul>
</div>
#endif
You can define a View Composer :
View::composer(array('your.first.view','your.second.view'), function($view)
{
$view->with('count', User::count());
});
Everytime you call your view, a user count will be bound to it automatically.
Edit:
About where to use it, it's up to you and it depends on your app, but you might use pp/start/global.php if you don't have a better place to put it. It just have to be executed before your those views.
#Antonio's answer is a good way to do this. You can also use View::share(); to accomplish this with a shorter code.
View::share(array(
'foo' => 'bar'
));

Resources