Skip to content

Instantly share code, notes, and snippets.

@chongkan
Created September 3, 2015 02:47
Show Gist options
  • Save chongkan/0e45b3f3b293efb604b2 to your computer and use it in GitHub Desktop.
Save chongkan/0e45b3f3b293efb604b2 to your computer and use it in GitHub Desktop.
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