Loomix

Loomix

Member Since 9 Months Ago

Experience Points
2,530
Total
Experience

2,470 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
2,530 XP
Oct
02
3 weeks ago
Activity icon

Replied to Getting 405 : Method Not Allowed From Ajax POST Request

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Activity icon

Replied to Getting 405 : Method Not Allowed From Ajax POST Request

No, it causes 404 not found.

Activity icon

Replied to Getting 405 : Method Not Allowed From Ajax POST Request

This webspace was not configured by me, it redirects from https://mydomain.com/ to https://mydomain.com/public/ , no idea why. I will contact the person who is responsible. I got APP_URL=https://mydomain.com/ in my .env though.

Ajax post to url https://mydomain.com/setOrdersTool causes the same 405 error, browser console says XHR GET https://rplaner.meshwork.it/public/setOrdersTool -- 405 Method not allowed.

Activity icon

Replied to Getting 405 : Method Not Allowed From Ajax POST Request

@amora2972 No, changing to method did not change anything.

But I found out that this error does not occur on another webspace I rented. Does anyone know what server configuration could cause a 405 error for POST on one server and not on the other?

Oct
01
4 weeks ago
Activity icon

Replied to Getting 405 : Method Not Allowed From Ajax POST Request

The function with the Ajax is triggered by mousedown event on a certain area of my FullCalendar. The production server was not configured by me, it's just a temporary webspace for development.

      resourceLabelDidMount: function(info){
        info.el.addEventListener("mousedown", function(){ 
         	makeResourcesSortable();
        });
      },
Activity icon

Started a new Conversation Getting 405 : Method Not Allowed From Ajax POST Request

From an Ajax request in my view I am getting a 405 error. The weird thing is that it works on my local VirtualHost but throws this error when testing on production server: AJAX: error : 405 : Method Not Allowed. Strangely, the console of Firefox says XHR GET https://mydomain.com/public/setOrdersTool - 405 Method not allowed what I don't understand, because I am not using GET but POST. Ajax request:

          $.ajax({
            url: root + "/setOrdersTool",
            type: "post",
            data: {
              resources: resources,
            },
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
            success: function(response){
            	calendar.refetchResources();
            },
            error: function(jqXHR, textStatus, errorThrown){
              alert("AJAX: " + textStatus + " : " + jqXHR.status + " : " + errorThrown);
            }
          });

web.php:

Route::post('/setOrdersTool', '[email protected]');

in header of my view:

<meta name="csrf-token" content="{{ csrf_token() }}" />

There is no entry in the Laravel log when the error occurs. What am I missing? Btw: I can't use GET, because then I get the error "URI is too long".

Sep
16
1 month ago
Activity icon

Replied to Positive Query Result But No Database Update

omg you're right. i just copied the try/catch and forgot the most important inbetween! xD

Activity icon

Replied to Positive Query Result But No Database Update

I've just found out that it works when I remove the try/catch . But why? Is there anything wrong with how I do it?

Activity icon

Replied to Positive Query Result But No Database Update

Yeah, the dump server says what is not reflecting in the database: 3 records differ in before and after and obviously the afteris coming from the db but in phpmyAdmin, there are no changes in the table and when I fetch all the resources again, the old order is still there. I don't get it!

First I thought I am somehow on the wrong server or wrong database but this is not the case. Is it possible that there is some kind of buffering issue? Here's an export of the table with 15 records, maybe there's something not right with it:

CREATE TABLE IF NOT EXISTS `tool_user` (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` int(10) UNSIGNED NOT NULL,
  `tool_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tool_order` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `fk_tool_user_user_id_idx` (`user_id`),
  KEY `fk_tool_user_tool_id_idx` (`tool_id`)
) ENGINE=InnoDB AUTO_INCREMENT=159 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `tool_user` (`id`, `user_id`, `tool_id`, `tool_order`) VALUES
(24, 19, '1122', 4),
(25, 19, '1121', 3),
(26, 19, '1123', 5),
(27, 19, '1124', 6),
(28, 19, '1125', 7),
(29, 19, '1126', 8),
(31, 19, '1133', 10),
(36, 19, '1150', 11),
(37, 19, '1153', 12),
(39, 19, '1156', 14),
(42, 19, '1114', 2),
(45, 19, '1110', 1),
(50, 19, '1132', 9),
(51, 20, '1126', 0),
(53, 20, '1123', 0);

Activity icon

Replied to Positive Query Result But No Database Update

count is a good idea but it's 1 for each resource in the loop. I already checked that in the database and technically the resources is always a list where any user_id and tool_id matches exactly 1 record in the table. The question of the query is only if tool_order gets an update or not.

Activity icon

Started a new Conversation Positive Query Result But No Database Update

I want to update the column tool_order in a pivot table tool_user for certain records (the ones where order has changed). The Laravel dump server and query result tell me that everything is fine and some records were updated but there are no changes in the table. There are no erros on console, dump server or log. My code:

    public function setOrders(Request $request)
    {
    	$resources = $request['resources'];
        DB::beginTransaction();
        try{
    	  foreach($resources as $resource){
    	  	$query = DB::table('tool_user')
    		    ->where('tool_id', strval($resource['id'])) 
    		    ->where('user_id', Auth::id())
    	            ->update(['tool_order' => $resource['order']]);
    	    dump($resource['id'].' '.Auth::id().' '.$resource['order']);
    	    dump($query);
      	}
      }
      catch(\Exception $e){
        DB::rollBack();
        throw $e;
      };
      return 1; 
    }

Table tool_user has the columns:

id (int(10) )

user_id (int(10) )

tool_id (varchar(64) utf8mb4_unicode_ci)

tool_order (smallint(5))

However, what works fine in another code section is

        $res = DB::table('tool_user')
         ->where('id', $row->id)
         ->update([
           'tool_order' => $newOrder
         ]);
      } 

I checked the docs at https://laravel.com/docs/7.x/queries#updates and can't see any issues with my query. Any ideas?

Sep
13
1 month ago
Activity icon

Started a new Conversation Unwanted Side Effects When Sorting Resources (fullcalendar)

I am successfully using the sortable widget (https://jqueryui.com/sortable/) of jQuery Ui 1.12.1 to make the resources of fullcalendar scheduler manually sortable. However, there are some severe side effects:

1.) The resize events function works, but the grid of the event area is distorted visually.

2.) Dragging events on the x-axis works but not on the y-axis to drag events to other resources.

3.) Adjoined events stick together when dragging.

4.) Selecting cells works but the y-lines of the event area grid disappear.

5.) Holding mousebutton down anywhere in the event area makes the y-lines of the event area grid disappear.

Working example https://codepen.io/craftydlx/pen/yLeXKKL and the JS code:

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');
  var calendar = new FullCalendar.Calendar(calendarEl, {
      initialView: 'resourceTimelineDay',
      editable: true,
      selectable: true,
      resources: 'https://fullcalendar.io/demo-resources.json',
      events: 'https://fullcalendar.io/demo-events.json?single-day&for-resource-timeline',
    })
    calendar.render()
    $(function(){
      $("table tbody").sortable({

      }).disableSelection() 
    });
});

Maybe the tags table tbody are not right or do I have to somehow insulate the event area from the sortable function? Or is there even a much better way to have the resources sortable?

Sep
08
1 month ago
Activity icon

Replied to Getting Data By Route To Javascript In View From Controller Response

@michaloravec Thank you, by using var resdata = @json($resdata); in my view everything is working fine!

However, best answer must go to @automica , because he answered my initial question how to avoid Ajax here.

Activity icon

Replied to Getting Data By Route To Javascript In View From Controller Response

oh dear, there's one issue left: the data feed is the resource for FullCalendar and it does not accept resdata as a resource. To see what the problem is I printed both the response from the ajax request (which is working as a resource) and the contents of resdata (the javascript way):

ajax response (working) printed to view with document.getElementById('out').innerHTML = response;

[object Object],[object Object],...

javascript resdata (not working) printed to view with document.getElementById('out2').innerHTML = resdata;

[{"id":"1110","order":1,"title":"Shemar Zieme (1110) (1)"},{"id":"1114","order":2,"title":"Peyton Moore (1114) (2)"},...

Both data are coming from the same controller function. I guess I have to encode the javascript data somehow to make it work as a resource?

Doing console.log(resdata) gives me loads of quotes, that does not seem right, maybe that's the issue?

[{&quot;id&quot;:&quot;1110&quot;,&quot;order&quot;:1,&quot;title&quot;:&quot;Shemar Zieme (1110) (1)&quot;},{&quot;id&quot;:&quot;1114&quot;,&quot;order&quot;:2,&quot;title&quot;:&quot;Peyton Moore (1114) (2)&quot;},...
Activity icon

Replied to Getting Data By Route To Javascript In View From Controller Response

...and let rdata = resdata; does the trick in the external js to fetch the data from controller, respectively view. Thanks, will do it this way, it's more clear than a hidden field.

Activity icon

Replied to Getting Data By Route To Javascript In View From Controller Response

No can do. I guess I have to put it in a hidden field of the view and get it by const resdata = document.querySelector('#mydata'); ? Is there really no way to get the feed by routing?

Activity icon

Replied to Getting Data By Route To Javascript In View From Controller Response

Okay, the controller response with return view('toolplans.index', ['resdata' => $resdata]); is working but there's something not right with the js part: let resdata = '{{ $resdata }}' just puts the string {{ $resdata }} to resdata. The js is in an external file which is refered to by <script src="{{ asset('js/ctm/tpindex.js')}}"></script> -- is that an issue?

Activity icon

Replied to Getting Data By Route To Javascript In View From Controller Response

Wow, that's really something, also performance-wise. Thanks, will try that!

Activity icon

Replied to Getting Data By Route To Javascript In View From Controller Response

@automica Thanks, could you be a bit more specific about pass it into your view to be used by your js? I am not sure yet how to get the data from the feed to $data.

Activity icon

Started a new Conversation Getting Data By Route To Javascript In View From Controller Response

Currently I am using Ajax to get a data feed from my controller to a javascript code in my view. The feed looks like

[{"id":"1110","order":1,"title":"Shemar Zieme (1110) (1)"},
{"id":"1114","order":2,"title":"Peyton Moore (1114) (2)"},
{...

and the Ajax call does not even need to transfer any request data:

var RESOURCE_URL = "/resource-feed";

    	$.ajax({
   	    url: RESOURCE_URL,
   	    type: "get",
   	    data: {},
   	    success: function(response){
(...)   	   

I guess there is a much better way in Laravel than Ajax to get this data into javascript in a view by using the route? I tried var resources = RESOURCE_URL but that only gives me the full path to the feed http://myapp/resource-feed.

Activity icon

Replied to Saving User Specific(!) Sort Order Of Array

I was hoping for a bit more feedback but the fact noone else replied probably means that dealing with this config in the db is the best way.

Sep
06
1 month ago
Activity icon

Started a new Conversation Saving User Specific(!) Sort Order Of Array

In my Laravel 7 app, I have several objects stored in an array, like

    var myCollection = [
      { id: '1110', title: 'g', sortOrder: 1},
      { id: '1112', title: 'gfg', sortOrder: 2, color: 'green' },
      { id: '1115', title: 'tzz', sortOrder: 3, color: 'orange' },
      { id: '1118', title: 'gfhfh', sortOrder: 4 },
      { id: '1120', title: 'fhgfhf', sortOrder: 5 },
      { id: '1119', title: '324r', sortOrder: 6, color: 'red' },
      { id: '1131', title: 'sdfsdf', sortOrder: 7 }
    ];

The user is able to sort these objects manually with the user interface and I managed to have the sortOrder changed properly, resulting in an array with correctly updated sortOrder for each item. Now I want to save the sortOrder for myCollection, so that the user does not have to sort again the next time he logs in.

Concept wise, what is the best way to do that in Laravel? My idea is not using the database, because that would be loads of additonal data for each user and item collections can get huge over time. I was thinking about exporting to XML file - maybe one file per user, maybe not? In general, what is the best way to save this user specific config, are there any special tools or concepts for this in Laravel?

Aug
06
2 months ago
Activity icon

Replied to Passing Php Variable To External Js File

Yeah, the 3rd option is exactly what I tried: var tlId = <?php echo json_encode($tool->id); ?>; but it fails with expected expression, got '<' . Any idea why?

Activity icon

Replied to Passing Php Variable To External Js File

Thanks a lot, will try that! Is there any of these two solutions I should prefer?

Activity icon

Replied to Passing Php Variable To External Js File

use data attributes to an element and then read it.

..could you give an example?

Activity icon

Started a new Conversation Passing Php Variable To External Js File

In my blade view, I am including an external js file with <script src="{{ asset('/js/ctm/resedit.js')}}"></script> which I want to pass the value of $tool->id (from my blade view) to. I tried var tlId = "<?php echo json_encode($tool->id); ?>"; what results in tlId being <?php echo json_encode($tool->id); ?>. I also tried var tlId = <?php echo json_encode($tool->id); ?> without quotation what leads to the error expected expression, got '<' . Changing echofor printdid also not bring any result. Is this even possible?

Activity icon

Replied to Routing From External Js

Okay, I understand, thanks.

Activity icon

Replied to Routing From External Js

Yeah thanks, this is working but I have to use var GET_USERS_URL = root + '/matpro/public/getUsers'; . Is there a way to get the public folder?

Activity icon

Started a new Conversation Routing From External Js

In my view I have some js to do an Ajax call and declared an url with var GET_USERS_URL = "{{url('/')}}" + "/getUsers"; which is in fact http://localhost/matpro/public/getUsers and worked very well. Now I put this js code to a seperate file in http://localhost/matpro/public/ja/ctm/rescreate.js and now var GET_USERS_URL = "{{url('/')}}" + "/getUsers"; does not work anymore, because it leads to http://localhost/matpro/public/tool/%7B%7Burl('/')%7D%7D/getUsers -- at least that's what the debugger says.

I experimented with URL::to and route(...) but nothing seems to work to get the correct url from the external javascript.

Jul
30
2 months ago
Activity icon

Replied to Updating Pivot Table Safely

Thanks, that was exactly what I was looking for. So do you prefer this way over many-to-many relations and sync in Laravel? And is this the way I should do any DB transaction, no matter if pivot or not, or should this only be used when having transactions with 2 or more steps?

Btw: I am already using Request classes.

Jul
29
3 months ago
Activity icon

Started a new Conversation Updating Pivot Table Safely

My function to update a pivot table is not very good, because there was an invalid value in the users array and therefore the foreach stopped with error. Needless to say that (regarding to my function) all the values for the specific tool instance were gone:

    public function update(ToolRequest $request, Tool $tool)
    { 
      DB::table('tool_user')
       ->where('tool_id', $request->id)
       ->delete();  

      foreach ($request->users as $key => $value){
        DB::table('tool_user')
         ->insert(array('user_id' => $value, 'tool_id' => $request->id)
        );          
      }
      return redirect()->route('tool.index');
    }

I am using 1-to-many and many-to-many relations but I recognized that doing it like this is much faster than using many-to-many and more readable. What is the way to prevent data loss when foreach fails here?

Jul
28
3 months ago
Activity icon

Replied to Best Way To Use Auth Middleware?

@jlrdw What makes you think I do not know the difference? My question was about which way is best to check if a user is authenticated.

Activity icon

Replied to Best Way To Use Auth Middleware?

Yeah, I get it, thanks guys for clarification. I first checked on stackoverflow and found Auth::check in several policies, can be quite confusing to browse through all these sources.

Activity icon

Replied to Best Way To Use Auth Middleware?

@martinbean Therefore the only method in my policy could be

    public function before()
    {
        return true;
    }

if any operation is allowed for logged in users, right?

Activity icon

Replied to Best Way To Use Auth Middleware?

@michaloravec Thanks, that makes sense, will try that.

@tykus Do I get this right: So checking for authentication in policy makes no sense in general? Or do you mean the policy is obsolete when I check for authentication in route?

Activity icon

Started a new Conversation Best Way To Use Auth Middleware?

In one of my policies the update function is granted when a user is just logged in:

use Illuminate\Support\Facades\Auth;
    public function update()
    {
    	if(Auth::check())
    	  return true;
      return false;
    }

It works, but is this the best way to do this, or should I rather check all available roles in my app? Moreover, I found at least 3 different ways to use the Auth middleware. These are:

In route:

Route::get('pages/mainpage', ['middleware' => 'auth', 'uses' => '[email protected]']);

In constructor of controller:

public function __construct(){
    $this->middleware('auth');
}

With use, e.g. in policy:

use Illuminate\Support\Facades\Auth;

These methods can be used seperately, so what is the preferred way, meaning what is the safest?

Jul
20
3 months ago
Activity icon

Replied to Updating CheckBox Value To Database

Thanks guys, works great!

@michaloravec was first, so he gets "best answer".

Activity icon

Started a new Conversation Updating CheckBox Value To Database

Updating the record with the values changed in the form works fine but the checkbox value remains the same in database, weather it was checked or not. In database, I have a field multiassign which contains 0 or 1. I think there's something wrong with my html code.

html:

<div class="form-group{{ $errors->has('multiassign') ? '' : '' }}" style="float:left">
  <input type="checkbox" 
    class="form-control{{ $errors->has('multiassign') ? ' is-invalid' : '' }}" 
    name="multiassign" 
    value="{{ old('multiassign', $process->multiassign) }}" {{ $process->multiassign ? 'checked' : '' }} />
  @include('alerts.feedback', ['field' => 'multiassign'])
</div>

controller:

public function update(ProcessRequest $request, Process $process)
{
  Log::info($request->all());
  $process->update($request->all());
  return redirect()->route('process.index')->withStatus(__('Saved!'));
 }

log:

[2020-07-20 12:46:52] local.INFO: array (
   '_token' => 'yOQ7x5UfuWtj0MZjMAvIE5bqHuESZYR3geD0Bx0J',
   '_method' => 'put',
   'id' => 'X0013',
   'title' => 'Repair',
   'client' => 'Example Client',
   'multiassign' => '1',
)

in browser (for originally checked, value 1 in database)

<input type="checkbox" class="form-control" name="multiassign" value="1" checked />
Jul
17
3 months ago
Activity icon

Started a new Conversation Passing Parameters From Blade View To Policy

I am getting the error message Argument 2 passed to App\Policies\ProcessPolicy::test() must be an instance of App\Policies\Process, instance of App\Process given when I pass an instance of my Process class to the policy. I am sure there's something wrong with the syntax. Why would it have to be an instance of App\Policies\Process when I want to pass an object of my Process class to the belonging policy?

From my blade view:

@foreach($processes as $process)                        
@php 
  {{ $cand = Auth::user()->can('test', $process, App\Process::class); }}
@endphp

From my ProcessPolicy.php:

 public function test(User $user, Process $process)
 {
   return true; //useless, just for testing.
 }
Jul
10
3 months ago
Activity icon

Replied to Enabling Mouse Scroll Wheel For Modal Dropdown List

<div class="row">
   <label class="col-sm-3 col-form-label">{{ __('Resource') }}</label>
   <div class="col-sm-9 text-left align-self-center">
     <select id="resource"></select>                       
   </div>
</div> 

It's just standard using the grid system, nothing special.

Activity icon

Started a new Conversation Enabling Mouse Scroll Wheel For Modal Dropdown List

I have a bootstrap modal window popup with a Select2 v4 (https://select2.org/) dropdown list (with search field) with many items, using the scroll wheel of the mouse would therefore be very nice. For some reason, the wheel retains its focus on the parent page (I can still scroll the parent page in the background while the modal ist open). I tried

$('#mymodal').on('shown.bs.modal', function () {
  $(this).find('input[type=text],textarea,select').filter(':visible:first').focus();
  $("select:first").focus();
});

but this only stops the scrolling of the parent page and does not activate the mouse wheel for scrolling the modal dropdown list.

Meanwhile I noticed that the mouse wheel does not work on any of my dropdown lists in my Laravel webapp. I just tested the user management and the role dropdown list does not scroll either. How can I set the focus on dropdown lists? Thanks.

Jun
29
4 months ago
Activity icon

Started a new Conversation Marking Overlapping Events Per Resource (FullCalendar 5)

Using resourceTimelineWeek of FullCalendar 5, I need to check for overlapping events -- not in general but per resource. The goal is to make a red border around the events when they overlap for one resource. I just can't a grip on how to implement this in Laravel 7 using Eloquent. I am getting my events for all resources I want to apply the check on with

protected $appends = ['color','borderColor'];

$events = Toolplan::query()
   ->select('id', 'eventId', 'resourceId', 'title', 'start', 'end')
   ->where(function ($query) use ($start, $end) {
       $query
        ->where(function ($q) use ($start, $end) {
           $q->whereDate('start', '>=', $start)->whereDate('end', '<=', $end);
         })
         ->orWhere(function ($q) use ($start, $end) {
           $q->whereDate('start', '<=', $start)->whereDate('end', '>=', $end);
         })
         ->orWhere(function ($q) use ($start, $end) {
           $q->whereDate('end', '>=', $start)->whereDate('end', '<=', $end);
         })
         ->orWhere(function ($q) use ($start, $end) {
           $q->whereDate('start', '>=', $start)->whereDate('start', '<=', $end);
         });
   })
->whereIn('eventId', $processIds)
->get(); 
return json_encode($events);

in my Toolplan.php and would like to work with an Accessor I have also defined in my Toolplan.php:

    public function getBorderColorAttribute($value)
    {
      $overlaps = $this->eventOverlaps();
      if($overlaps)
        return 'Red';
      return $this->color;
    }    

The issue is now that I need to determine if two events overlap for one resource and that's where I'm stuck:

    public function eventOverlaps()
    {
        (...) // ???
    	  return true;
    	
      return false;
    } 

I don't know if I'm on the right track with this approach. I am grateful for any hint in the right direction.

Jun
28
4 months ago
Activity icon

Replied to Adding WhereIn To OrWhere Functions In Database Query

Yeah, it works, thank you!

Activity icon

Replied to Adding WhereIn To OrWhere Functions In Database Query

I am pretty sure the orWhere conditions are not repetitive. It's for getting overlapping events in a FullCalendar timespan view, so it's about 1) overlapping to the left, 2) to the right, 3) overlapping left and right and 4) being fully in timespan. Will try the callback, thanks.

Activity icon

Awarded Best Reply on Request Parameters From FullCalendar Not Received In Route

It's working now, with the exact same code I showed above. I reinstalled Wamp, set up a fresh Laravel and installed FullCalendar. No idea what it was, bit frustrating. I read in other posts that certain php settings could prevent request but that would not explain why it worked for other requests in my app. Nevermind.

@bobbybouwmann : No, FullCalendar sends start and end request parameters automatically, you don't have to do this explicit. You can check this in network traffic.

Activity icon

Started a new Conversation Adding WhereIn To OrWhere Functions In Database Query

I am struggling to add a whereIn to a more complex query:

      $events = Toolplan::query()
        ->select('id', 'eventId', 'resourceId', 'title', 'start', 'end')
        ->where(function ($query) use ($start, $end) {
            $query->whereDate('start', '>=', $start)->whereDate('end', '<=', $end);
        })
        ->orWhere(function ($query) use ($start, $end) {
            $query->whereDate('start', '<=', $start)->whereDate('end', '>=', $end);
        })
        ->orWhere(function ($query) use ($start, $end) {
            $query->whereDate('end', '>=', $start)->whereDate('end', '<=', $end);
        })
        ->orWhere(function ($query) use ($start, $end) {
            $query->whereDate('start', '>=', $start)->whereDate('start', '<=', $end);
        }) 
// gives "General error: 1096 No tables used":
        ->whereIn('eventId', function ($query) use ($eventIds){
           $query->whereIn('eventId', $eventIds);	
        })
// no effect: 
//      ->whereIn('eventId', $eventIds)
        ->get(); 

I tried to add it as a function and in simple form but the function leads to General error: 1096 No tables used and the other shows no effect at all, because the collection is far too large and should be only 2 items (for a certain timespan) after whereIn and the orWhere selection. $eventIds is a flat array:

["P000018","P000054","P000021","P000030"]
Jun
16
4 months ago
Activity icon

Replied to Get Events Which Overlap With FullCalendar View Start And End Date

500 : Internal Server Error ...it's an invalid query.

Activity icon

Replied to Request Parameters From FullCalendar Not Received In Route

It's working now, with the exact same code I showed above. I reinstalled Wamp, set up a fresh Laravel and installed FullCalendar. No idea what it was, bit frustrating. I read in other posts that certain php settings could prevent request but that would not explain why it worked for other requests in my app. Nevermind.

@bobbybouwmann : No, FullCalendar sends start and end request parameters automatically, you don't have to do this explicit. You can check this in network traffic.

Activity icon

Replied to Get Events Which Overlap With FullCalendar View Start And End Date

No luck so far with

$events = DB::table('events')->select('id','resourceId','title','start','end')
  ->whereDate('start', '>=', $start)->whereDate('end', '<=', $end)
  ->orWhere(function($query) {
    $query->whereDate('start', '<=', $start)
                 ->whereDate('end', '>=', $end);
    })
  ->get();

Is orWherenot supposed to work with whereDate?