/**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('articles', function ($id) {
         return Article::published()->findOrFail($id);
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     $router->bind('articles', function ($id) {
         $article = Article::findOrFail($id);
         // If the owner return all articles else return only published.
         if (Auth::user() && $article->user_id === Auth::user()->id) {
             $articles = Article::findOrFail($id);
         } else {
             $articles = Article::published()->findOrFail($id);
         }
         return $articles;
     });
     $router->bind('questions', function ($id) {
         return Question::findOrFail($id);
     });
     $router->bind('answers', function ($id) {
         return Answer::findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return Tag::where('name', $name)->firstOrFail();
     });
     $router->bind('users', function ($id) {
         return User::findOrFail($id);
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     /**
      * Binding the model
      */
     // $router->model('articles', 'App\Article');
     /**
      * Optional custom bind
      */
     $router->bind('articles', function ($id) {
         /**
          * Show only the published articles
          */
         return \App\Article::published()->findOrFail($id);
     });
     // $router->model('tags', 'App\Tag');
     $router->bind('tags', function ($name) {
         /**
          * Show only the related same tag by name
          */
         return \App\Tag::where('name', $name)->firstOrFail();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     /*Route::model*/
     /**
      * Route model binding altering default logic
      * $router->bind('articles',function($id){
      *     return \App\Article::published()->findOrFail($id);
      * });
      */
     /*Using wildcard*/
     /*$router->model('articles','App\Article');*/
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('rates', function ($id) {
         return \App\Rate::where('id', $id)->firstOrFail();
     });
     $router->bind('customers', function ($id) {
         return \App\Customer::where('id', $id)->firstOrFail();
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     $router->bind('motherboards', function ($name) {
         return \App\Motherboard::where('name', $name)->firstOrFail();
     });
 }
Example #5
0
 public function getCoursesInCategory($slug)
 {
     $articles = Article::published()->orderBy('published_at', 'desc')->take(2)->get();
     $category = Category::where('slug', $slug)->first();
     $courses = Course::published()->where('category_id', $category->id)->get();
     return view('courses.index', ['courses' => $courses, 'page_id' => $slug, 'category' => $category, 'latest_articles' => $articles]);
 }
Example #6
0
 public function show($slug)
 {
     $page = Page::where('slug', $slug)->first();
     $courses = Course::published()->hasCategory()->orderBy('created_at', 'desc')->take(4)->get();
     $articles = Article::published()->orderBy('published_at', 'desc')->take(2)->get();
     return view('pages.show', ['page' => $page, 'latest_courses' => $courses, 'latest_articles' => $articles]);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->model('articles', 'App\\Article');
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('articles', function ($id) {
         return \Route::currentRouteName() == "articles.edit" ? \App\Article::findOrFail($id) : \App\Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('articles', function ($id) {
         return Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($tags) {
         return Tag::where('name', $tags)->first();
     });
     parent::boot($router);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\tag::where('name', $name)->firstOrFail();
     });
 }
 public function edit($id)
 {
     if (Auth::user()->name === 'Penna') {
         $article = Article::published()->findOrFail($id);
         if (Auth::user()->id == $article->user_id) {
             return view('edit', compact('article'));
         } else {
             return redirect('/');
         }
     }
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     //$router->model('articles', 'App\Article');
     //\Illuminate\Support\Facades\Route::model('articles', 'App\Article');
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
         //return \App\Article::findOrFail($id);
     });
 }
 private function composeSidebar()
 {
     view()->composer('blog.partials.side', function ($view) {
         $allCategories = \App\Category::getSortedCategories();
         $NewestArticles = \App\Article::published()->orderBy('updated_at', 'desc')->take(10)->get();
         $view->with(compact('allCategories', 'NewestArticles'));
     });
     view()->composer('home.partials.side', function ($view) {
         $NewestArticles = \App\Article::published()->orderBy('updated_at', 'desc')->take(10)->get();
         $view->with(compact('NewestArticles'));
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     //$router->model('articles', 'App\Article');
     /**
      *Tuong tu cho ham ben tren
      */
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('tag', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     /**
      * Bind the wildcard 'articles' with the model App\Article for use in Route Model Binding.
      */
     //$router->model('articles', 'App\Article');
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     //bind the "articles" widlcard key to Article models
     //$router->model("articles", "App\Article");
     //more complex bind that does the same thing, but can also do more complex things
     $router->bind("articles", function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind("tags", function ($name) {
         return \App\Tag::where("name", $name)->firstOrFail();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('tag', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     //        $router->model('articles', 'App\Article'); // binds it to the articles model
     // or Route::model->model(...)
     // is a facade  - pointers to a registered underlying class
 }
Example #18
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     // $router->model('articles', 'App\Article');
     $router->bind('articles', function ($slug) {
         return \App\Article::published()->whereSlug($slug)->firstOrFail();
     });
     $router->bind('tags', function ($slug) {
         return \App\Tag::whereSlug($slug)->firstOrFail();
     });
     $router->bind('users', function ($slug) {
         return \App\User::whereSlug($slug)->firstOrFail();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     //$router->model('article', 'App\Article');//
     $router->bind('article', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     //$router->model('tags', 'App\Tag');
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     $router->bind('songs', function ($slug) {
         //return App\Song::whereSlug($slug)->first();//App\Song::where('slug', $slug)->first()
         return \App\Song::where('slug', $slug)->firstOrFail();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     //$router->model('articles', 'App\Article');
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     // This would override default logic.
     /*$router->bind('articles', function($id)
       {
           return \App\Article::published()->findOrFail($id);
       });*/
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //once the laravel app is bootstraped and ready to do the following
     parent::boot($router);
     //note: doing this isn't necessary and in some cases may
     // be inappropriate to do
     //here we are binding the specific route wildcard to the
     //Article Model
     //Note: to view wildcards use the route:list command
     //wildcards go inbetween {} ex /articles/{wildcard}
     //$router->model('articles', 'App\Article');
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->findOrFail($name);
     });
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('partials.latestArticles', function ($view) {
         $latestArticles = Article::published()->active()->latest()->take(10)->get();
         $view->with(['latestArticles' => $latestArticles]);
     });
     view()->composer('partials.latestCourses', function ($view) {
         $latestCourses = Course::latest()->take(10)->get();
         $view->with(['latestCourses' => $latestCourses]);
     });
     view()->composer('partials.latestSessions', function ($view) {
         $latestSessions = Session::latest()->take(10)->get();
         $view->with(['latestSessions' => $latestSessions]);
     });
     view()->composer('partials.categories', function ($view) {
         $totalCategories = DB::table('categories')->where('depth', '=', 1)->leftJoin('category_course', 'categories.id', '=', 'category_course.category_id')->leftJoin('article_category', 'categories.id', '=', 'article_category.category_id')->groupBy('categories.id')->select('categories.name', 'categories.id', DB::raw('COUNT(`course_id`) + COUNT(`article_id`) AS num'))->orderBy('num', 'DESC')->get();
         $view->with(['totalCategories' => $totalCategories]);
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     //$router->model('articles', 'App\Article');// Binding wildcard articles key to instance of 'App\Article'
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     /*
              * Incase we need to override default logic for route-model binding
              * such as incase we need to have different "WHERE" calluses on items in addition to "id".
              * 
              * $router->bind('articles', function($id){
                 return \App\Article::published()->findOrFail($id);
             });*/
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     //$router->model('tags', 'App\Tag');// it would search for key, we need to search for name like above using "$router->bind"
 }
Example #24
0
 public function index($page = 1)
 {
     $page = max(1, $page * 1);
     $per_page = 12;
     $skip = ($page - 1) * $per_page;
     // ------------------------------------------------------------------------------------------------------------
     // QUERY ARTICLE
     // ------------------------------------------------------------------------------------------------------------
     $article_count = Cache::remember('published_article_count', 15, function () {
         return Article::published()->count();
     });
     $articles = Cache::remember('latest_articles_page' . $page, 15, function () use($skip, $per_page) {
         return Article::published()->with('images')->latest('published_at')->skip($skip)->take($per_page)->get();
     });
     if (!$articles->count()) {
         App::abort(404);
     }
     $start_pagination = max(1, $page - 3);
     $last_pagination = min(ceil($article_count / $per_page), $page + 3);
     // ------------------------------------------------------------------------------------------------------------
     // SHOW DISPLAY
     // ------------------------------------------------------------------------------------------------------------
     $this->layout->page = view($this->page_base_dir . 'blogs');
     $this->layout->page->articles = $articles;
     $this->layout->page->article_count = $article_count;
     $this->layout->page->start_pagination = $start_pagination;
     $this->layout->page->last_pagination = $last_pagination;
     $this->layout->page->top_destinations = $this->get_top_destinations();
     $this->layout->page->current_page = $page;
     $this->layout->page->latest_tours = $this->get_latest_tours();
     $this->layout->title = 'Travel Blog ' . ($page > 1 ? ' Halaman ' . $page : '') . ' - Capcus.id';
     $this->layout->og['title'] = $this->layout->title;
     $this->layout->og['type'] = 'website';
     $this->layout->og['image'] = $articles->count() ? $articles->first()->images->where('name', 'LargeImage')->first()->path : asset('images/logo-black.png');
     $this->layout->og['image:type'] = pathinfo('images/' . $this->layout->og['image'], PATHINFO_EXTENSION);
     $this->layout->og['image:width'] = 600;
     $this->layout->og['image:height'] = 400;
     return $this->layout;
 }
Example #25
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('articles', function ($slug) {
         return \Route::currentRouteName() == "articles.edit" ? \App\Article::findOrFail($slug) : \App\Article::published()->findOrFail($slug);
     });
     $router->bind('news', function ($id) {
         return \Route::currentRouteName() == "news.edit" ? \App\News::findOrFail($id) : \App\News::published()->findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     $router->bind('users', function ($id) {
         return \App\User::where('id', $id)->firstOrFail();
     });
     $router->bind('messages', function ($id) {
         return \App\Message::where('id', $id)->firstOrFail();
     });
     $router->bind('registrants', function ($id) {
         return \App\Registrant::where('id', $id)->firstOrFail();
     });
     $router->model('image', Image::class);
 }
Example #26
0
 public function index()
 {
     return view('articles.index', ['articles' => Article::published()->simplePaginate()]);
 }
Example #27
0
 public function index()
 {
     $articles = Article::published()->latest()->paginate(15);
     return view('article.list', compact('articles'))->with(['title' => 'مقالات نمآموز']);
 }
 public function show($id)
 {
     //  dd($id);
     $article = Article::published()->findOrFail($id);
     //        dd($article);
     // dd($articles->published_at->diffForHumans());
     return view('articles.show', compact('article'));
 }
Example #29
0
 public function index()
 {
     $articles = Article::published()->orderBy('published_at', 'desc')->get();
     $courses = Course::published()->hasCategory()->orderBy('created_at', 'desc')->take(3)->get();
     return view('articles.index', ['articles' => $articles, 'latest_courses' => $courses]);
 }
Example #30
0
 public function index()
 {
     $pagination = Article::published()->latest('published_at')->paginate(6);
     $articles = $pagination->chunk(3);
     return view('blog.index', compact('articles', 'pagination'));
 }