Created
August 1, 2016 15:14
-
-
Save Moccine/9050d61efb8cea2c3d3186929a88dd3c to your computer and use it in GitHub Desktop.
Share Link via Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use App\Bookmark; | |
| use Illuminate\Http\Request; | |
| use App\Http\Requests; | |
| use Illuminate\Support\Facades\Auth; | |
| use Illuminate\Support\Facades\DB; | |
| use Illuminate\Support\Facades\Session; | |
| class BookmarkController extends Controller | |
| { | |
| public function __construct() | |
| { | |
| $this->middleware('auth', ['except' => ['index', | |
| 'gridBookmarks', | |
| 'listBookmarks', | |
| 'category', | |
| 'categories' | |
| ]]); | |
| } | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index() | |
| { | |
| $bookmarks = Bookmark::getBookmarks(); | |
| $categories = Bookmark::getCategories(); | |
| return view('bookmark.index', ['books' => $bookmarks, 'categories' => $categories]); | |
| } | |
| /** | |
| * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | |
| */ | |
| public function userBookmarks() | |
| { | |
| $bookmarks = Bookmark::getBookmarks(); | |
| $categories = Bookmark::getCategories(); | |
| return view('user.userbookmarks', ['books' => $bookmarks, 'categories' => $categories]); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create(Request $request) | |
| { | |
| $this->validate($request, [ | |
| 'url' => 'required|url', | |
| 'category' => 'required', | |
| ]); | |
| $bookmark = DB::table('bookmarks')->where('bm_url', $request->input('url'))->first(); | |
| if ($bookmark) { | |
| flash()->error('Error', 'This bookmark not added ** Exist!'); | |
| } else { | |
| $action = $request->user()->bookmarks()->create([ | |
| 'bm_url' => $request->input('url'), | |
| 'category' => $request->input('category') | |
| ]); | |
| flash()->success('Success', 'Bookmark added !!'); | |
| } | |
| return redirect()->route('allUserLink'); | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy(Request $request, $id) | |
| { | |
| flash()->overlay('Suppresion', 'Suppresion'); | |
| $bookmark = Bookmark::findOrfail($id); | |
| if (Auth::id() == $bookmark->user_id) { | |
| $bookmark->delete(); | |
| $request->session()->flash('1', 'Task was successful!'); | |
| } | |
| $request->session()->flash('2', 'Task was failled!'); | |
| return redirect()->back(); | |
| } | |
| /** | |
| * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | |
| */ | |
| public function createForm() | |
| { | |
| return view('bookmark.createForm'); | |
| } | |
| /** | |
| * @param Request $request | |
| * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | |
| */ | |
| public function profil(Request $request) | |
| { | |
| return view('bookmark.profil'); | |
| } | |
| /** | |
| * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | |
| */ | |
| public function categories() | |
| { | |
| $categories = Bookmark::getCategories(); | |
| $cat = array(); | |
| foreach ($categories as $category) { | |
| array_push($cat, strtolower($category->category)); | |
| } | |
| return view('bookmark.categories', ['categories' => $cat]); | |
| } | |
| public function category(Request $request, $category) | |
| { | |
| $categories = DB::table('bookmarks')->where('category', $category)->get(); | |
| return view('bookmark.category', ['categories' => $categories, 'cat' => $category]); | |
| } | |
| public function listBookmarks() | |
| { | |
| $bookmarks = Bookmark::getBookmarks(); | |
| return view('bookmark.listBookmarks', ['books' => $bookmarks]); | |
| } | |
| public function gridBookmarks() | |
| { | |
| $bookmarks = Bookmark::getBookmarks(); | |
| return view('bookmark.gridBookmarks', ['books' => $bookmarks]); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment