Laravel Fullcalendar 5.5 - php

i'm trying to implement Laravel FullCalendar with help of (https://github.com/maddhatter/laravel-fullcalendar)
My controller code -
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Calendar;
use App\Event;
class EventController extends Controller
{
public function index()
{
$events = [];
$data = Event::all();
if($data->count()) {
foreach ($data as $key => $value) {
$events[] = Calendar::event(
$value->title,
true,
new \DateTime($value->start_date),
new \DateTime($value->end_date.' +1 day'),
null,
// Add color and link on event
[
'color' => '#f05050',
'url' => 'pass here url and any route',
]
);
}
}
$calendar = Calendar::addEvents($events);
return view('fullcalender', compact('calendar'));
}
}
Blade File -
#extends('layouts.app')
#section('style')
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
#endsection
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Full Calendar Example</div>
<div class="panel-body">
{!! $calendar->calendar() !!}
</div>
</div>
</div>
</div>
</div>
#endsection
#section('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar->script() !!}
#endsection
I m sharing calendar event creation code.
$calendar = \Calendar::addEvents($events) //add an array with addEvents
->addEvent($eloquentEvent, [ //set custom color fo this event
'color' => '#800',
])->setOptions([ //set fullcalendar options
'firstDay' => 1
])->setCallbacks([ //set fullcalendar callback options (will not be JSON encoded)
'eventClick' => 'function() {
showModal();
}'
]);
everything work fine, but i need to open pophover (custom html) on click of event. as i had implemented same thing with JS fullcalendar (https://codepen.io/IsmiKin/pen/WbOeGw).
Any suggestion is appreciated. Thanks in advance.

Just add eventRender to the setCallbacks() method. I assumed you are using bootstrap 4.
$calendar = Calendar::addEvents($e)->setCallbacks([
'themeSystem' => '"bootstrap4"',
'eventRender' => 'function(event, element) {
element.popover({
animation: true,
html: true,
content: $(element).html(),
trigger: "hover"
});
}'
]);

Related

Livewire Powergrid with Laravel - how to create a alert/confirmation after "Delete" button click?

I'm using Laravel with TailwindCSS, so I assume that, the SweetAlert wouldn't work.
I'm also using Livewire Powergrid, which works fine, but I don't know how to emit simple alert window after clicking f.e. "Delete" button.
Inside actions method, there's option emit() but I really don't know what it does.
Button::make('destroy', 'Delete')
->class('bg-red-500 cursor-pointer text-white px-3 m-1 rounded text-sm hover:bg-red-800')
->emit(),
What does it call and where? Should I put emited method inside UsersTable(powergrid component) or somewhere else?
Can someone explain? There's other possibility to achieve the alert window with confirmation?
You have to pass the method name within emit and that method has to be defined in the same class (I am using PowerGrid Component), example :
// rowActionEvent is my method name and the second parameter is data array which has to be passes ad parameter to rowActionEvent method
Button::make('destroy', 'Delete')
->class('bg-red-500 cursor-pointer text-white px-3 m-1 rounded text-sm hover:bg-red-800')
->emit('rowActionEvent', ['id' => 'id']),
In the same class, define the method also
protected function getListeners()
{
return array_merge(
parent::getListeners(),
[
'rowActionEvent',
]);
}
public function rowActionEvent(array $data): void
{
$message = 'You have clicked #' . $data['id'];
$this->dispatchBrowserEvent('showAlert', ['message' => $message]);
}
In the frontend (blade file or the view file) define the showAlert javascript.
<script>
window.addEventListener('showAlert', event => {
alert(event.detail.message);
})
</script>
In my case , I had to add both the event and the listener to the mother component , instead of the PowerGrid class (cause it was not working )
Inside Powergrid class (UserTable) , I have these buttons inside actions function
public function actions(): array
{
return [
Button::make('edit', 'Edit')
->class('btn btn-info')
->route('admin.users.edit', ['userId' => 'id']),
Button::make('destroy', 'Delete')
->class('btn btn-danger')
->emit('deleteUser', ['key' => 'id']),
];
}
Livewire Mother Component
class Users extends Component
{
public $userId ;
use LivewireAlert;
protected $listeners = ['deleteUser' , 'confirmDelete'];
public function deleteUser($userId){
$this->userId = $userId['userId'];
$this->alert('warning', 'Are you sure , you want to delete this user ? ' , [
'icon'=>'warning',
'showConfirmButton' => true,
'showCancelButton' => true,
'confirmButtonText' => 'Delete',
'cancelButtonText' => 'Cancel',
'onConfirmed' => 'confirmed',
'allowOutsideClick' => false,
'timer' => null ,
'position' => 'center',
'onConfirmed' => 'confirmDelete'
]);
}
Public function confirmDelete(){
Admin::destroy($this->userId);
$this->flash('success', 'User Successfully deleted', [
'position' => 'center',
'timer' => 3000,
'toast' => false,
'icon' => 'success',
], '/admin/users');
}
public function render()
{
return view('livewire.admin.users')->layout('layouts.admin.admin-template');
}
}
Livewire Mother Component Blade
<div>
<div class="row mb-2">
<div class="col-6 d-flex align-items-center">
<h3 class="mb-0">Users {{ $userId }}</h3>
</div>
<div class="col-6 text-end">
<a class="btn bg-gradient-dark mb-0" href="{{
route('admin.users.create') }}"><i class="fas fa-plus"></i> Add
New User</a>
</div>
</div>
<div class="col mb-3">
<div class="card">
<div class="card-body p-3">
<livewire:admin-table/>
</div>
</div>
</div>
</div>
sample image 1
I used Livewire Alert package

CRUD Backpack Laravel . Graph update, when Ajax Filter get changed

kindly avoid giving me negative reviews Thanks
in Laravel Backpack admin, when we click on Date Range filters , it's Filtering our table data, that is working fine, but I want Graph also get changed when we change ajax filters.
as per I know, ajax Date Range filter code in CrudConTroller :
$this->crud->addFilter([
'type' => 'date_range',
'name' => 'created_at',
'label' => 'Date range'
],
false,
function ($value) { // if the filter is active, apply these constraints
$dates = json_decode($value);
$this->crud->addClause('where', 'created_at', '>=', $dates->from);
$this->crud->addClause('where', 'created_at', '<=', $dates->to . ' 23:59:59');
});
and graph is coming in widget, blade templating file : list.blade.php .
$widgets['before_content'][] = [
'type' => 'div',
'class' => 'row',
'content' => [ // widgets
[
'type' => 'chart',
'wrapperClass' => 'mt-4 col-md-12',
// 'class' => 'col-md-12',
'controller' => \App\Http\Controllers\Admin\Charts\UserChartController::class,
'content' => [
'header' => 'New Users', // optional
'body' => 'This chart should make it obvious', // optional
]
],
],
]
I needed this exact thing too. Quite hacky, but what I did was create a new filter, starting from the date_range filter, that instead of refreshing only the datatables, refreshes the entire page.
Here it is. If you place it in resources/views/vendor/backpack/crud/filters/date_range_refresh.blade.php you'll be able to use date_range_refresh instead of date_range as the filter type, and get the results you want:
{{-- Date Range Backpack CRUD filter --}}
<li filter-name="{{ $filter->name }}"
filter-type="{{ $filter->type }}"
filter-key="{{ $filter->key }}"
class="nav-item dropdown {{ Request::get($filter->name)?'active':'' }}">
{{ $filter->label }} <span class="caret"></span>
<div class="dropdown-menu p-0">
<div class="form-group backpack-filter mb-0">
<div class="input-group date">
<div class="input-group-prepend">
<span class="input-group-text"><i class="la la-calendar"></i></span>
</div>
<input class="form-control pull-right"
id="daterangepicker-{{ $filter->key }}"
type="text"
#if ($filter->currentValue)
#php
$dates = (array)json_decode($filter->currentValue);
$start_date = $dates['from'];
$end_date = $dates['to'];
$date_range = implode(' ~ ', $dates);
$date_range = str_replace('-', '/', $date_range);
$date_range = str_replace('~', '-', $date_range);
#endphp
placeholder="{{ $date_range }}"
#endif
>
<div class="input-group-append daterangepicker-{{ $filter->key }}-clear-button">
<a class="input-group-text" href=""><i class="la la-times"></i></a>
</div>
</div>
</div>
</div>
</li>
{{-- ########################################### --}}
{{-- Extra CSS and JS for this particular filter --}}
{{-- FILTERS EXTRA CSS --}}
{{-- push things in the after_styles section --}}
#push('crud_list_styles')
<!-- include select2 css-->
<link rel="stylesheet" type="text/css" href="{{ asset('packages/bootstrap-daterangepicker/daterangepicker.css') }}" />
<style>
.input-group.date {
width: 320px;
max-width: 100%; }
.daterangepicker.dropdown-menu {
z-index: 3001!important;
}
</style>
#endpush
{{-- FILTERS EXTRA JS --}}
{{-- push things in the after_scripts section --}}
#push('crud_list_scripts')
<script type="text/javascript" src="{{ asset('packages/moment/min/moment.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('packages/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
<script>
function applyDateRangeFilter{{$filter->key}}(start, end) {
if (start && end) {
var dates = {
'from': start.format('YYYY-MM-DD'),
'to': end.format('YYYY-MM-DD')
};
var value = JSON.stringify(dates);
} else {
//this change to empty string,because addOrUpdateUriParameter method just judgment string
var value = '';
}
var parameter = '{{ $filter->name }}';
// behaviour for ajax table
var ajax_table = $('#crudTable').DataTable();
var current_url = ajax_table.ajax.url();
var new_url = addOrUpdateUriParameter(current_url, parameter, value);
// replace the datatables ajax url with new_url and reload it
new_url = normalizeAmpersand(new_url.toString());
ajax_table.ajax.url(new_url).load();
// add filter to URL
crud.updateUrl(new_url);
// mark this filter as active in the navbar-filters
if (URI(new_url).hasQuery('{{ $filter->name }}', true)) {
$('li[filter-key={{ $filter->key }}]').removeClass('active').addClass('active');
}
else
{
$('li[filter-key={{ $filter->key }}]').trigger('filter:clear');
}
// ---------------------------------------------------------------
// THIS is where it's different from the regular date_range filter
// ---------------------------------------------------------------
// When the filter is changed, refresh the page,
// so that the NPS widget up-top get reloaded.
document.location.reload();
}
jQuery(document).ready(function($) {
var dateRangeInput = $('#daterangepicker-{{ $filter->key }}').daterangepicker({
timePicker: false,
ranges: {
'Last Year': [moment().startOf('year').subtract(1, 'year'), moment().endOf('year').subtract(1, 'year')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
'Last Week': [moment().subtract(1, 'week').startOf('week'), moment().subtract(1, 'week').endOf('week')],
'This Year': [moment().startOf('year'), moment().endOf('year')],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'This Week': [moment().startOf('week'), moment().endOf('week')]
},
#if ($filter->currentValue)
startDate: moment("{{ $start_date }}"),
endDate: moment("{{ $end_date }}"),
#endif
alwaysShowCalendars: true,
autoUpdateInput: true
});
dateRangeInput.on('apply.daterangepicker', function(ev, picker) {
applyDateRangeFilter{{$filter->key}}(picker.startDate, picker.endDate);
});
$('li[filter-key={{ $filter->key }}]').on('hide.bs.dropdown', function () {
if($('.daterangepicker').is(':visible'))
return false;
});
$('li[filter-key={{ $filter->key }}]').on('filter:clear', function(e) {
// console.log('daterangepicker filter cleared');
//if triggered by remove filters click just remove active class,no need to send ajax
$('li[filter-key={{ $filter->key }}]').removeClass('active');
// ---------------------------------------------------------------
// THIS is where it's different from the regular date_range filter
// ---------------------------------------------------------------
// When the filter is changed, refresh the page,
// so that the NPS widget up-top get reloaded.
document.location.reload();
});
// datepicker clear button
$(".daterangepicker-{{ $filter->key }}-clear-button").click(function(e) {
e.preventDefault();
applyDateRangeFilter{{$filter->key}}(null, null);
})
});
</script>
#endpush
{{-- End of Extra CSS and JS --}}
{{-- ########################################## --}}
It's not pretty... but... it's a solution 😀
There's many solution you can use php to generate the graph instead of the template. See the related section in the. documentation.
Then use the request parameter to filter the data for the graph. I ll try to post an example.

Laravel 5.8 + FullCalendar + Popover: Attempting to replicate demo is failing with popover error

In my application, I am trying to use FullCalendar to display events. Specifically, I'm trying to replicate the demo example they provide.
I am making use of maddHatter\laravel-fullcalendar
My Laravel/PHP code in a blade template to generate the calendar is as follows:
$cal_events = [];
foreach ($events as $key => $value) {
$cal_events[] = Calendar::event(
$value->eventName,
false,
new \DateTime($value->eventStartDate),
new \DateTime($value->eventEndDate),
$value->eventID,
// Add color
[
'color' => '#0000FF',
'textColor' => '#FFFFFF',
'url' => env('APP_URL')."/events/$value->slug",
'description' => $value->eventDescription,
]
);
}
$calendar = Calendar::addEvents($cal_events)
->setCallbacks([
'eventRender' => 'function(event, element) {
element.popover({
container: "body",
html: true,
placement: "top",
trigger: "hover",
title: "Random Title",
content: "Some Content"
});
}'
]);
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<b>{!! $header !!} </b>
</div>
<div class="panel-body" >
{!! $calendar->calendar() !!}
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar->script() !!}
I can get the calendar to display with my events just fine when I do not have the ->setCallBacks() portion above.
Adding it in results in the following error when looking at the console in Chrome:
jquery.min.js:2 Uncaught TypeError: element.popover is not a function
at Object.eventRender (1:formatted:83)
at me.U [as trigger] (fullcalendar.min.js:6)
at t.constructor.trigger (fullcalendar.min.js:8)
at t.constructor.resolveEventEl (fullcalendar.min.js:8)
at HTMLAnchorElement.<anonymous> (fullcalendar.min.js:7)
at Function.each (VM2577 jquery.min.js:2)
at r.fn.init.each (VM2577 jquery.min.js:2)
at t.constructor.renderFgSegEls (fullcalendar.min.js:7)
at t.constructor.renderFgSegs (fullcalendar.min.js:7)
at t.constructor.renderEvents (fullcalendar.min.js:7)
What am I missing?
If there is anything else you need to know, ask and I will provide it.
The CodePen demo you've linked to includes Bootstrap's JavaScript and CSS files, which provide the popover functionality. Your version doesn't, from what you've shown.
Check what's included in the CodePen (it's in the Settings area) and make sure you've got the same or very similar version of Bootstrap available to your page.

How can I give HyperLink in my full calender?

I am displaying my events in calender. It will display it properly. But I want that when I click on that event it will redirect on particular event_detail page.
I am beginner in laravel so woll you please help me???
This Is my controller file
<?php
namespace App\Http\Controllers\Admin;
use Carbon;
use Calendar;
use App\Event;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class CalendarController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/*
*Display All The Events In Calendar
*
*/
public function calendar()
{
$event = [];
$allEvent = Event::all();
if($allEvent->count())
{
foreach ($allEvent as $key => $eventList)
{
$event[] = Calendar::event(
$eventList->name,
true,
new \DateTime($eventList->event_date),
new \DateTime($eventList->evet_date)
);
}
}
$showInCalendar = Calendar::addEvents($event);
return view('admin.calendar.event_calendar', compact('showInCalendar', 'allEvent'));
}
}
This is muy blade file
#extends('admin.layout.default')
#section('css')
<link href="{{ url('assets/plugins/calendar/dist/fullcalendar.css') }}" rel="stylesheet" />
#endsection
#section('content')
<div class="row page-titles">
<div class="col-md-5 col-8 align-self-center">
<h3 class="text-themecolor">Calendar</h3>
<ol class="breadcrumb">
<li class="breadcrumb-item">Dashboard</li>
<li class="breadcrumb-item active">Calendar</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card card-outline-info">
<div class="card-body">
<div class="container">
<div class="row justify-content-center">
<div id="calendar">
{!! $showInCalendar->calendar() !!}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('jsPostApp')
{!! $showInCalendar->script() !!}
<script src="{{ url('assets/plugins/calendar/jquery-ui.min.js') }}"></script>
<script src="{{ url('assets/plugins/moment/moment.js') }}"></script>
<script src="{{ url('assets/plugins/calendar/dist/fullcalendar.min.js') }}"></script>
<script type="text/javascript">
</script>
#endsection
I dont know how to handle that hyperlink to open that particular event's detils page.
It's very easy to achieve that behavior.
You will need to set the property url in your event objects. Once you have it, you can use the callback eventClick to redirect the user. By default, eventClick will always redirect to link inside url.
If you want to display it in a different tab, or a popup, take a look at the section Cancelling Default Behavior in the eventClick link I posted here.
Owk I got the solution
public function calendar()
{
$event = [];
$allEvent = Event::all();
if($allEvent->count())
{
foreach ($allEvent as $key => $eventList)
{
$event[] = Calendar::event(
$eventList->name,
true,
new \DateTime($eventList->event_date),
new \DateTime($eventList->event_date),
null,
[
'url' => 'event/' .$eventList->id,
]
);
}
}

Controller method not defined in laravel

I am new in Laravel and trying to learn forms. Currently I am trying to do a file uploading form and my create page looks like this:
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
{!! Form::open(['action' => 'MovieController#create', 'enctype' => 'multipart/form-data']) !!}
<div class="form-group">
{{Form::label('name', 'Name')}}
<br>
{{Form::text('name')}}
</div>
<div class="form-group">
{{Form::label('description', 'Description')}}
<br>
{{Form::textarea('description')}}
</div>
<div class="form-group">
{{Form::label('release_date', 'Release Date')}}
<br>
{Form::date('release_date')}}
</div>
<div class="form-group">
{{Form::label('country', 'Country')}}
<br>
{{Form::text('country')}}
</div>
<div class="form-group">
{{Form::label('poster_name', 'Poster Image')}}
{{Form::file('poster_name')}}
</div>
<div class="form-group">
{{Form::label('file_name', 'Movie File')}}
{{Form::file('file_name')}}
</div>
{{Form::submit('Submit',['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
</body>
</html>
As you can see I am trying to make an action of 'MovieController#create'. Now let's see MovieController file:
namespace
App\Http\Controllers;
use Illuminate\Http\Request;
use App\Movie;
class MovieController extends Controller
{
public function create(Request $request){
$this->validate($request,[
'poster_name' => 'required|image'
]);
//Handle poster upload
$imageName = $request->file('poster_name')->getClientOriginalName();
$request->file('poster_name')->storeAs('public/images',$imageName);
$videoName = $request->file('file_name')->getClientOriginalName();
$request->file('file_name')->storeAs('public/videos',$videoName);
$movie = new Movie;
$movie->name = $request->name;
$movie->description = $request->description;
$movie->release_date = $request->release_date;
$movie->country = $request->country;
$movie->poster_name = $imageName;
$movie->file_name = $videoName;
$movie->save();
$movies = Movie::all();
return view('home',['movies' => $movies]);
}
}
At the beginning everything was working but then I made a few changes in create file (only css and visual changes) and now when I try to go to that page, it gives the following error:
ErrorException
Action App\Http\Controllers\MovieController#create not defined. (View: C:\xampp\htdocs\MagicMovie\resources\views\movies\create.blade.php)
Any suggestions?
Try doing something like this,
On you form
{!! Form::open([ 'action' => route('create_movie'),
'enctype' => 'multipart/form-data', 'method' => 'POST']) !!}
or
{!! Form::open([ 'action' => url('movie/create'),
'enctype' => 'multipart/form-data' , 'method' => 'POST' ]) !!}
And on your routes (web.php)
Route::post('movie/create', ['uses' => 'MovieController#create', 'as' => 'create_movie']);
You can also check some basic Laravel routing here.
I think you can try this :
Route::post('/storeMovie', 'MovieController#create')->name('storeMovie');
in form action
{!! Form::open(['route' => 'storeMovie', 'enctype' => 'multipart/form-data']) !!}
Hope this work for you !!!
You are binding controller method to form directly, you can't do that.
You should write a Route for it.
in web.php
Route::post('/add', 'MovieController#create')->name('create_movie');
in form action
'action' => 'create_movie'

Categories