How can I give HyperLink in my full calender? - php

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,
]
);
}
}

Related

PHP/Laravel search query controller

I am trying to build a search query to use the user's search input (gene name) and return the gene location and symbol from a JSON file I loaded in.
My Site Controller for the JSON input:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SiteController extends Controller
{
public function index()
{
$results = file_get_contents("http://ftp.ebi.ac.uk/pub/databases/genenames/hgnc/json/locus_groups/protein-coding_gene.json");
$data = json_decode($results, true);
dd($data);
}
}
My Search Controller for the search function:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function search(Request $request){
// Get the search value from the request
$search = $request->input('search');
// Search in the name column from the data table
$data = data::query()
->where('name', 'LIKE', "%{$search}%")
->get();
// Return the search view with the results compacted
return view('search', compact('data'));
}
}
My routes:
<?php
use Illuminate\Support\Facades\Route;
//use App\Http\Controllers\Controller;
use App\Http\Controllers\SiteController;
Route::get('/data', [SiteController::class, 'index']);
Route::get('search', [SearchController::class, 'search']);
Route::get('/', function () {
return view('welcome');
});
And my welcomeblade:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Geisinger</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/1866062af8.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="{{ asset('/styles.css') }}" >
</head>
<body>
<img src="{{ asset('/Geisinger_logo.jpg') }}" alt="Geisinger Logo">
<h1> Geisinger Gene Search </h1>
<div class="container my-8 py-5 px-5 mx-5">
<!-- Search input -->
<form action="{{ route('search') }}" method="GET">>
<input type="search" class="form-control" placeholder="Search Gene Name" name="search">
<button type="submit">Search</button>
</form>
<div class="d-grid gap-2 col-6 mx-auto">
<button class="btn btn-outline-dark" type="button">Search <i class="fa-solid fa-magnifying-glass"></i></button>
</div>
<br>
<br>
<h2>Results <i class="fa-solid fa-square-poll-horizontal"></i></h2>
<!-- List items -->
<?php
#if($data->isNotEmpty())
#foreach ($data as $data)
<ul class="list-group mt-3">
<li class="list-group-item">{{ $data->name }}<</li>
<li class="list-group-item">{{ $data->location }}</li>
<li class="list-group-item">{{ $data->symbol }}</li>
</ul>
#endforeach
#else
<div>
<h2>No Gene found</h2>
</div>
#endif
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
</body>
</html>
I keep getting "route 'search' not defined" and "syntax error unexpected token "if"". Thank you for your help!
You can only access the route() method on named routes. In your web.php file, you must give your search route the name search before you can access it via route('search')
In you web.php change:
Route::get('search', [SearchController::class, 'search']);
to this:
Route::get('search', [SearchController::class, 'search'])->name('search');
Please visit the docs to learn more.

How can i translate dynamic seo_url in Laravel?

I have dynamic laravel route. But i cannot translate this route when i use getTranslatedAttribute in the blade. I guess i got error because of the dynamic route.
i got this error.
Call to a member function getTranslatedAttribute() on null (View:/home//public_html/resources/views///)
my route
Route::get('/en/solutions/{seo_url}', function ($seo_url) {
App::setLocale('en');
$themes = App\Theme::all();
$services = App\Service::all();
$referances = App\Referance::all();
$blogs = App\Blog::all();
$solutions = App\Solution::all();
$announcements = App\Announcement::all();
$news = App\News::all();
$subsolutions = App\Subsolution::all();
$solution_details = App\Solution::where('seo_url', $seo_url)->first();
$pages = TCG\Voyager\Models\Page::all();
return view('tema.parallax.en.solution_detail', compact('services','solution_details','themes','pages' , 'referances' , 'blogs' , 'solutions', 'subsolutions' , 'news', 'announcements') );
});
my blade
<div class="container ms-content">
<div class="row justify-content-between">
<div class="row blog-sidebar grid-content col-lg-12">
<div class="grid-sizer col-12"></div>
#if ("en/solutions/" . $solution_details->getTranslatedAttribute('seo_url', 'en', 'fallbackLocale') == Request::path())
<article class="grid-item col-12 pb-lg-5">
<div class="work-card card--is-link"> <figure
class="card__img media-wrapper media-wrapper--21:9"><img
src="/public/storage/{{$solution_details->resim}}"
alt="{!!$solution_details->getTranslatedAttribute('baslik', 'en', 'fallbackLocale')!!}">
<div class="glow-wrap"><i class="glow"></i></div>
</figure>
<br>
<div class="card__content"><a class="card__title">
<h4>{!!$solution_details->getTranslatedAttribute('baslik', 'en', 'fallbackLocale')!!}
</h4>
</a>
<p class="text-sm post-excerpt">{!!$solution_details->getTranslatedAttribute('aciklama',
'en', 'fallbackLocale')!!}</p>
<div class="post-info__footer"><span class="post-info__divider"></span></div>
</div>
</div>
</article>
#endif
</div>
</div>
</div>
my Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use TCG\Voyager\Traits\Translatable;
class Solution extends Model
{
use Translatable;
protected $translatable = ['baslik', 'aciklama', 'aciklama_kisa', 'seo_url' , 'seo_baslik' ,'seo_aciklama'];
}
In short, I want to translate my dynamic url.
How can i do that ?

Q: how do I show, update, edit user profile by username in Laravel?

I have a custom authentication guard Applicant and already have created ApplicantsProfile model.
Problem 1 :
so far i am stuck with the show method, it is working but whatever ID i passed to the route it renders the view .
Problem 2 :
I want to access each applicant profile by it's ID
Problem 3 :
How do edit and update the authenticated user profile?
Profile Model
class ApplicantsProfile extends Model
{
protected $fillable = [
'job_title', 'applicant_id',
];
public function applicant()
{
return $this->belongsTo(Applicant::class);
}
}
Profile Controller
class ApplicantsProfileController extends Controller
{
public function __construct()
{
$this->middleware('auth:applicant');
}
public function show($id)
{
$profile = ApplicantsProfile::find($id);
return view('applicant.profile', compact('profile'));
}
}
Profile View
#extends('layouts.auth')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-5">
<div class="card">
<div class="card-header">{{Auth::guard('applicant')->user()->name}}</div>
<div class="card-body">
{{Auth::guard('applicant')->user()->profile->job_title}}
</div>
</div>
</div>
</div>
</div>
#endsection
Route
Route::get('/account/{profile}', 'ApplicantsProfileController#show');
If I go to route: account/1 or account/2 it renders the view of the authenticated user.
in your profile view, you use Auth so it's normal to show these results.
you have to modify your view blade to something like :
#extends('layouts.layout')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-5">
<div class="card">
<div class="card-header">
{{ $applicantsProfile['name'] }}
</div>
<!-- complete your code like so -->
in your controller you have to do something like:
public function show(ApplicantsProfile $applicantsProfile)
{
return view('applicant.profile', compact('applicantsProfile'));
}
and in your web.php route:
Route::get('/account/{applicantsProfile}', 'ApplicantsProfileController#show');

How to Pass Data From One View to Another in Laravel?

I am quite new to Laravel
I have two views
Book
Read
The Book View displays a single book
<section class="cont-readingone">
<div class="container">
<div class="row row-grid">
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
<div class="cont-reading-image">
<img src="{{ $book->image_url }}" alt="trending image" />
</div>
</div>
<div class="col-md-6">
<div class="out-box">
<h2>{{ $book->name }}</h2>
<h3>{{ $book->author->name }}</h3>
<br>
Start Reading<br><br>
<img src="\images\cart-buy.png" width="13px"/> Buy
</div>
</div>
</div>
</div>
In my controller, I was able to achieve it using
public function show(Book $book) {
$relatedBooks = Book::where('author_id', $book->author_id)
->where('id', '!=', $book->id)
->get();
return view('book')->with('book', $book)->with('relatedBooks', $relatedBooks);
}
In my web.php
Route::get('/books/{book}', [BooksController::class, 'show'])->name('book');
What I am trying to achieve is that, when I click Start Reading on
the Single Book Page, it takes me to another view page (Read) but it takes the book id that I clicked.
In the Read View I have this code,
<script>
"use strict";
document.onreadystatechange = function () {
if (document.readyState == "complete") {
window.reader = ePubReader("{{ $book->epub_url }}", {
restore: true
});
}
};
</script>
My problem is that I don't know how to take the id of the book that I
click and Pass it to the Read View
I will be glad if someone can explain the logic to me as I am confused.
To do via POST
//Book View
//change Start Reading to
<form action="{{ route("your.route.to.read") }}" method="POST">
#csrf
<input name="book_id " value ={{$book->id}} hidden>
<button type="submit">Start Reading</button>
</form>
//your Route will be
Route::get('/read',YourReadController#yourFunction)->name('your.route.to.read');
//your controller will be
public function yourFunction(Request $request)
{
//book id is in $$request->book_id
//your operation here
return view('read')->with('data',$dataYouWantToSend);
}
To do via GET
//Book View
//change Start Reading<br><br> to
Start Reading
//route for get will be
Route::get('/read/{book_id}',YourReadController#yourFunction)->name('your.route.to.read');
//your countroller will be
public function yourFunction($book_id)
{
//book id is in $book_id
//your operation here
return view('read')->with('data',$dataYouWantToSend);
}

Laravel Fullcalendar 5.5

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"
});
}'
]);

Categories