Last active
November 3, 2020 20:28
-
-
Save iamtomc/9598b2b9b72ddbc60557938379769a7b to your computer and use it in GitHub Desktop.
Laravel News Portal Gist
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 | |
| use Illuminate\Support\Facades\Schema; | |
| use Illuminate\Database\Schema\Blueprint; | |
| use Illuminate\Database\Migrations\Migration; | |
| class CreateSettingsTable extends Migration | |
| { | |
| /** | |
| * Run the migrations. | |
| * | |
| * @return void | |
| */ | |
| public function up() | |
| { | |
| Schema::create('settings', function (Blueprint $table) { | |
| $table->increments('id'); | |
| $table->string('site_name'); | |
| $table->string('site_logo')->default('logo.png'); | |
| $table->string('site_favicon')->default('favicon.ico'); | |
| $table->string('email'); | |
| $table->string('phone')->nullable(); | |
| $table->string('facebook')->nullable(); | |
| $table->string('twitter')->nullable(); | |
| $table->string('linkedin')->nullable(); | |
| $table->string('vimeo')->nullable(); | |
| $table->string('youtube')->nullable(); | |
| $table->text('about_us')->nullable(); | |
| $table->string('address')->nullable(); | |
| $table->integer('breaking_news_category_id')->nullable(); | |
| $table->timestamps(); | |
| }); | |
| } | |
| /** | |
| * Reverse the migrations. | |
| * | |
| * @return void | |
| */ | |
| public function down() | |
| { | |
| Schema::dropIfExists('settings'); | |
| } | |
| } |
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\Providers; | |
| use App\Menu; | |
| use App\News; | |
| use App\Setting; | |
| use App\Category; | |
| use App\Advertisement; | |
| use Illuminate\Support\Facades\Schema; | |
| use Illuminate\Support\ServiceProvider; | |
| class AppServiceProvider extends ServiceProvider | |
| { | |
| /** | |
| * Bootstrap any application services. | |
| * | |
| * @return void | |
| */ | |
| public function boot() | |
| { | |
| Schema::defaultStringLength(191); | |
| if (! $this->app->runningInConsole()) { | |
| view()->composer( | |
| [ | |
| 'frontend.layout.partials.header', | |
| 'frontend.layout.partials.footer' | |
| ], | |
| function($view) { | |
| $view->with('headersettings', Setting::first()); | |
| $view->with('headerads', Advertisement::get()); | |
| }); | |
| view()->composer('frontend.layout.partials.mainmenu', function($view) { | |
| $menus = Menu::all()->groupBy('parent_id'); | |
| $view->with('mainmenus', $menus); | |
| }); | |
| view()->composer('frontend.layout.partials.header', function($view) { | |
| $categoryid = Setting::first(); | |
| $newstickers = News::latest()->whereHas('category')->where('category_id',$categoryid->breaking_news_category_id)->where('status',1)->get(); | |
| $view->with('newstickers', $newstickers); | |
| }); | |
| view()->composer('frontend.layout.partials.footer', function($view) { | |
| $view->with('footernewscategorylist', Category::has('newslist')->withCount('newslist')->orderBy('name','desc')->where('status',1)->get()); | |
| }); | |
| view()->composer('frontend.pages.sidebar', function($view) { | |
| $newscategory_two = News::latest()->whereHas('category')->where('category_id',5)->where('status',1)->take(3)->get(); | |
| $newstabspopular = News::orderBy('view_count','DESC')->whereHas('category')->where('status',1)->take(5)->get(); | |
| $newstabsrecent = News::latest()->whereHas('category')->where('status',1)->take(5)->get(); | |
| $newsinRandomOrder = News::inRandomOrder()->whereHas('category')->where('status',1)->first(); | |
| $newscategory_list = Category::has('newslist')->withCount('newslist')->orderBy('name','desc')->where('status',1)->get(); | |
| $view->with( compact( | |
| 'newscategory_two', | |
| 'newstabspopular', | |
| 'newstabsrecent', | |
| 'newsinRandomOrder', | |
| 'newscategory_list' | |
| )); | |
| }); | |
| } | |
| } | |
| /** | |
| * Register any application services. | |
| * | |
| * @return void | |
| */ | |
| public function register() | |
| { | |
| // | |
| } | |
| } |
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
| @extends('backend.layout.master') | |
| @section('title', 'Setting Breaking News') | |
| @section('content') | |
| <section class="content-header"> | |
| <h1> | |
| Breaking News Setting | |
| </h1> | |
| <ol class="breadcrumb"> | |
| <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li> | |
| <li><a href="#">Forms</a></li> | |
| <li class="active">General Elements</li> | |
| </ol> | |
| </section> | |
| <section class="content"> | |
| <div class="row"> | |
| <div class="col-md-12"> | |
| <div class="box box-primary"> | |
| <div class="box-header with-border"> | |
| <h3 class="box-title">Select Category of Breaking News</h3> | |
| </div> | |
| <form action="{{ route('admin.settings.breakingnews.store') }}" method="POST" role="form"> | |
| @csrf | |
| <div class="box-body"> | |
| <div class="form-group"> | |
| <label>Category</label> | |
| <select name="breaking_news_category_id" class="form-control" style="width: 100%;"> | |
| <option selected disabled> --Select Category-- </option> | |
| @foreach ($categories as $category) | |
| <option value="{{ $category->id }}" @if($setting->breaking_news_category_id==$category->id){{'selected'}}@endif>{{ $category->name }}</option> | |
| @endforeach | |
| </select> | |
| </div> | |
| </div> | |
| <div class="box-footer"> | |
| <button type="submit" class="btn btn-primary btn-flat">UPDATE</button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| @endsection |
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
| @extends('frontend.layout.master') | |
| @section('title', 'Category Page') | |
| @section('content') | |
| <section class="section"> | |
| <div class="page-header container"> | |
| <h1>Category: {{ $category->name }}</h1> | |
| <ul> | |
| <li><a href="{{ route('home') }}"><i class="fas fa-home"></i> Home</a></li> | |
| <li> / </li> | |
| <li><i class="far fa-folder"></i> {{ $category->name }}</li> | |
| </ul> | |
| </div> | |
| </section> | |
| <section class="section"> | |
| <div class="section-grid container"> | |
| @foreach($featurednewslist as $key => $featurednews) | |
| <div class="section-item"> | |
| <a href="{{ route('page.news',$featurednews->slug) }}"> | |
| <img src="{{ asset('images/'.$featurednews->image) }}" alt="{{ $featurednews->title }}" class="width-100"> | |
| </a> | |
| <h3> | |
| <a href="{{ route('page.news',$featurednews->slug) }}">{{ $featurednews->title }}</a> | |
| </h3> | |
| @if($key == 0) | |
| <p>{{ $featurednews->details }}</p> | |
| @endif | |
| <ul> | |
| <li><i class="far fa-comment-alt"></i> <a href="#">{{ $featurednews->id }}</a></li> | |
| <li><i class="far fa-clock"></i> {{ $featurednews->created_at->diffForHumans() }}</li> | |
| </ul> | |
| </div> | |
| @endforeach | |
| </div> | |
| </section> | |
| <section class="section"> | |
| <div class="section-news container"> | |
| <div class="news"> | |
| @if ($advertisements && $advertisements->body_middle) | |
| <img src="{{ asset('images/advertisements/'.$advertisements->body_middle) }}" alt="Ads" class="width-100"> | |
| @endif | |
| <div class="news-category-container"> | |
| <div class="news-technology"> | |
| @foreach($newscategorylist as $newscategory) | |
| <div class="section-item"> | |
| <a href="{{ route('page.news',$newscategory->slug) }}"> | |
| <img src="{{ asset('images/'.$newscategory->image) }}" alt="{{ $newscategory->title }}" class="width-100"> | |
| </a> | |
| <h3><a href="{{ route('page.news',$newscategory->slug) }}">{{ $newscategory->title }}</a></h3> | |
| <p>{{ $newscategory->details }}</p> | |
| <ul> | |
| <li><i class="far fa-comment-alt"></i> <a href="#">{{ $newscategory->id }}</a></li> | |
| <li><i class="far fa-clock"></i> {{ $newscategory->created_at->diffForHumans() }}</li> | |
| </ul> | |
| </div> | |
| @endforeach | |
| </div> | |
| </div> | |
| @if ($advertisements && $advertisements->body_bottom) | |
| <img src="{{ asset('images/advertisements/'.$advertisements->body_bottom) }}" alt="Ads" class="width-100"> | |
| @endif | |
| </div> | |
| <aside class="sidebar"> | |
| @if ($advertisements && $advertisements->sidebar_one) | |
| <img src="{{ asset('images/advertisements/'.$advertisements->sidebar_one) }}" alt="Ads" class="width-100"> | |
| @endif | |
| @include('frontend.pages.sidebar') | |
| </aside> | |
| </div> | |
| </section> | |
| @endsection | |
| @push('scripts') | |
| @endpush |
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; | |
| use Illuminate\Database\Eloquent\Model; | |
| class News extends Model | |
| { | |
| protected $fillable = ['title', 'slug', 'details', 'image', 'category_id', 'status', 'featured', 'view_count']; | |
| public function category() | |
| { | |
| return $this->belongsTo('App\Category'); | |
| } | |
| } |
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
| @extends('frontend.layout.master') | |
| @section('title', 'Home') | |
| @section('content') | |
| <section class="section"> | |
| <div class="section-grid container"> | |
| @foreach($topnewslist as $key => $topnews) | |
| <div class="section-item"> | |
| <a href="{{ route('page.news',$topnews->slug) }}"> | |
| <img src="{{ asset('images/'.$topnews->image) }}" alt="{{ $topnews->title }}" class="width-100"> | |
| </a> | |
| <h3> | |
| <a href="{{ route('page.news',$topnews->slug) }}">{{ $topnews->title }}</a> | |
| </h3> | |
| @if($key == 0) | |
| <p>{{ $topnews->details }}</p> | |
| @endif | |
| <ul> | |
| <li><i class="far fa-folder"></i> <a href="{{ route('page.category',$topnews->category->slug) }}">{{ $topnews->category->name }}</a></li> | |
| <li><i class="far fa-clock"></i> {{ $topnews->created_at->diffForHumans() }}</li> | |
| </ul> | |
| </div> | |
| @endforeach | |
| </div> | |
| </section> | |
| <section class="section"> | |
| <div class="section-news container"> | |
| <div class="news"> | |
| <div class="news-category-container"> | |
| <h2>Recent Category</h2> | |
| <div class="news-category"> | |
| @foreach($newscategory_one as $key => $topnews) | |
| <div class="section-item"> | |
| <a href="{{ route('page.news',$topnews->slug) }}" class="bg-image" style="background-image:url({{ asset('images/'.$topnews->image) }})"></a> | |
| <div> | |
| <h3><a href="{{ route('page.news',$topnews->slug) }}">{{ $topnews->title }}</a></h3> | |
| @if($key == 0) | |
| <p>{{ $topnews->details }}</p> | |
| @endif | |
| <ul> | |
| <li><i class="far fa-folder"></i> <a href="{{ route('page.category',$topnews->category->slug) }}">{{ @$topnews->category->name }}</a></li> | |
| <li><i class="far fa-clock"></i> {{ $topnews->created_at->diffForHumans() }}</li> | |
| </ul> | |
| </div> | |
| </div> | |
| @endforeach | |
| </div> | |
| </div> | |
| <div class="news-category-container"> | |
| <h2>Recent Lifestyle</h2> | |
| <div class="news-lifestyle"> | |
| @foreach($newscategory_two as $topnews) | |
| <div class="section-item"> | |
| <a href="{{ route('page.news',$topnews->slug) }}" class="bg-image" style="background-image:url({{ asset('images/'.$topnews->image) }})"></a> | |
| <div> | |
| <h3><a href="{{ route('page.news',$topnews->slug) }}">{{ $topnews->title }}</a></h3> | |
| <p>{{ $topnews->details }}</p> | |
| <ul> | |
| <li><i class="far fa-folder"></i> <a href="{{ route('page.category',$topnews->category->slug) }}">{{ $topnews->category->name }}</a></li> | |
| <li><i class="far fa-clock"></i> {{ $topnews->created_at->diffForHumans() }}</li> | |
| </ul> | |
| </div> | |
| </div> | |
| @endforeach | |
| </div> | |
| </div> | |
| <div class="news-category-container"> | |
| <h2>Tech News</h2> | |
| <div class="news-technology"> | |
| @foreach($newscategory_three as $topnews) | |
| <div class="section-item"> | |
| <a href="{{ route('page.news',$topnews->slug) }}"> | |
| <img src="{{ asset('images/'.$topnews->image) }}" alt="{{ $topnews->title }}" class="width-100"> | |
| </a> | |
| <h3><a href="{{ route('page.news',$topnews->slug) }}">{{ $topnews->title }}</a></h3> | |
| <p>{{ $topnews->details }}</p> | |
| <ul> | |
| <li><i class="far fa-folder"></i> <a href="{{ route('page.category',$topnews->category->slug) }}">{{ $topnews->category->name }}</a></li> | |
| <li><i class="far fa-clock"></i> {{ $topnews->created_at->diffForHumans() }}</li> | |
| </ul> | |
| </div> | |
| @endforeach | |
| </div> | |
| </div> | |
| </div> | |
| <aside class="sidebar"> | |
| @include('frontend.pages.sidebar') | |
| </aside> | |
| </div> | |
| </section> | |
| @endsection | |
| @push('scripts') | |
| <script> | |
| $(function(){ | |
| // | |
| }); | |
| </script> | |
| @endpush |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <title>News - @yield('title')</title> | |
| <link rel="stylesheet" href="{{ asset('frontend/css/breaking-news-ticker.css') }}"> | |
| <link rel="stylesheet" href="{{ asset('frontend/css/style.css') }}"> | |
| </head> | |
| <body> | |
| <header> | |
| @include('frontend.layout.partials.header') | |
| @include('frontend.layout.partials.mainmenu') | |
| </header> | |
| @yield('content') | |
| <footer> | |
| @include('frontend.layout.partials.footer') | |
| </footer> | |
| <!-- jQuery 3 --> | |
| <script src="{{ asset('backend/components/jquery/dist/jquery.min.js') }}"></script> | |
| <script src="{{ asset('frontend/js/breaking-news-ticker.min.js') }}"></script> | |
| @stack('scripts') | |
| <script> | |
| $(function(){ | |
| $('#breakingnewsticker').breakingNews({radius: 0}); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
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; | |
| use Illuminate\Database\Eloquent\Model; | |
| class Setting extends Model | |
| { | |
| protected $fillable = [ | |
| 'site_name', 'site_logo', 'site_favicon', 'email', 'phone', | |
| 'facebook', 'twitter', 'linkedin', 'vimeo', 'youtube', | |
| 'about_us', 'address', | |
| 'breaking_news_category_id' | |
| ]; | |
| } |
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\Setting; | |
| use App\Category; | |
| use Illuminate\Http\Request; | |
| class SettingController extends Controller | |
| { | |
| public function index() | |
| { | |
| $setting = Setting::first(); | |
| return view('backend.settings.index',compact('setting')); | |
| } | |
| public function store(Request $request) | |
| { | |
| $request->validate([ | |
| 'site_name' => 'required|max:250', | |
| 'site_logo' => 'nullable|image|mimes:png', | |
| 'site_favicon' => 'nullable', | |
| 'email' => 'required|max:250', | |
| 'facebook' => 'nullable|url', | |
| 'twitter' => 'nullable|url', | |
| 'linkedin' => 'nullable|url', | |
| 'vimeo' => 'nullable|url', | |
| 'youtube' => 'nullable|url' | |
| ]); | |
| $setting = new Setting(); | |
| if ($request->hasFile('site_logo')) { | |
| $site_logo = 'logo'.'.'.$request->site_logo->getClientOriginalExtension(); | |
| $request->site_logo->move(public_path('images'), $site_logo); | |
| }elseif($request->site_logo){ | |
| $site_logo = $request->site_logo; | |
| }else{ | |
| $site_logo = 'logo.png'; | |
| } | |
| if ($request->hasFile('site_favicon')) { | |
| $site_favicon = 'favicon'.'.'.$request->site_favicon->getClientOriginalExtension(); | |
| $request->site_favicon->move(public_path('images'), $site_favicon); | |
| }elseif($request->site_favicon){ | |
| $site_logo = $request->site_favicon; | |
| }else{ | |
| $site_favicon = 'favicon.ico'; | |
| } | |
| $setting->updateOrCreate(['id' => 1], | |
| [ | |
| 'site_name' => $request->site_name, | |
| 'site_logo' => $site_logo, | |
| 'site_favicon' => $site_favicon, | |
| 'email' => $request->email, | |
| 'phone' => $request->phone, | |
| 'facebook' => $request->facebook, | |
| 'twitter' => $request->twitter, | |
| 'linkedin' => $request->linkedin, | |
| 'vimeo' => $request->vimeo, | |
| 'youtube' => $request->youtube, | |
| 'about_us' => $request->about_us, | |
| 'address' => $request->address | |
| ] | |
| ); | |
| $notification = array( | |
| 'message' => 'Settings updated successfully !' | |
| ); | |
| return back()->with('success', 'Setting updated successfully.')->with($notification); | |
| } | |
| public function breakingNews() | |
| { | |
| $categories = Category::all(); | |
| $setting = Setting::first(); | |
| return view('backend.settings.breaking-news',compact('categories','setting')); | |
| } | |
| public function storeBreakingNews(Request $request) | |
| { | |
| $request->validate([ | |
| 'breaking_news_category_id' => 'required', | |
| ]); | |
| $setting = new Setting(); | |
| $setting->updateOrCreate(['id' => 1], | |
| [ | |
| 'breaking_news_category_id' => $request->breaking_news_category_id | |
| ] | |
| ); | |
| return back()->with('message', 'Breaking news category updated successfully !'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment