Beispiel #1
0
 public function createLink(Request $request)
 {
     $parameters = $request->except(['_token']);
     $parameters['slug'] = Str::slug($parameters['name']);
     $date = new \DateTime(null);
     $link = new Links();
     $link->name = $parameters['name'];
     $link->link = $parameters['link'];
     $link->description = $parameters['description'];
     $link->slug = $date->format('dmYhis') . '-' . Str::slug($parameters['name']);
     $link->save();
     return redirect()->route('listLink')->with('success', 'Item was added !');
 }
 /**
  * Display a listing of categories and the category members (parent-children) and their social media.
  *
  * @return Response
  */
 public function index($slug)
 {
     // get links in footer
     $linksArr = \App\Links::orderBy('rank', 'ASC')->lists('link', 'name');
     if ($slug != 'all') {
         $catObj = Category::whereSlug($slug)->first();
         if (is_null($catObj)) {
             \Session::flash('message', 'Invalid category');
             return redirect('/socialmedia/all');
         }
         $catPathArr = $catObj->getCategoryPath($slug);
         $catArr = $catObj->getChildren($catObj->id);
     } else {
         $catPathArr = array();
         $catObj = new Category();
         $catArr = $catObj->getParents();
     }
     $getChildren = $this->getChildrenBool($catPathArr, $slug, $catObj);
     // eg. get the teammates on the Lakers, don't get teams in the Pacific Coast division
     if ($getChildren) {
         $memberArr = $this->memberObj->getMembersWithinSingleCategory($catObj->id);
         list($memberArr, $contentArr) = $this->memberSocialObj->getSocialMediaWithMemberIds($memberArr);
         return view('socialmedia.child', compact('memberArr', 'contentArr', 'catPathArr', 'linksArr'));
     } else {
         $parentArr['contentArr'] = [];
         foreach ($catArr as $catId => $catName) {
             $memberArr = $this->memberObj->getMembersWithinSingleCategory($catId);
             $tmpMemberArr = array($memberArr[0]);
             list(, $contentArr) = $this->memberSocialObj->getSocialMediaWithMemberIds($tmpMemberArr);
             $parentArr['memberArr'][$catId] = $memberArr;
             $parentArr['contentArr'] = $parentArr['contentArr'] + $contentArr;
         }
         return view('socialmedia.parent', compact('parentArr', 'catArr', 'catPathArr', 'linksArr'));
     }
 }
Beispiel #3
0
 public function updateLink(Request $req, $id)
 {
     $link = Links::find($id);
     if ($req->isMethod('post')) {
         $parametres = $req->except(['_token']);
         $link->nom = $parametres['nom'];
         $link->link = $parametres['lien'];
         $link->description = $parametres['description'];
         $link->save();
         return redirect()->route('listLink')->with('ok', 'Lien modifié');
     }
     return view('link/addLink')->with('link', $link);
 }
Beispiel #4
0
 public static function recent($paginate = 15)
 {
     return Links::with('user', 'category')->published()->orderBy('published_at', 'desc')->orderBy('created_at', 'desc')->paginate($paginate);
 }
Beispiel #5
0
 /**
  * @param Request $request
  * @return static
  */
 protected function saveLink(Request $request)
 {
     return Links::create(['category_id' => $request->category_id, 'user_id' => auth()->user()->id, 'title' => $request->title, 'url' => $request->url, 'description' => $request->description]);
 }
Beispiel #6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Links::whereId($id)->delete();
     return Redirect::route('links.index')->with('message', 'Link deleted.');
 }
Beispiel #7
0
 public function run()
 {
     DB::table('links')->truncate();
     factory(App\Links::class, 10)->create();
     \App\Links::create(['category_id' => 2, 'user_id' => 1, 'title' => 'Laravel Permission', 'url' => 'https://github.com/spatie/laravel-permission', 'description' => 'This package allows to save permissions and roles in a database.', 'published' => 1]);
 }
Beispiel #8
0
 /**
  * Redirect to the URL
  * @param  string $code URL hash
  * @return [type]       [description]
  */
 public function redirect($code)
 {
     $link = Links::whereCode($code)->first();
     header("Location:" . $link->url);
 }
Beispiel #9
0
 /**
  * Show the application dashboard.
  *
  * @return Response
  */
 public function index()
 {
     return view('home', ['links' => Links::recent()]);
 }
Beispiel #10
0
 /**
  * 
  */
 public function DeletePdf($id)
 {
     $link = Links::findOrFail($id);
     \File::cleanDirectory(storage_path('app') . $link->pdf);
     \File::deleteDirectory(storage_path('app/pdf/') . $link->id);
     $link->update(['pdf' => '']);
     return \Redirect::back()->with('message', 'Pdf Başarıyla Silindi!');
 }
 /**
  * Update to increase the downvotes of a link.
  *
  * @param  int  $id
  * @return Response
  */
 public function downvote($id)
 {
     //retrieve entry for current link
     if (is_null(Votes::where(['userid' => Auth::user()->id, 'linkid' => $id])->first())) {
         $link = Links::find($id);
         $link->downvotes += 1;
         $link->save();
         $newVote = Votes::create(['linkid' => $id, 'userid' => Auth::user()->id, 'vote' => -1]);
         $newVote->save();
     } else {
         return redirect()->action('LinkController@index')->withErrors(['You have already voted.']);
     }
     return redirect()->action('LinkController@index');
 }