/** * Display a listing of the resource. * * @return Response */ public function index() { if (Auth::user()->can('view-vote')) { //Administrator able to see any vote return Vote::all(); } return Vote::where('user_id', Auth::user()->id)->get(); //Get standard users comment votes }
/** * Return home page * * @return \Illuminate\View\View */ public function getHome() { $lastNews = Category::find(1)->articles->sortBy('created_at')->first(); $lastEvent = Category::find(2)->articles->sortBy('created_at')->first(); $lastInterview = Category::find(3)->articles->sortBy('created_at')->first(); $users = User::all(); $randUser = $users[rand(0, $users->count() - 1)]; $votes = Vote::all()->where('status', 'pending'); $randVote = $votes[rand(0, $votes->count() - 1)]; return view('front.index', compact('lastNews', 'lastEvent', 'lastInterview', 'randUser', 'randVote')); }
/** * Execute the console command. * * @return mixed */ public function handle() { $now = Carbon::now(); foreach (Vote::all()->where('status', 'pending') as $vote) { $date = Carbon::parse($vote->date_end); if ($now->timestamp >= $date->timestamp) { $vote->status = 'archived'; $vote->save(); if ($vote->debates->first()) { Post::create(['user_id' => null, 'debate_id' => $vote->debates->first()->id, 'message' => '<p>Le vote est terminé. <a href="' . url('/forum/vote/' . $vote->id) . '">Les résultats sont consultables dans les archives.</a></p>']); } } } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store($aid, $vote1) { $id = Auth::id(); $vote2 = Vote::all(); foreach ($vote2 as $v) { if ($v->aid == $aid && $v->id == $id) { $voter = Vote::find($v->id); $voter->delete(); } } $vote = new Vote(); $vote->aid = $aid; $vote->id = $id; $vote->value = $vote1; $vote->save(); return redirect()->back(); }
/** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index(Artikel $artikel, User $user) { $votes = Vote::all(); $artikels = Artikel::with('user.votes')->orderBy('value', 'desc')->get(); return view('home')->with('artikels', $artikels)->with('votes', $votes); }
Route::get('/about', 'PagesController@about'); Route::get('/Register', 'RegisterController@create'); Route::post('/Register', 'RegisterController@store'); Route::get('/index', 'RegisterController@index'); Route::get('/Login', 'LoginController@create'); Route::post('/Login', 'LoginController@store'); Route::group(['middleware' => 'auth'], function () { Route::get('/Userhome', 'UserhomeController@create'); Route::get('/Question', 'QuestionController@create'); Route::post('/Question', 'QuestionController@store'); Route::get('/List', function () { $title = Question::all(); return view('List', ['title' => $title]); }); Route::get('Answer/{id}/{question}', function ($id, $question) { $user1 = User::all(); $answer1 = Answer::all(); $question1 = Question::all(); $vote2 = Vote::all(); return view('/Answer', ['question1' => $question1, 'answer1' => $answer1, 'id' => $id, 'user1' => $user1, 'vote2' => $vote2]); }); Route::post('Answer/{id}/{question}', 'AnswerController@store'); Route::get('Vote/{aid}/{vote1}', 'VoteController@store'); Route::get('/Logout', 'LogoutController@create'); }); Route::get('auth/login', function () { Cache::flush(); Session::flush(); return view('/Login'); }); Route::post('auth/login', 'LoginController@store');
public function getIndexArchived() { $votes = Vote::all()->sortByDesc('date_end')->where('status', 'archived'); return view('vote.indexArchived', compact('votes')); }