Created
September 3, 2015 02:47
-
-
Save chongkan/0e45b3f3b293efb604b2 to your computer and use it in GitHub Desktop.
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
public function update(UpdateCampaignRequest $request, $id) | |
{ | |
$campaign = Campaign::findOrFail($id); | |
//A. Update all Regular Fields | |
$campaign->update($request->all()); | |
//B. Update Terms | |
// B.1. Delete all terms to write a new list | |
$campaign->terms()->delete(); | |
// B.2. Assign the fresh terms list | |
$myTerms = $request->input('myTerms'); | |
$myTerms = rtrim($myTerms, ','); | |
$terms = explode(',', $myTerms); | |
foreach($terms as $term){ | |
$term = strtolower($term); | |
$new_term = Term::firstOrNew(['term' => $term]); | |
$new_terms[] = $new_term; | |
} | |
$campaign->terms()->saveMany($new_terms); | |
//dd($campaign); | |
//$term = Term::create($request->all()); | |
return redirect()->route('admin.campaigns.index'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment