Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I upgraded the project to dark mode added some amazing features #19

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/Console/Commands/GenerateSitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Console\Commands;

use App\Models\Listing;
use Illuminate\Console\Command;
use PharIo\Manifest\Url as ManifestUrl;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\Tags\Url;

class GenerateSitemap extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sitemap:generate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Automatically Generate an XML Sitemap';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$postsitmap = Sitemap::create();
Listing::get()->each(function (Listing $post) use ($postsitmap) {
$postsitmap->add(
Url::create("/listing/{$post->id}")
->setPriority(0.9)
// ->setChangeFrequency(ManifestUrl::monthly)
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
);
});
$postsitmap->writeToFile(public_path('sitemap.xml'));
}
}
3 changes: 2 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('sitemap:generate')->daily();
}

/**
Expand All @@ -25,7 +26,7 @@ protected function schedule(Schedule $schedule)
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
$this->load(__DIR__ . '/Commands');

require base_path('routes/console.php');
}
Expand Down
316 changes: 316 additions & 0 deletions app/Http/Controllers/CountiesController.php

Large diffs are not rendered by default.

68 changes: 53 additions & 15 deletions app/Http/Controllers/ListingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,60 @@
class ListingController extends Controller
{
// Show all listings
public function index() {
public function index()
{
// SitemapGenerator::create('https://example.com')->writeToFile($path);
return view('listings.index', [
'listings' => Listing::latest()->filter(request(['tag', 'search']))->paginate(6)
'listings' => Listing::latest()->filter(request(['tag', 'search']))->paginate(12)
]);
}

public function search(Request $request)
{
// dd(1);
$name = $request->name;
$occupation = $request->occupation;
if ($occupation == 'all') {
$listings = Listing::where('title', 'like', '%' . $name . '%')
->orWhere('description', 'like', '%' . $name . '%')
->orWhere('tags', 'like', '%' . $name . '%')->paginate(12);
} else {
if ($name == '') {
$listings = Listing::where('occupation', 'like', '%' . $occupation . '%')->paginate(12);
} else {
# code...
$listings = Listing::where(function ($query) use ($name) {
return $query->where('title', 'like', '%' . $name . '%')
->orWhere('description', 'like', '%' . $name . '%')
->orWhere('tags', 'like', '%' . $name . '%');
})->where(function ($query) use ($occupation) {
return $query->where('occupation', 'like', '%' . $occupation . '%');
})->paginate(12);
}
}
// dd($listings);
$d['listings'] = $listings;
$d['name'] = $occupation;
$d['occupation'] = $occupation;
return view('listings.index', $d);
}
//Show single listing
public function show(Listing $listing) {
public function show(Listing $listing)
{
return view('listings.show', [
'listing' => $listing
]);
}

// Show Create Form
public function create() {
public function create()
{
return view('listings.create');
}

// Store Listing Data
public function store(Request $request) {
public function store(Request $request)
{
$formFields = $request->validate([
'title' => 'required',
'company' => ['required', Rule::unique('listings', 'company')],
Expand All @@ -39,7 +73,7 @@ public function store(Request $request) {
'description' => 'required'
]);

if($request->hasFile('logo')) {
if ($request->hasFile('logo')) {
$formFields['logo'] = $request->file('logo')->store('logos', 'public');
}

Expand All @@ -51,17 +85,19 @@ public function store(Request $request) {
}

// Show Edit Form
public function edit(Listing $listing) {
public function edit(Listing $listing)
{
return view('listings.edit', ['listing' => $listing]);
}

// Update Listing Data
public function update(Request $request, Listing $listing) {
public function update(Request $request, Listing $listing)
{
// Make sure logged in user is owner
if($listing->user_id != auth()->id()) {
if ($listing->user_id != auth()->id()) {
abort(403, 'Unauthorized Action');
}

$formFields = $request->validate([
'title' => 'required',
'company' => ['required'],
Expand All @@ -72,7 +108,7 @@ public function update(Request $request, Listing $listing) {
'description' => 'required'
]);

if($request->hasFile('logo')) {
if ($request->hasFile('logo')) {
$formFields['logo'] = $request->file('logo')->store('logos', 'public');
}

Expand All @@ -82,18 +118,20 @@ public function update(Request $request, Listing $listing) {
}

// Delete Listing
public function destroy(Listing $listing) {
public function destroy(Listing $listing)
{
// Make sure logged in user is owner
if($listing->user_id != auth()->id()) {
if ($listing->user_id != auth()->id()) {
abort(403, 'Unauthorized Action');
}

$listing->delete();
return redirect('/')->with('message', 'Listing deleted successfully');
}

// Manage Listings
public function manage() {
public function manage()
{
return view('listings.manage', ['listings' => auth()->user()->listings()->get()]);
}
}
53 changes: 53 additions & 0 deletions app/Http/Controllers/g.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
#############################################################
# 47 counties of Kenya #
#############################################################
$config['counties'] = [
'BARINGO' => 'Baringo County',
'BOMET' => 'Bomet County',
'BUNGOMA' => 'Bungoma County',
'BUSIA' => 'Busia County',
'ELGEYO-MARAKWET' => 'Elgeyo-Marakwet County',
'EMBU' => 'Embu County',
'GARISSA' => 'Garissa County',
'HOMA-BAY' => 'Homa-bay County',
'ISIOLO' => 'Isiolo County',
'KAJIADO' => 'Kajiado County',
'KAKAMEGA' => 'Kakamega County',
'KERICHO' => 'Kericho County',
'KIAMBU' => 'Kiambu County',
'KILIFI' => 'Kilifi County',
'KIRINYAGA' => 'Kirinyaga County',
'KISII' => 'Kisii County',
'KISUMU' => 'Kisumu County',
'KITUI' => 'Kitui County',
'KWALE' => 'Kwale County',
'LAIKIPIA' => 'Laikipia County',
'LAMU' => 'Lamu County',
'MACHAKOS' => 'Machakos County',
'MAKUENI' => 'Makueni County',
'MANDERA' => 'Mandera County',
'MARSABIT' => 'Marsabit County',
'MERU' => 'Meru County',
'MIGORI' => 'Migori County',
'MOMBASA' => 'Mombasa County',
'MURANGA' => 'Muranga County',
'NAIROBI' => 'Nairobi County',
'NAKURU' => 'Nakuru County',
'NANDI' => 'Nandi County',
'NAROK' => 'Narok County',
'NYAMIRA' => 'Nyamira County',
'NYANDARUA' => 'Nyandarua County',
'NYERI' => 'Nyeri County',
'SAMBURU' => 'Samburu County',
'SIAYA' => 'Siaya County',
'TAITA-TAVETA' => 'Taita-Taveta County',
'TANA RIVER' => 'Tana River County',
'THARAKA-NITHI' => 'Tharaka-Nithi County',
'TRANS-NZOIA' => 'Trans-Nzoia County',
'TURKANA' => 'Turkana County',
'UASIN GISHU' => 'Uasin Gishu County',
'VIHIGA' => 'Vihiga County',
'WAJIR' => 'Wajir County',
'WEST POKOT' => 'West Pokot County',
];
13 changes: 13 additions & 0 deletions app/Models/Countie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Countie extends Model
{
use HasFactory;

protected $fillable = ['name'];
}
12 changes: 7 additions & 5 deletions app/Models/Listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ class Listing extends Model
{
use HasFactory;

// protected $fillable = ['title', 'company', 'location', 'website', 'email', 'description', 'tags'];
protected $fillable = ['title', 'company', 'location', 'website', 'email', 'description', 'tags', 'occupation'];

public function scopeFilter($query, array $filters) {
if($filters['tag'] ?? false) {
public function scopeFilter($query, array $filters)
{
if ($filters['tag'] ?? false) {
$query->where('tags', 'like', '%' . request('tag') . '%');
}

if($filters['search'] ?? false) {
if ($filters['search'] ?? false) {
$query->where('title', 'like', '%' . request('search') . '%')
->orWhere('description', 'like', '%' . request('search') . '%')
->orWhere('tags', 'like', '%' . request('search') . '%');
}
}

// Relationship To User
public function user() {
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
}
28 changes: 28 additions & 0 deletions app/View/Components/Forms/tinymceEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\View\Components\Forms;

use Illuminate\View\Component;

class tinymceEditor extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.forms.tinymce-editor');
}
}
28 changes: 28 additions & 0 deletions app/View/Components/Head/tinymceConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\View\Components\Head;

use Illuminate\View\Component;

class tinymceConfig extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.head.tinymce-config');
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"itsgoingd/clockwork": "^5.1",
"laravel/framework": "^9.2",
"laravel/sanctum": "^2.14.1",
"laravel/tinker": "^2.7"
"laravel/tinker": "^2.7",
"spatie/laravel-sitemap": "^6.2",
"tinymce/tinymce": "^6.3"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand Down
Loading