Anuj-Panthri commited on
Commit
60c127b
·
1 Parent(s): 2b70216

added myskills add new skill functionality

Browse files
app/Http/Controllers/DashboardController.php CHANGED
@@ -3,14 +3,72 @@
3
  namespace App\Http\Controllers;
4
 
5
  use Illuminate\Http\Request;
6
- // use
 
 
 
7
 
8
  class DashboardController extends Controller
9
  {
10
  public function home(){
11
  return view('dashboard.home');
12
  }
 
13
  public function explore(){
14
  return view('dashboard.explore');
15
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
 
3
  namespace App\Http\Controllers;
4
 
5
  use Illuminate\Http\Request;
6
+ use App\Models\CustomUser;
7
+ use App\Models\Skill;
8
+ use App\Models\Task;
9
+ use Auth;
10
 
11
  class DashboardController extends Controller
12
  {
13
  public function home(){
14
  return view('dashboard.home');
15
  }
16
+
17
  public function explore(){
18
  return view('dashboard.explore');
19
  }
20
+
21
+ public function myskills(){
22
+ $skills = Skill::where(
23
+ 'belongs_to',
24
+ Auth::guard('customuser')->user()->username
25
+ )->get();
26
+
27
+ return view('dashboard.myskills',[
28
+ 'skills'=>$skills,
29
+ ]);
30
+ }
31
+
32
+ public function createSkill(Request $request){
33
+ // request includes title
34
+ // validate
35
+ $request->validate([
36
+ 'title' => ['required',
37
+ 'string',
38
+ ]
39
+ ]);
40
+
41
+ // save data for current user
42
+ $skill = new Skill();
43
+ $skill->title = $request->title;
44
+ $skill->belongs_to = Auth::guard('customuser')->user()->username; // username of current logged in user
45
+
46
+ $skill->save();
47
+
48
+ return redirect(route('dashboard.myskills'));
49
+
50
+ }
51
+
52
+ public function skill($id){
53
+ // returns the view for current user's skill which has the given id
54
+ $current_skill = Skill::where(
55
+ 'belongs_to',
56
+ Auth::guard('customuser')->user()->username)->where(
57
+ 'id',
58
+ $id
59
+ )->first();
60
+
61
+ if($current_skill==null){
62
+ return redirect(route('dashboard.myskills')); // skill not found
63
+ }
64
+
65
+ // get the list of tasks which belongs to this particular skill
66
+ $tasks = Task::where('skill_id',$current_skill->id)->get();
67
+
68
+ return view('dashboard.skill',[
69
+ 'skill' => $current_skill,
70
+ 'tasks' => $tasks,
71
+ ]);
72
+
73
+ }
74
  }
app/Models/Skill.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace App\Models;
4
+
5
+ use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+ use Illuminate\Database\Eloquent\Model;
7
+
8
+ class Skill extends Model
9
+ {
10
+ use HasFactory;
11
+ }
app/Models/Task.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace App\Models;
4
+
5
+ use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+ use Illuminate\Database\Eloquent\Model;
7
+
8
+ class Task extends Model
9
+ {
10
+ use HasFactory;
11
+ }
database/migrations/2024_01_02_075155_create_skills_table.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Illuminate\Database\Migrations\Migration;
4
+ use Illuminate\Database\Schema\Blueprint;
5
+ use Illuminate\Support\Facades\Schema;
6
+
7
+ return new class extends Migration
8
+ {
9
+ /**
10
+ * Run the migrations.
11
+ */
12
+ public function up(): void
13
+ {
14
+ Schema::create('skills', function (Blueprint $table) {
15
+ $table->id();
16
+ $table->string('title');
17
+ $table->string('belongs_to');
18
+ $table->foreign('belongs_to')->on('custom_users')->references('username')->onDelete('cascade');
19
+ $table->timestamps();
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Reverse the migrations.
25
+ */
26
+ public function down(): void
27
+ {
28
+ Schema::dropIfExists('skills');
29
+ }
30
+ };
database/migrations/2024_01_02_075201_create_tasks_table.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Illuminate\Database\Migrations\Migration;
4
+ use Illuminate\Database\Schema\Blueprint;
5
+ use Illuminate\Support\Facades\Schema;
6
+
7
+ return new class extends Migration
8
+ {
9
+ /**
10
+ * Run the migrations.
11
+ */
12
+ public function up(): void
13
+ {
14
+ Schema::create('tasks', function (Blueprint $table) {
15
+ $table->id();
16
+ $table->string('title');
17
+ $table->string('type');
18
+ $table->string('skill_id');
19
+ $table->foreign('skill_id')->on('skills')->references('id')->onDelete('cascade');
20
+
21
+ $table->timestamps();
22
+ });
23
+ }
24
+
25
+ /**
26
+ * Reverse the migrations.
27
+ */
28
+ public function down(): void
29
+ {
30
+ Schema::dropIfExists('tasks');
31
+ }
32
+ };
public/css/dashboard/myskills.css ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #main_section {
2
+ margin: 2rem;
3
+ padding: 2rem;
4
+ border-radius: 10px;
5
+ min-height: 500px;
6
+ background-color: #ffe4e4;
7
+ box-shadow: 0px 0px 17px -10px #000;
8
+ display: flex;
9
+ flex-direction: column;
10
+ align-items: center;
11
+
12
+ }
13
+
14
+
15
+ .header_container {
16
+ width: 100%;
17
+ display: flex;
18
+ flex-direction: row;
19
+ align-items: center;
20
+ justify-content: space-between;
21
+ margin-top: 0.5rem;
22
+ }
23
+
24
+ #add_new_skill_btn {
25
+ background-color: blue;
26
+ color: #fff;
27
+ padding: 0.7rem 1rem;
28
+ border-radius: 50px;
29
+ border:none;
30
+ cursor: pointer;
31
+ }
32
+
33
+ .line {
34
+ margin: 2rem 0;
35
+ width: 80%;
36
+ border-bottom: 2px solid black;
37
+ }
38
+
39
+ #skills{
40
+ width:100%;
41
+ display:flex;
42
+ flex-direction: row;
43
+ flex-wrap:wrap;
44
+ align-items: center;
45
+ }
46
+ .skill{
47
+ padding:4rem;
48
+ background-color: #fff;
49
+ border-radius: 10px;
50
+ margin:2rem;
51
+ margin-top:0;
52
+ margin-left:0;
53
+ }
54
+
55
+
56
+ #modal{
57
+ position: absolute;
58
+ top:50%;
59
+ left:50%;
60
+ transform: translate(-50%,-50%);
61
+ border:none;
62
+ outline: none;
63
+ border-radius: 10px;
64
+ padding:2rem;
65
+ background-color: #f0f0f0;
66
+ }
67
+
68
+ #modal>.close_btn{
69
+ position:absolute;
70
+ top:10px;
71
+ right:10px;
72
+ cursor: pointer;
73
+ }
74
+
75
+ #modal>.container{
76
+ display: flex;
77
+ flex-direction: column;
78
+ align-items: center;
79
+ }
80
+
81
+ #modal>.container>.title{
82
+ font-size: 2rem;
83
+ }
84
+
85
+
86
+ #modal .skill_input{
87
+ border-radius: 10px;
88
+ border: none;
89
+ outline: none;
90
+ font-size: 1rem;
91
+ padding:1rem 2rem;
92
+ margin-top: 5rem;
93
+ background-color: #fff;
94
+ box-shadow: 0px 0px 10px -8px;
95
+ }
96
+
97
+ #modal .submit_btn{
98
+ border-radius: 50px;
99
+ border: none;
100
+ outline: none;
101
+ background-color: #2b60f2;
102
+ color: #fff;
103
+ padding:0.7rem 1.5rem;
104
+ margin-top: 3rem;
105
+ cursor: pointer;
106
+ }
107
+
108
+ .field{
109
+ display: flex;
110
+ flex-direction: column;
111
+ }
112
+
113
+ .error_msg{
114
+ color: red;
115
+ font-size:0.8rem;
116
+ }
117
+
118
+
119
+
public/css/dashboard/skill.css ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #main_section {
2
+ margin: 2rem;
3
+ padding: 2rem;
4
+ border-radius: 10px;
5
+ min-height: 500px;
6
+ background-color: #ffe4e4;
7
+ box-shadow: 0px 0px 17px -10px #000;
8
+ display: flex;
9
+ flex-direction: column;
10
+ align-items: center;
11
+
12
+ }
13
+
14
+
15
+ .header_container {
16
+ width: 100%;
17
+ display: flex;
18
+ flex-direction: row;
19
+ align-items: center;
20
+ justify-content: space-between;
21
+ margin-top: 0.5rem;
22
+ }
23
+
24
+ .new_btn {
25
+ background-color: blue;
26
+ color: #fff;
27
+ padding: 0.7rem 1rem;
28
+ border-radius: 50px;
29
+ border:none;
30
+ cursor: pointer;
31
+ }
32
+
33
+
34
+ .line {
35
+ margin: 2rem 0;
36
+ width: 80%;
37
+ border-bottom: 2px solid black;
38
+ }
39
+
40
+ .task_container{
41
+ width:100%;
42
+ display:flex;
43
+ flex-direction: column;
44
+ align-items: center;
45
+ background-color: #fff;
46
+ border-radius: 10px;
47
+ margin:1rem;
48
+ padding:1rem;
49
+ }
50
+ .tasks{
51
+ width:100%;
52
+ margin-top:2rem;
53
+ display:flex;
54
+ flex-direction: row;
55
+ flex-wrap:wrap;
56
+ align-items: center;
57
+ background-color: #fff;
58
+ border-radius: 10px;
59
+ }
60
+ .task{
61
+ box-shadow:0px 0px 10px -6px #000;
62
+ padding:3rem 2rem;
63
+ background-color: #fff;
64
+ border-radius: 10px;
65
+ margin:2rem;
66
+ margin-top:0;
67
+ margin-left:0;
68
+ width: 18ch;
69
+ cursor: pointer;
70
+ }
71
+ .task>span{
72
+ text-align: center;
73
+ }
74
+
75
+ #modal{
76
+ position: absolute;
77
+ top:50%;
78
+ left:50%;
79
+ transform: translate(-50%,-50%);
80
+ border:none;
81
+ outline: none;
82
+ border-radius: 10px;
83
+ padding:2rem;
84
+ background-color: #f0f0f0;
85
+ }
86
+
87
+ #modal>.close_btn{
88
+ position:absolute;
89
+ top:10px;
90
+ right:10px;
91
+ cursor: pointer;
92
+ }
93
+
94
+ #modal>.container{
95
+ display: flex;
96
+ flex-direction: column;
97
+ align-items: center;
98
+ }
99
+
100
+ #modal>.container>.title{
101
+ font-size: 2rem;
102
+ margin-bottom: 1rem;
103
+ }
104
+
105
+ #modal .field{
106
+ display: flex;
107
+ flex-direction: column;
108
+ margin-top: 1rem;
109
+ }
110
+
111
+ #modal .task_input{
112
+ border-radius: 10px;
113
+ border: none;
114
+ outline: none;
115
+ font-size: 1rem;
116
+ padding:1rem 2rem;
117
+ background-color: #fff;
118
+ box-shadow: 0px 0px 10px -8px;
119
+ }
120
+
121
+ #modal .submit_btn{
122
+ border-radius: 50px;
123
+ border: none;
124
+ outline: none;
125
+ background-color: #2b60f2;
126
+ color: #fff;
127
+ padding:0.7rem 1.5rem;
128
+ margin-top: 2rem;
129
+ cursor: pointer;
130
+ }
131
+
132
+
133
+ .error_msg{
134
+ color: red;
135
+ font-size:0.8rem;
136
+ }
137
+
138
+
139
+
resources/views/dashboard/home.blade.php CHANGED
@@ -9,7 +9,7 @@
9
  <p>
10
  Start learning the skills which you always wanted to the right way.
11
  </p>
12
- <a href="{{ route('dashboard.explore') }}" id="get_started_btn">Get Started</a>
13
  </div>
14
  <img src="{{ asset('images/skills collage.png') }}">
15
  {{-- @include('components.topdown')
 
9
  <p>
10
  Start learning the skills which you always wanted to the right way.
11
  </p>
12
+ <a href="{{ route('dashboard.myskills') }}" id="get_started_btn">Get Started</a>
13
  </div>
14
  <img src="{{ asset('images/skills collage.png') }}">
15
  {{-- @include('components.topdown')
resources/views/dashboard/myskills.blade.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @extends('layouts.main')
2
+
3
+ @section('head')
4
+ <link rel="stylesheet" href="{{ asset('css/dashboard/myskills.css') }}">
5
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
6
+ integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
7
+ crossorigin="anonymous" referrerpolicy="no-referrer" />
8
+ @endsection
9
+
10
+ @section('main')
11
+ <section id='main_section'>
12
+ <div class='header_container'>
13
+ <h2>My Skills</h2>
14
+ <button id="add_new_skill_btn" onclick="modal.showModal()">Add New Skill</button>
15
+ </div>
16
+ <hr class='line'>
17
+ <div id="skills">
18
+ @foreach ($skills as $skill)
19
+ <a href="{{ route('dashboard.skill',$skill->id) }}" class='skill'>{{ $skill->title }}</a>
20
+ @endforeach
21
+
22
+ {{-- <div>
23
+ No skills yet
24
+ </div> --}}
25
+ </div>
26
+ </section>
27
+ <dialog id="modal">
28
+ <i onclick="modal.close()" class="fa-solid fa-xmark close_btn"></i>
29
+ <form class="container" method="POST" action="{{ route('dashboard.createskill') }}">
30
+ @csrf
31
+ <p class='title'>
32
+ Which Skill do you wanna start learning ?
33
+ </p>
34
+ <div class="field">
35
+ <input type='text' class='skill_input' name="title" placeholder="singing, dancing">
36
+ <span class='error_msg'>
37
+ @error('title')
38
+ {{ $message }}
39
+ @enderror
40
+ </span>
41
+ </div>
42
+ <input type='submit' class='submit_btn' value='Add'>
43
+ </form>
44
+ </dialog>
45
+ {{-- if there is any error show the modal --}}
46
+ <script>
47
+ @if ($errors->any())
48
+ modal.showModal();
49
+ @endif
50
+ </script>
51
+ @endsection
resources/views/dashboard/skill.blade.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @extends('layouts.main')
2
+
3
+ @section('head')
4
+ <link rel="stylesheet" href="{{ asset('css/dashboard/skill.css') }}">
5
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
6
+ integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
7
+ crossorigin="anonymous" referrerpolicy="no-referrer" />
8
+ @endsection
9
+
10
+ @section('main')
11
+ <section id='main_section'>
12
+ <div class='header_container'>
13
+ <h2>Learning {{ $skill->title }} Skill</h2>
14
+ </div>
15
+ <div class="task_container">
16
+ <div class='header_container'>
17
+ <h2>Basic/Core Skills</h2>
18
+ <button class="new_btn" onclick="modal.showModal()">New</button>
19
+ </div>
20
+ <div class="tasks">
21
+ <div class='task'>
22
+ <span>learn how fret works</span>
23
+ </div>
24
+ <div class='task'>
25
+ <span>learn how tuning keys works</span>
26
+ </div>
27
+ <div class='task'>
28
+ <span>learn guitar string names</span>
29
+ </div>
30
+
31
+ </div>
32
+ </div>
33
+ </section>
34
+ <dialog id="modal">
35
+ <i onclick="modal.close()" class="fa-solid fa-xmark close_btn"></i>
36
+ {{-- <form class="container" method="POST" action="{{ route('dashboard.createtask',$skill->id) }}"> --}}
37
+ <form class="container" method="POST">
38
+ @csrf
39
+ <p class='title'>
40
+ New Task
41
+ </p>
42
+ <div class="field">
43
+ <input type='text' class='task_input' name="title" placeholder="task name">
44
+ <span class='error_msg'>
45
+ @error('title')
46
+ {{ $message }}
47
+ @enderror
48
+ </span>
49
+ </div>
50
+ <div class="field">
51
+ <label for="task_type">Choose your task type:</label>
52
+ <select name="task_type" class='task_input' id="task_type">
53
+ <option value="basic">Basic</option>
54
+ <option value="sub">Sub</option>
55
+ <option value="app">Application</option>
56
+ </select>
57
+ <span class='error_msg'>
58
+ @error('title')
59
+ {{ $message }}
60
+ @enderror
61
+ </span>
62
+ </div>
63
+ <input type='submit' class='submit_btn' value='Add'>
64
+ </form>
65
+ </dialog>
66
+ {{-- if there is any error show the modal --}}
67
+ <script>
68
+ @if ($errors->any())
69
+ modal.showModal();
70
+ @endif
71
+ </script>
72
+ @endsection
resources/views/layouts/main.blade.php CHANGED
@@ -14,8 +14,8 @@
14
  <div class="sub_header">
15
  <div>
16
  <a href="{{ route('dashboard') }}">Dashboard</a>
17
- <a>My Skills</a>
18
- <a href="{{ route('dashboard.explore') }}">Explore</a>
19
  </div>
20
 
21
  @if (!Auth::guard('customuser')->check())
 
14
  <div class="sub_header">
15
  <div>
16
  <a href="{{ route('dashboard') }}">Dashboard</a>
17
+ <a href="{{ route('dashboard.myskills') }}">My Skills</a>
18
+ {{-- <a href="{{ route('dashboard.explore') }}">Explore</a> --}}
19
  </div>
20
 
21
  @if (!Auth::guard('customuser')->check())
routes/web.php CHANGED
@@ -25,6 +25,9 @@
25
  Route::prefix('/dashboard')->middleware('is_customuser')->controller(DashboardController::class)->group(function(){
26
 
27
  Route::get("/",'home')->name("dashboard");
28
- Route::get("/explore",'explore')->name("dashboard.explore");
 
 
 
29
 
30
  });
 
25
  Route::prefix('/dashboard')->middleware('is_customuser')->controller(DashboardController::class)->group(function(){
26
 
27
  Route::get("/",'home')->name("dashboard");
28
+ // Route::get("/explore",'explore')->name("dashboard.explore");
29
+ Route::get("/myskills",'myskills')->name("dashboard.myskills");
30
+ Route::post("/createskill",'createSkill')->name("dashboard.createskill");
31
+ Route::get("/skill/{id}",'skill')->name("dashboard.skill");
32
 
33
  });