Skip to content

Commit

Permalink
Pushing all latest changes to master branch - further profile customi…
Browse files Browse the repository at this point in the history
…sation incl. remove and upload profile picture
  • Loading branch information
mandyfarrugia committed Jan 24, 2025
2 parents 1a5990c + 40fa8fa commit de5833d
Show file tree
Hide file tree
Showing 32 changed files with 384 additions and 75 deletions.
58 changes: 56 additions & 2 deletions twodeesapp/app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,64 @@

class ProfileController extends Controller {
public function index($id) {
$user = User::where('id', $id)->first();
$user = User::find($id);

if($user != null) {
return view('profile.index', compact('user'));
$region = $user->location->region;

if($region != null) {
$country = $region->country;
}

return view('profile.index', compact('user', 'region', 'country'));
} else {
return redirect()->route('/')->with('error', 'The profile you are searching for does not exist!');
}
}

public function upload_profile_picture($id) {
$user = User::find($id);

if($user != null) {
return view('profile.upload_profile_picture', compact('user'));
} else {
return redirect()->route('/')->with('error', 'The profile you are searching for does not exist!');
}
}

public function process_profile_picture_upload($id, Request $request) {
$user = User::find($id);

if($user != null) {
$request->validate([
'profile_picture' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
]);

$profile_picture = $request->file('profile_picture');
$profile_picture_name = time() . '.' . $request->profile_picture->extension();
$profile_picture->move(public_path('profile_pictures'), $profile_picture_name);

$user->profile_picture = 'profile_pictures/' . $profile_picture_name;
$user->save();

return redirect()->route('profile.index', $user->id)->with('success', "Your profile picture has been updated! Looking great! \u{1F60A}");
} else {
return redirect()->route('/')->with('error', 'The profile you are searching for does not exist!');
}
}

public function remove_profile_picture($id, Request $request) {
$user = User::find($id);

if($user != null) {
if(file_exists(public_path($user->profile_picture))) {
unlink(public_path($user->profile_picture));
}

$user->profile_picture = null;
$user->save();

return redirect()->route('profile.index', $user->id)->with('success', "Your profile picture has been removed! \u{1F622}");
} else {
return redirect()->route('/')->with('error', 'The profile you are searching for does not exist!');
}
Expand Down
2 changes: 1 addition & 1 deletion twodeesapp/app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Category extends Model
{
use HasFactory;

protected $fillable = ["name", "imagePath"]; //Technique to enable mass assignment yet again, although in the case overkill since model is only made up of one attribute apart from the id and timestamps.
protected $fillable = ['name', 'image_path']; //Technique to enable mass assignment yet again, although in the case overkill since model is only made up of one attribute apart from the id and timestamps.

//Establishing a relationship between Item and Category model (one-to-many relationship whereby one category can be assigned to many items).
public function items() {
Expand Down
2 changes: 1 addition & 1 deletion twodeesapp/app/Models/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Country extends Model
{
use HasFactory;

protected $fillable = ["name"];
protected $fillable = ['name'];

public function regions() {
return $this->hasMany(Region::class);
Expand Down
2 changes: 1 addition & 1 deletion twodeesapp/app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Item extends Model
{
use HasFactory;

protected $fillable = ["name", "price", "release_date", "description", "image_path", "category_id"]; //Technique to enable mass assignment.
protected $fillable = ['name', 'price', 'release_date', 'description', 'image_path', 'category_id']; //Technique to enable mass assignment.

//Establishing a relationship between Item and Category model (one-to-many relationship whereby one category can be assigned to many items).
public function category() {
Expand Down
2 changes: 1 addition & 1 deletion twodeesapp/app/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Location extends Model
{
use HasFactory;

protected $fillable = ["name", "region_id"];
protected $fillable = ['name', 'region_id'];

public function region() {
return $this->belongsTo(Region::class);
Expand Down
2 changes: 1 addition & 1 deletion twodeesapp/app/Models/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Region extends Model
{
use HasFactory;

protected $fillable = ["name", "country_id"];
protected $fillable = ['name', 'country_id'];

public function country() {
return $this->belongsTo(Country::class);
Expand Down
14 changes: 14 additions & 0 deletions twodeesapp/database/seeders/CountriesTableSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Database\Seeders;

use App\Models\Country;
use Illuminate\Database\Seeder;

class CountriesTableSeeder extends Seeder
{
public function run(): void
{
Country::create(['name' => 'Malta']);
}
}
17 changes: 6 additions & 11 deletions twodeesapp/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
// \App\Models\User::factory(10)->create();

// \App\Models\User::factory()->create([
// 'name' => 'Test User',
// 'email' => 'test@example.com',
// ]);
$this->call([
CountriesTableSeeder::class,
RegionsTableSeeder::class,
LocationsTableSeeder::class
]);
}
}
}
100 changes: 100 additions & 0 deletions twodeesapp/database/seeders/LocationsTableSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace Database\Seeders;

use App\Models\Location;
use App\Models\Region;
use Illuminate\Database\Seeder;

class LocationsTableSeeder extends Seeder
{
public function run(): void
{
$easternRegion = Region::where('name', 'Eastern Region')->first()->id;
$gozoRegion = Region::where('name', 'Gozo Region')->first()->id;
$northernRegion = Region::where('name', 'Northern Region')->first()->id;
$portRegion = Region::where('name', 'Port Region')->first()->id;
$southernRegion = Region::where('name', 'Southern Region')->first()->id;
$westernRegion = Region::where('name', 'Western Region')->first()->id;

$locationObjects = [
['name' => 'Fontana', 'region_id' => $gozoRegion],
['name' => 'Ghajnsielem', 'region_id' => $gozoRegion],
['name' => 'Gharb', 'region_id' => $gozoRegion],
['name' => 'Ghasri', 'region_id' => $gozoRegion],
['name' => 'Kercem', 'region_id' => $gozoRegion],
['name' => 'Marsalforn', 'region_id' => $gozoRegion],
['name' => 'Mgarr (Gozo)', 'region_id' => $gozoRegion],
['name' => 'Munxar', 'region_id' => $gozoRegion],
['name' => 'Nadur', 'region_id' => $gozoRegion],
['name' => 'Qala', 'region_id' => $gozoRegion],
['name' => 'San Lawrenz', 'region_id' => $gozoRegion],
['name' => 'Sannat', 'region_id' => $gozoRegion],
['name' => 'Victoria', 'region_id' => $gozoRegion],
['name' => 'Xaghra', 'region_id' => $gozoRegion],
['name' => 'Xewkija', 'region_id' => $gozoRegion],
['name' => 'Xlendi', 'region_id' => $gozoRegion],
['name' => 'Zebbug (Gozo)', 'region_id' => $gozoRegion],
['name' => 'Birkirkara', 'region_id' => $easternRegion],
['name' => 'Gharghur', 'region_id' => $easternRegion],
['name' => 'Gzira', 'region_id' => $easternRegion],
['name' => 'Ibragg', 'region_id' => $easternRegion],
['name' => 'Iklin', 'region_id' => $easternRegion],
['name' => 'Lija', 'region_id' => $easternRegion],
['name' => 'Msida', 'region_id' => $easternRegion],
['name' => 'Pembroke', 'region_id' => $easternRegion],
['name' => 'Pietà', 'region_id' => $easternRegion],
['name' => 'San Giljan', 'region_id' => $easternRegion],
['name' => 'Sliema', 'region_id' => $easternRegion],
['name' => 'Swieqi', 'region_id' => $easternRegion],
['name' => 'Ta\' Xbiex', 'region_id' => $easternRegion],
['name' => 'Dingli', 'region_id' => $westernRegion],
['name' => 'Kirkop', 'region_id' => $westernRegion],
['name' => 'Mdina', 'region_id' => $westernRegion],
['name' => 'Mqabba', 'region_id' => $westernRegion],
['name' => 'Qrendi', 'region_id' => $westernRegion],
['name' => 'Rabat', 'region_id' => $westernRegion],
['name' => 'Safi', 'region_id' => $westernRegion],
['name' => 'Siggiewi', 'region_id' => $westernRegion],
['name' => 'Zebbug (Malta)', 'region_id' => $westernRegion],
['name' => 'Zurrieq', 'region_id' => $westernRegion],
['name' => 'Birzebbuga', 'region_id' => $southernRegion],
['name' => 'Ghaxaq', 'region_id' => $southernRegion],
['name' => 'Gudja', 'region_id' => $southernRegion],
['name' => 'Hamrun', 'region_id' => $southernRegion],
['name' => 'Luqa', 'region_id' => $southernRegion],
['name' => 'Marsa', 'region_id' => $southernRegion],
['name' => 'Marsaskala', 'region_id' => $southernRegion],
['name' => 'Marsaxlokk', 'region_id' => $southernRegion],
['name' => 'Qormi', 'region_id' => $southernRegion],
['name' => 'Santa Lucija', 'region_id' => $southernRegion],
['name' => 'Santa Venera', 'region_id' => $southernRegion],
['name' => 'Zejtun', 'region_id' => $southernRegion],
['name' => 'Birgu', 'region_id' => $portRegion],
['name' => 'Bormla', 'region_id' => $portRegion],
['name' => 'Fgura', 'region_id' => $portRegion],
['name' => 'Floriana', 'region_id' => $portRegion],
['name' => 'Isla', 'region_id' => $portRegion],
['name' => 'Kalkara', 'region_id' => $portRegion],
['name' => 'Paola', 'region_id' => $portRegion],
['name' => 'Tarxien', 'region_id' => $portRegion],
['name' => 'Valletta', 'region_id' => $portRegion],
['name' => 'Xghajra', 'region_id' => $portRegion],
['name' => 'Zabbar', 'region_id' => $portRegion],
['name' => 'Attard', 'region_id' => $northernRegion],
['name' => 'Bahar ic-Caghaq', 'region_id' => $northernRegion],
['name' => 'Bidnija', 'region_id' => $northernRegion],
['name' => 'Balzan', 'region_id' => $northernRegion],
['name' => 'Mellieha', 'region_id' => $northernRegion],
['name' => 'L-Imgarr', 'region_id' => $northernRegion],
['name' => 'Mosta', 'region_id' => $northernRegion],
['name' => 'Mtarfa', 'region_id' => $northernRegion],
['name' => 'Naxxar', 'region_id' => $northernRegion],
['name' => 'San Pawl il-Bahar', 'region_id' => $northernRegion],
];

foreach($locationObjects as $locationObject) {
Location::create($locationObject);
}
}
}
28 changes: 28 additions & 0 deletions twodeesapp/database/seeders/RegionsTableSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Database\Seeders;

use App\Models\Country;
use App\Models\Region;
use Illuminate\Database\Seeder;

class RegionsTableSeeder extends Seeder
{
public function run(): void
{
$malta = Country::where('name', 'Malta')->first()->id;

$regionObjects = [
['name' => 'Eastern Region', 'country_id' => $malta],
['name' => 'Gozo Region', 'country_id' => $malta],
['name' => 'Northern Region', 'country_id' => $malta],
['name' => 'Port Region', 'country_id' => $malta],
['name' => 'Southern Region', 'country_id' => $malta],
['name' => 'Western Region', 'country_id' => $malta]
];

foreach($regionObjects as $regionObject) {
Region::create($regionObject);
}
}
}
Binary file removed twodeesapp/public/images/1737318350.jpg
Binary file not shown.
Binary file removed twodeesapp/public/images/1737319402.jpg
Binary file not shown.
Binary file removed twodeesapp/public/images/1737320138.jpg
Binary file not shown.
Binary file removed twodeesapp/public/images/1737355066.jpg
Binary file not shown.
Binary file removed twodeesapp/public/images/1737466715.jpg
Binary file not shown.
Binary file removed twodeesapp/public/images/1737466789.png
Binary file not shown.
Binary file removed twodeesapp/public/images/1737622530.jpg
Binary file not shown.
Binary file removed twodeesapp/public/images/1737623670.png
Binary file not shown.
Loading

0 comments on commit de5833d

Please sign in to comment.