Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Laravel 5.4 zmiana kolory eventu gdy user zapisze sie na niego, zmiana kolory eventu gdy user zapisze sie na niego
K3n0
post
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 3.05.2016

Ostrzeżenie: (0%)
-----


Witam mam problem nie wiem jak zrobić, aby event zmieniał kolor. A dokładniej chodzi mi o to, że nie wiem jak w funkcji w w skrypcie do fullcalendarza pobrać zmienną events_id, która odpowiedzialna jest za relację.
Kombinuję na różne sposoby i nie wiem jak to ugryść. Czy zrobić to w controllerze czy w wywoływaniu kalandarza.

Widok:
  1. <script src="{{ asset('js/fullcalendar') }}/fullcalendar.js"></script>
  2. <script src="{{ asset('js/bootstrap.js') }}"></script>
  3. <script type="text/javascript">
  4. $(document).ready(function() {
  5. var base_url = '{{ url('/') }}';
  6. $('#bootstrapModalFullCalendar').fullCalendar({
  7. weekends: true,
  8. header: {
  9. left: 'prev,next today',
  10. center: 'title',
  11. right: 'month,agendaWeek'
  12. },
  13. eventClick: function(event, jsEvent, view) {
  14. $('#modalTitle').html(event.title);
  15. $('#modalBody').html(event.name);
  16. $('#eventUrl').attr('href','/home/zapis/'+event.id);
  17. $("#startTime").html(moment(event.start).format('HH:mm '));
  18. if (event.end) $("#endTime").html(moment(event.end).format('HH:mm '));
  19. else $("#endTime").html('');
  20. $('#fullCalModal').modal();
  21. return false;
  22. },
  23.  
  24. eventLimit: true, // allow "more" link when too many events
  25. FirstDay: 1,
  26. contentheight : 650,
  27. editable : true,
  28. allDay : false,
  29. aspectRatio : 2,
  30. slotLabelFormat : 'HH:mm:ss',
  31. timeFormat : 'HH:mm',
  32. displayEventEnd : true,
  33. events: {
  34. url: base_url + '/api',
  35. error: function() {
  36. alert("cannot load json");
  37. }
  38. },
  39. eventAfterRender: function (event, element, view,events_id) {
  40. if(event.id === 1){
  41. element.css('background-color', '#cccccc');
  42. }
  43. else
  44. {
  45. if (event.title == "Wydzial 1")
  46. {
  47. element.css('background-color', '#378006');
  48. }
  49. else if(event.title == "Wydzial 2"){
  50. element.css('background-color', '#ff0000');
  51. }
  52. else if(event.title == "Wydzial 3"){
  53. element.css('background-color', '#73e600');
  54. }
  55. else{
  56. element.css('background-color', '#0066ff');
  57. }
  58. }
  59.  
  60. }
  61. });
  62. });
  63. </script>
  64.  

Ta 1 wstawiłem, żeby sprawdzić czy chociaż if dobrze smiga. Domyślam się że zamiast 1 należy spawdzić czy ten event znajduje sie w tablicy odpowiedzialnej za relacje i tu jest problem nie mam pojećia jak to sprawdzić
Controller:
  1. public function index()
  2. {
  3. $events= HomeModel::all();
  4. // foreach ($events as $event) {
  5. // if ($event->title=="Wydzial 1") {
  6. // }
  7. // elseif($event->title == "Wydzial 2"){
  8. // }elseif ($event->title == "Wydzial 3") {
  9. // }elseif ($event->title == "Wydzial 4") {
  10. // }
  11. // }
  12.  
  13.  
  14. return view('home',['events'=>$events]);
  15. }

Model:
  1. <?php
  2. namespace App;
  3.  
  4. use Illuminate\Database\Eloquent\Model;
  5.  
  6. class HomeModel extends Model
  7. {
  8. protected $table = 'events'; // you may change this to your name table
  9. public $timestamps = true; // set true if you are using created_at and updated_at
  10. protected $primaryKey = 'id'; // the default is id
  11. public function usersave()
  12. {
  13. return $this->belongsToMany(User::class,'save_events','events_id','users_id');
  14. }
  15. }

Byłbym wdzięczny nawet na nakietowanie w jaki sposób to rozwiązać bo naprawdę nie mam bladego pojecia.

W controllerze dodalem cos takiego $eventscolo=DB::table('save_events')->select('events_id')->get(); . Pobieram id eventow, przekazuje do widoku ale teraz nie wiem jak sprawidzc. Próboje zrobić cos takiego w if (event.id===eventscolo) i nie dziala ;p


Ten post edytował K3n0 5.04.2017, 19:25:08
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 16:15