-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from NickMous/feature/implement-database-structure
Feature/implement database structure
- Loading branch information
Showing
36 changed files
with
1,107 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class GiveRole extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:give-role'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Give a role to a user'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$loop = true; | ||
while ($loop) { | ||
$email = $this->ask('Enter the email of the user'); | ||
$role = $this->ask('Enter the role to give to the user'); | ||
$user = \App\Models\User::where('email', $email)->first(); | ||
if ($user) { | ||
$user->assignRole($role); | ||
$this->info('Role given successfully!'); | ||
} else { | ||
$this->error('User not found!'); | ||
} | ||
$loop = $this->confirm('Do you want to give another role to a user?'); | ||
} | ||
$this->info('Bye!'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Spatie\Permission\Models\Permission; | ||
use Spatie\Permission\Models\Role; | ||
use Spatie\Permission\PermissionRegistrar; | ||
|
||
class SeedRoles extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:seed-roles'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Seed the roles and permissions'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
app()[PermissionRegistrar::class]->forgetCachedPermissions(); | ||
Role::create(['name' => 'admin']); | ||
$user = Role::create(['name' => 'user']); | ||
|
||
$travelRoutes = Permission::create(['name' => 'travel routes']); | ||
$travelRoutes->assignRole($user); | ||
|
||
$this->info('Roles and permissions seeded successfully!'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Answer extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'question_id', | ||
'answer', | ||
'is_correct' | ||
]; | ||
|
||
public function question() | ||
{ | ||
return $this->belongsTo(Question::class); | ||
} | ||
|
||
public function media() | ||
{ | ||
return $this->morphMany(Media::class, 'mediable'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Checkpoint extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'description', | ||
'route_id', | ||
'order', | ||
'latitude', | ||
'longitude', | ||
'address' | ||
]; | ||
|
||
public function route() | ||
{ | ||
return $this->belongsTo(Route::class); | ||
} | ||
|
||
public function question() | ||
{ | ||
return $this->hasMany(Question::class); | ||
} | ||
|
||
public function media() | ||
{ | ||
return $this->morphMany(Media::class, 'mediable'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Media extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'route_id', | ||
'location_id', | ||
'question_id', | ||
'answer_id', | ||
'url', | ||
'type', | ||
'alt' | ||
]; | ||
|
||
public function mediable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Progress extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'user_id', | ||
'route_id', | ||
'progress', | ||
'location_id', | ||
'question_id', | ||
'score', | ||
'started_at', | ||
'completed_at' | ||
]; | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
public function route() | ||
{ | ||
return $this->belongsTo(Route::class); | ||
} | ||
|
||
public function checkpoint() | ||
{ | ||
return $this->has(Checkpoint::class); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Question extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'question', | ||
'location_id', | ||
'type', | ||
'order' | ||
]; | ||
|
||
public function checkpoint() | ||
{ | ||
return $this->belongsTo(Checkpoint::class); | ||
} | ||
|
||
public function answers() | ||
{ | ||
return $this->hasMany(Answer::class); | ||
} | ||
|
||
public function media() | ||
{ | ||
return $this->morphMany(Media::class, 'mediable'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Route extends Model | ||
{ | ||
use HasFactory; | ||
|
||
public function checkpoints() | ||
{ | ||
return $this->hasMany(Checkpoint::class); | ||
} | ||
|
||
protected $fillable = [ | ||
'name', | ||
'description', | ||
'difficulty', | ||
'length', | ||
'duration', | ||
'user_id', | ||
'available_at', | ||
'unavailable_at', | ||
'is_public' | ||
]; | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
public function progress() | ||
{ | ||
return $this->hasMany(Progress::class); | ||
} | ||
|
||
public function media() | ||
{ | ||
return $this->morphMany(Media::class, 'mediable'); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.