/** * When a snippet is created, we should see it in the list. * * @return void */ public function testSnippetInfos() { $snippet = new Snippet(); $snippet->description = "MyDescriptionTest"; $snippet->namespace = "testNamespace"; $snippet->tags = "sublime-text"; $snippet->content = "MyContentTest{console.log(1337);}"; $snippet->save(); $this->visit(route('snippet.index'))->see($snippet->description)->see($snippet->content)->see($snippet->namespace)->see($snippet->tags)->see($this->getHtmlId($snippet->id)); }
public function numberOfViewsPerSnippet() { $snippets = Snippet::all(); $viewsPerSnippet = []; foreach ($snippets as $snippet) { $viewsPerSnippet[$snippet->name] = [$this->getCountOfViewsPerSnippet($snippet)]; } return $viewsPerSnippet; }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $snippet = Snippet::find($this->snippet); switch ($this->method()) { case 'POST': return ['description' => 'required|unique:snippets,description', 'content' => 'required', 'namespace' => 'required', 'tags' => 'required']; case 'PUT': case 'PATCH': return ['description' => 'required|unique:snippets,description,' . $snippet->id, 'content' => 'required', 'namespace' => 'required', 'tags' => 'required']; default: break; } }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { $sidebar = $this->sidebar; $snippets = Snippet::orderBy('created_at', 'desc')->paginate(15); $newsPickup = $this->news->orderBy('created_at', 'desc')->first(); // $redis = \Redis::connection(); // $unsubmittedUsers = $redis->lrange('unsubmittedUsers', 0, -1); // if (isset($snippets) && isset($newsPickup)) { return view('home')->with(compact('snippets', 'newsPickup', 'sidebar')); // } else { // list($snippets, $newsPickup) = array([],[]); // return view('home')->with(compact('snippets', 'newsPickup')); // } }
public function sendMail($id) { $file = Data::findOrFail($id); $pathToFile = $file->path; Mail::raw(Input::get('body'), function ($message) use($pathToFile, $file) { $message->to(Input::get('email')); $message->subject(Input::get('subject')); $message->attach($pathToFile, ['as' => $file->name, 'mime' => 'application/pdf']); }); if ($file->courseId != null) { $course = Course::findOrFail($file->courseId); return Redirect::action('CoursesController@showParam', [$course->slug]); } if ($file->snippetId != null) { $snippet = Snippet::findOrFail($file->snippetId); return Redirect::action('CoursesController@show', [$snippet->slug]); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { //TODO check if user is admin if (\Auth::user()->isUserAdmin()) { $snippet = Snippet::where('id', $id)->orWhere('slug', $id)->firstOrFail(); File::deleteDirectory($snippet->path_to_material); $snippet->delete(); return redirect('/snippets'); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $snippet = Snippet::findOrFail($id); $snippet->delete(); return redirect()->route('snippet.index')->with('message', 'Snippet well deleted.'); }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->snippet->reindex(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { return Snippet::all(); }
public function searchSnippets() { $searchTerm = Input::get('search-term'); $searchResults = Snippet::search($searchTerm)->get(); return view('search.showSnippets', compact('searchResults', 'searchTerm')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $deleteArray = explode(',', $id); if (count($deleteArray) == 0) { return $this->respondBadRequest('No snippet was selected to be deleted. Please select the snippets you want to delete by clicking on the checkboxes next to them'); } if (count($deleteArray) > 50) { return $this->respondBadRequest('You are not allowed to delete more than 50 snippets at one time'); } try { $messages = []; $resourceList = Snippet::whereIn('id', $deleteArray); $deletedCount = $resourceList->delete(); $messages['success'][] = $deletedCount . ' Snippet' . strtolower($deletedCount == 1 ? '' : 's') . ' deleted successfully.'; return $this->respondWithMessages($messages); } catch (Exception $e) { \Log::error($e->getTraceAsString()); return $this->respondInternalError($e->getMessage()); } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request, $id) { $input = $request->all(); if (array_key_exists('selected-tags', $input)) { $this->snippet->where('id', $id)->update(['title' => $input['title'], 'body' => $input['body']]); // スニペットにタグを紐付ける $snippet = Snippet::find($id); $snippet->tags()->detach(); $snippet->tags()->attach($input['selected-tags']); return redirect()->to("/snippet/{$id}"); } else { \Session::flash('snippetFormError', '必ずタグを選択してください'); $request->flashOnly('title', 'body'); return redirect()->back()->withInput(); } }