/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($code)
 {
     if (Gate::denies('show-news')) {
         abort(403);
     }
     $news = News::getByPublicCode($code);
     return $this->edit($news);
 }
 public function getExternalNewsInfo($id, $name)
 {
     $news = News::with('translations')->findOrFail($id);
     if ($name != Str::slug($news->title)) {
         abort(403);
     }
     return view('frontend.external.news', compact('news'));
 }
 public function testStakeholdersConnected_RemovesOne_TheOthersAreStillThere()
 {
     // Initial state
     // a-->b
     // a-->c
     // Remove a-->c, result should be
     $a_news = $this->newsData();
     $a = News::create($a_news);
     $b_stakeholder = $this->stakeholderData();
     $b = Stakeholder::create($b_stakeholder);
     $c_stakeholder = $this->stakeholderData();
     $c = Stakeholder::create($c_stakeholder);
     // Connect a-->b, a-->c
     $a_news['stakeholders_connected'] = [$b->id, $c->id];
     $response = $this->call('PUT', action('NewsController@update', [$a]), $a_news);
     $this->assertEquals(200, $response->status());
     //news a won't be connected with stakeholder c
     $a_news['stakeholders_connected'] = [$b->id];
     $response = $this->call('PUT', action('NewsController@update', [$a]), $a_news);
     // Check a-x->c
     $c_found = false;
     foreach ($a->connectedStakeholders as $sc) {
         if ($sc->id == $c->id) {
             $c_found = true;
         }
     }
     $this->assertFalse($c_found);
     // Check a-->c
     $b_found = false;
     foreach ($a->connectedStakeholders as $sc) {
         if ($sc->id == $b->id) {
             $b_found = true;
         }
     }
     $this->assertTrue($b_found);
     $c->delete();
     $b->delete();
     $a->delete();
 }
 public function queryNews(Request $request)
 {
     $queryNewsName = $request->name;
     $newsIds = NewsTranslation::where('title', 'like', '%' . $queryNewsName . '%')->where('locale', \App::getLocale())->lists('news_id');
     $news = News::whereIn('id', $newsIds)->with(['translations'])->get();
     $result = [];
     foreach ($news as $n) {
         $result[] = ['id' => $n->id, 'name' => $n->title];
     }
     return $result;
 }
 protected function importNewsStakeholder()
 {
     $newsStakeholders = DB::connection('oldissue')->select('select id,author from relatednewsandstatments');
     foreach ($newsStakeholders as $newsStakeholder) {
         if ($newsStakeholder->author !== NULL && $newsStakeholder->author !== "Array") {
             $stakeholderConnected = News::find($newsStakeholder->id);
             $connectedNews = explode(',', $newsStakeholder->author);
             try {
                 $stakeholderConnected->connectedStakeholders()->sync($connectedNews);
             } catch (\Exception $e) {
                 print_r("Shiit! O relatie nu s-a putut importa.\n");
             }
         }
     }
     print_r("Relatiile News - Stakeholder au fost adaugate cu succes.\n");
     return true;
 }