public function index() { $slider_objects = SliderObject::all(); $department_id = Auth::check() ? Auth::user()->department->id : 1; $role = Auth::check() ? Auth::user()->role->name : ''; if ($role === 'admin') { $articles = Article::latest('created_at')->paginate(6); } else { if ($role === 'editor') { $articles = Article::latest('published_at')->departmentArticles($department_id)->paginate(6); } else { if ($role === 'user') { $articles = Article::latest('published_at')->departmentArticles($department_id)->approved()->paginate(6); } else { $articles = Article::latest('published_at')->publicArticles()->approved()->paginate(6); } } } return view('articles.index', compact('slider_objects', 'articles', 'role')); }
public function destroy($id) { SliderObject::destroy($id); return redirect('articles'); }