Created
February 6, 2017 07:37
-
-
Save itsrachelfish/f64e929eadf45d84e36bb1302ff1fe14 to your computer and use it in GitHub Desktop.
Issue with JSON fields in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shift {#278 ▼ | |
#fillable: array:10 [▶] | |
#connection: null | |
#table: null | |
#primaryKey: "id" | |
#perPage: 15 | |
+incrementing: true | |
+timestamps: true | |
#attributes: array:12 [▼ | |
"department_id" => "26" | |
"shift_data_id" => "56" | |
"dates" => "["2017-06-06","2017-06-08","2017-06-10","2017-06-12"]" | |
"start_time" => "0:00" | |
"end_time" => "24:00" | |
"duration" => "12:00" | |
"volunteers" => "4" | |
"start_date" => "2017-06-06" | |
"end_date" => "2017-06-12" | |
"updated_at" => "2017-02-06 07:34:14" | |
"created_at" => "2017-02-06 07:34:14" | |
"id" => 131 | |
] | |
#original: array:12 [▶] | |
#relations: [] | |
#hidden: [] | |
#visible: [] | |
#appends: [] | |
#guarded: array:1 [▶] | |
#dates: [] | |
#dateFormat: null | |
#casts: [] | |
#touches: [] | |
#observables: [] | |
#with: [] | |
#morphClass: null | |
+exists: true | |
+wasRecentlyCreated: true | |
#forceDeleting: false | |
} | |
"["2017-06-06","2017-06-08","2017-06-10","2017-06-12"]" | |
Shift {#278 ▼ | |
#fillable: array:10 [▶] | |
#connection: null | |
#table: null | |
#primaryKey: "id" | |
#perPage: 15 | |
+incrementing: true | |
+timestamps: true | |
#attributes: array:12 [▼ | |
"department_id" => "26" | |
"shift_data_id" => "56" | |
"dates" => "["2017-06-06","2017-06-08","2017-06-10","2017-06-12"]" | |
"start_time" => "0:00" | |
"end_time" => "24:00" | |
"duration" => "12:00" | |
"volunteers" => "4" | |
"start_date" => "2017-06-06" | |
"end_date" => "2017-06-12" | |
"updated_at" => "2017-02-06 07:34:14" | |
"created_at" => "2017-02-06 07:34:14" | |
"id" => 131 | |
] | |
#original: array:12 [▶] | |
#relations: [] | |
#hidden: [] | |
#visible: [] | |
#appends: [] | |
#guarded: array:1 [▶] | |
#dates: [] | |
#dateFormat: null | |
#casts: [] | |
#touches: [] | |
#observables: [] | |
#with: [] | |
#morphClass: null | |
+exists: true | |
+wasRecentlyCreated: true | |
#forceDeleting: false | |
} | |
[] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Create a new schedule | |
public function create(ScheduleRequest $request) | |
{ | |
$this->authorize('create-schedule'); | |
$input = $request->all(); | |
//... | |
$input['dates'] = json_encode($input['dates']); | |
//... | |
$schedule = Shift::create($input); | |
dump($schedule); | |
dump($schedule->dates); | |
// Generate slots based on schedule options | |
Slot::generate($schedule); | |
//... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
static public function generate(Shift $shift) | |
{ | |
//... | |
dump($shift); | |
dd($shift->dates); | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment