mardi 26 janvier 2016

Cannot read property 'hasTime' of undefined

I'm using FullCalendar to display staff hours on a Calendar.

I'm pulling the events via an ajax call like so:

"events": function(start, end, timezone, callback) {

  //create the data to be sent
  var objectToSend = {
    "start_date": start.format("YYYY-MM-DD"),
    "finish_date": end.format("YYYY-MM-DD"),
  };

  //craft and make the request
  $.ajax({
    url: 'calendar/test',
    data: objectToSend,
    type: 'POST',
    cache: false
  }).done(function(data) {
    //on success call `callback` with the data
    callback(data)
  })
}

This works perfectly fine, however I am getting an error showing in my console "Uncaught TypeError: Cannot read property 'hasTime' of undefined" and that this is coming from fullcalendar.min.js:6.

I'm not very fluent in JavaScript, but my searching suggests that I either haven't provided the right dates or have junk data in there.

As far as I can tell I am providing all the right data. The function generating the data looks like so:

public function test(Request $request) {
  $start_date = Input::get('start_date');
  $finish_date = Input::get('finish_date');

  $shifts = Roster::whereBetween('date', array($start_date, $finish_date)) - > get();

  foreach($shifts as $shift) {
    $start = $shift - > date.
    ' '.$shift - > start_time;
    $finish = $shift - > date.
    ' '.$shift - > finish_time;

    $events[] = array(
      'title' => $shift - > staff - > first_name,
      'start' => Carbon::createFromFormat('Y-m-d H:i:s', $start) - > toDateTimeString(),
      'end' => Carbon::createFromFormat('Y-m-d H:i:s', $finish) - > toDateTimeString(),
      'id' => $shift - > id,
      'allDay' => false
    );
  }

  return json_encode($events);
}

which outputs:

[{"title":"Gemma","start":"2016-02-01 18:00:00","end":"2016-02-01 22:00:00","id":1,"allDay":false},
{"title":"Gemma","start":"2016-01-26 18:00:00","end":"2016-01-26 22:00:00","id":49,"allDay":false}]

Can anyone spot what I am doing wrong? I am simply trying to use this to render my events for the given month.

Edit: output of console.log(data)

It prints out:

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

Opening this up I get:

0: Object

Opening this up I get:

allDay: false
end: "2016-02-01 22:00:00"
id: 1
start: "2016-02-01 18:00:00"
title: "Gemma"



via Chebli Mohamed

lundi 25 janvier 2016

Laravel ORM - Custom GroupBy Month JSON Response

I currently I have a model like this-

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class UserSlidePhoto extends Model
{
    protected $table="users_slides_photos";
    protected $fillable=['user_id','social_image_id','original_image_name','provider_key','provider_id','thumbnail_name'];

    public $timestamps = true;

    public function users()
    {
        return $this->belongsTo('App\User')->withTimestamps();
    }
}

And a controller like this-

public  function rearrangePhotoMonth(Request $request)
{
    //$ordering = $request->input('ordering');
    $thumbs = url('/uploads/userfiles/thumbs/')."/";
    $images = url('/uploads/userfiles/images/')."/";
    return UserSlidePhoto::where('user_id', Auth::id())
                  ->selectRaw(
                                "id,
                                CONCAT('".$thumbs."',thumbnail_name) AS thumbnail_url,
                                CONCAT('".$images."',original_image_name) AS original_image_url"
                              )
                  ->get();
}

And I am getting JSON response like this-

[
  {
    "id": 2,
    "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-YgLYcr5DsB3kHjpa7cxcznjiEFdzeF.png",
    "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-YgLYcr5DsB3kHjpa7cxcznjiEFdzeF.png"
  },
  {
    "id": 4,
    "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-A7rlDeFmMybmXNUtcxKyEtzM9TPywq.png",
    "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-A7rlDeFmMybmXNUtcxKyEtzM9TPywq.png"
  },
  {
    "id": 1,
    "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-Xfvn6b8rnE4loZjZOlv14c0FZYVT3A.png",
    "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-Xfvn6b8rnE4loZjZOlv14c0FZYVT3A.png"
  },
  {
    "id": 7,
    "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-aZa54HnAqwY2DPMlSVI2UpbRohVTlY.png",
    "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-aZa54HnAqwY2DPMlSVI2UpbRohVTlY.png"
  }
]

But I like to get response like this-

[
  {
    "month": "January 2015",
    "data": {
      {
        "id": 6,
        "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-WujsXF8iNSuwxQX4QRebKkOqFinlJV.png",
        "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-WujsXF8iNSuwxQX4QRebKkOqFinlJV.png"
      },
      {
        "id": 8,
        "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-VcgQcjoi0iXM2YOqhgt0fYUZf8kwsE.png",
        "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-VcgQcjoi0iXM2YOqhgt0fYUZf8kwsE.png"
      },
      {
        "id": 5,
        "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-r6jxeFfV7nnLrMxO5l88sC7Pt0Xq1A.png",
        "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-r6jxeFfV7nnLrMxO5l88sC7Pt0Xq1A.png"
      }
    }
  },
  {
    "month": "March 2015",
    "data": {
      {
        "id": 2,
        "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-YgLYcr5DsB3kHjpa7cxcznjiEFdzeF.png",
        "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-YgLYcr5DsB3kHjpa7cxcznjiEFdzeF.png"
      },
      {
        "id": 9,
        "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-ivnXQ5ZA1y2mVVxcRtmH3UFd41Xdg3.png",
        "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-ivnXQ5ZA1y2mVVxcRtmH3UFd41Xdg3.png"
      }
    }
  },
  {
    "month": "January 2016",
    "data": {
      {
        "id": 3,
        "thumbnail_url": "http:\/\/localhost:8000\/uploads\/userfiles\/thumbs\/2-NfMq71wghF7Al3Fn4KS3SG9ylC4ayo.png",
        "original_image_url": "http:\/\/localhost:8000\/uploads\/userfiles\/images\/2-NfMq71wghF7Al3Fn4KS3SG9ylC4ayo.png"
      }
    }
  }
]

Can anyone please help?



via Chebli Mohamed

JWT Token Expiry inconsistent

I'm still new to laravel, api, as well as JWT. Is there anyone using tymon jwt?

I have been troubling with the Token Expiry. When ever it gets expired, it shows 2 different kinds of errors. Usually, it is just plainly {message: "token_expired"} with a status code of 401, which is fine. But, sometimes it shows up this kind of error, wherein it says it comes from a PayloadValidator, and which I could not trap where I can trigger this. It is a problem for me because its status code is 500 and our frontend developers do not want status code 500.

I would like to make it 400, or rather just have a consistent error response Is there anyone here could help me understand why there 2 kinds of error? How were these encountered?

Inconsistent TokenExpiry Response



via Chebli Mohamed

Fatal error: Class 'Artisaninweb\SoapWrapper\ServiceProvider' not found

how to fix this problem in laravel 5.1. Did I forgot something in following this steps http://ift.tt/WwvM9R . Also I'm a little bit confused where to put this register class alias:

class_alias('Artisaninweb\SoapWrapper\Facades\SoapWrapper', 'SoapWrapper');

Thanks! :)



via Chebli Mohamed

Laravel 5.1 Session not working

i have Session in my Controller store

public function store(Request $request)
{
\Session::push('store_pos.items',$request->all());
print_r(\Session::get('store_pos.items')); // This is show array
exit;
}

public function create()
{
$items = \Session::get('store_pos.items');
print_r($items); // in this syntax not show array
}

why session in function create not show ? I've been using the session put but still does not appear

Thanks



via Chebli Mohamed

Pass the data in the many to many relation ship in laravel

I have create a form that will show the user the event title, event description. And the code

public function show($id){

            $showevents = Events::findOrFail($id);
            return view('events.show',compact('showevents'));
    }

This data i pass dont have the user data, but it will give me the specific event data. My question is how to pass the user data along with this? Because my event table dont have the user information, it all in the user table. I try {{$showevents->user->name}} in the view form, but it doesnt give me the information of the user.



via Chebli Mohamed

Uploading file gives error

I need to upload .xlsx file to database . I have 3 column in db value,pin_num,password_num. my code is like this

 public function import(Request $request)
    {
        if($request->hasFile('file'))
        {
            $files = $request->file('file');

            $file = fopen($files, "r");
            while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
            {
                 $excel = new Excel;
                 $excel->value = $emapData[0];
                 $excel->pin_num = $emapData[1];
                 $excel->password_num = $emapData[2];

                 $excel->save();

            }

        }
       return Redirect::to('dashboard/file/view');

This upload .csvfile successfullly but it gives error on uploading.xlsx file Error is like this

Undefined offset: 1
in AdminController.php line 36
at HandleExceptions->handleError('8', 'Undefined offset: 1', '/var/www/html/project/app/Http/Controllers/Backend/Admin/AdminController.php', '36', array('request' => object(Request), 'files' => object(UploadedFile), 'file' => resource, 'emapData' => array('PK!q9+p��[Content_Types].xml ��(�̔MN�0��H�!�%n��j�?K��ؓƪc[���g��'), 'excel' => object(Excel))) in AdminController.php line 36

on dd($emapData); it gives below result

array:1 [▼
  0 => b"PK\x03\x04\x14\x00\x06\x00\x08\x00\x00\x00!\x00q\x0E9+p\x01\x00\x00 \x05\x00\x00\x13\x00Û\x01[Content_Types].xml ¢×\x01( \x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Ì”MNÃ0\x10…÷HÜ!ò\x16%n‹„\x10jÚ\x05?K¨\x04\x1CÀؓƪc[\x1E·´·g’Ð"
]

How to upload xlsx file?How to modify this code?



via Chebli Mohamed