Last active
November 1, 2016 10:43
-
-
Save AdrianKuriata/490619b03b9910f15d9bd9f9a9c07100 to your computer and use it in GitHub Desktop.
Revisions
-
AdrianKuriata revised this gist
Nov 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -29,5 +29,5 @@ public function storePost(Request $request) $getTagsId = Tag::whereIn('id', $createdTags)->pluck('id')->toArray(); //Add exists and not exists tags to one array for save it with attach posts $tagsToAdd = array_merge($exTags, $getTagsId); } -
AdrianKuriata renamed this gist
Nov 1, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
AdrianKuriata created this gist
Nov 1, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ public function storePost(Request $request) { $notexistsTags = array(); $existsTags = Tag::whereIn('id', $request->input('tag_name'))->get(); foreach($request->input('tag_name') as $tag_name) { // Check if tag currently exist in database foreach($existsTags as $tag) { $match = false; if($tag_name == $tag->id) { $match = true; break; } } // If tag from user's input was not matched to tag in database // add it to the $notexistsTags array. if(!$match) { $notexistsTags['tag_name'] = $tag_name; } } //Get a pluck ID exists tags $exTags = $existsTags->pluck('id')->toArray(); //Create not exists tags $createdTags = Tag::create($notexistsTags); //Get ID tags which was created $getTagsId = Tag::whereIn('id', $createdTags)->pluck('id')->toArray(); //Add exists and not exists tags to one array for save it with attach posts $tagsToAdd = array_merge($eTags, $getTagsId); }