/**
  * Create a new Favourite instance after a valid submission.
  *
  * @param  array  $data
  * @return Snippet
  */
 protected function create(array $data)
 {
     $favourite = Favourite::create();
     $favourite->user()->associate(Auth::user());
     $favourite->snippet()->associate(Snippet::find($data['snippet_id']));
     $favourite->save();
     return $favourite;
 }
示例#2
0
 public function generateCode()
 {
     if ($this->code == null) {
         $code = substr(md5(microtime()), rand(0, 26), 8);
         while (Snippet::where('code', $code)->count() != 0) {
             $code = substr(md5(microtime()), rand(0, 26), 8);
         }
         $this->code = $code;
         return $code;
     }
 }
 /**
  * Create a new Snippet instance after a valid submission.
  *
  * @param  array  $data
  * @return Snippet
  */
 protected function create(array $data)
 {
     $snippet = new Snippet();
     $snippet->name = $data['name'];
     $snippet->extension = strtolower($data['extension']);
     $snippet->description = $data['description'];
     $code = $snippet->generateCode();
     $snippet->updateContents(File::get($data['file']));
     $snippet->author()->associate(Auth::user());
     $snippet->save();
     return $snippet;
 }