Skip to content

Commit

Permalink
Merge branch 'feature/database' into pre-deploy2
Browse files Browse the repository at this point in the history
  • Loading branch information
pilpod committed Jan 24, 2021
2 parents 10a28cd + 15f2bc3 commit 0c72d2c
Show file tree
Hide file tree
Showing 29 changed files with 725 additions and 42 deletions.
46 changes: 46 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class AdminController extends Controller
{
public function __construct()
{
$this->middleware('admin');
}

public function index()
{
$users = User::all();

return view('admin-dashboard', ['users' => $users]);
}

public function edit($id)
{
$user = User::find($id);
return view('edit-user', ['user' => $user]);
}

public function show($id)
{
$user = User::find($id);
return view('show-user', ['user' => $user]);
}

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

$user->name = $request->name;
$user->isAdmin = $request->isAdmin;

$user->save();

return view('show-user', ['user' => $user]);
}

}
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

Expand All @@ -26,6 +27,7 @@ class LoginController extends Controller
*
* @var string
*/

protected $redirectTo = RouteServiceProvider::HOME;

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function validator(array $data)
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'isAdmin' => ['required', 'string', 'max:255'],
]);
}

Expand All @@ -68,6 +69,7 @@ protected function create(array $data)
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'isAdmin' => $data['isAdmin'],
]);
}
}
36 changes: 35 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use App\Models\WorkExperience;

class HomeController extends Controller
{
Expand All @@ -23,6 +25,38 @@ public function __construct()
*/
public function index()
{
return view('home');
$user = User::find(auth()->id());

return view('home', ['user' => $user]);
}

public function show(User $user)
{
$works = $user->WorkExperiences()->get();

return view('work-experiences', ['works' => $works]);

}

public function create()
{
return view('create-work');
}

public function store(Request $request)
{
WorkExperience::create([
'position' => $request->position,
'org_name' => $request->org_name,
'org_activity' => $request->org_activity,
'description' => $request->description,
'month_start' => $request->month_start,
'year_start' => $request->year_start,
'month_end' => $request->month_end,
'year_end' => $request->year_end,
'user_id' => auth()->id(),
]);

return redirect()->route('home');
}
}
15 changes: 15 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
public function index()
{

}

}
85 changes: 85 additions & 0 deletions app/Http/Controllers/WorkExperienceController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Controllers;

use App\Models\WorkExperience;
use Illuminate\Http\Request;

class WorkExperienceController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \App\Models\WorkExperience $workExperience
* @return \Illuminate\Http\Response
*/
public function show(WorkExperience $workExperience)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\WorkExperience $workExperience
* @return \Illuminate\Http\Response
*/
public function edit(WorkExperience $workExperience)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\WorkExperience $workExperience
* @return \Illuminate\Http\Response
*/
public function update(Request $request, WorkExperience $workExperience)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\WorkExperience $workExperience
* @return \Illuminate\Http\Response
*/
public function destroy(WorkExperience $workExperience)
{
//
}
}
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ class Kernel extends HttpKernel
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'admin' => \App\Http\Middleware\AdminMiddleware::class,
];
}
26 changes: 26 additions & 0 deletions app/Http/Middleware/AdminMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AdminMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if(Auth::check() && Auth::user()->isAdmin==true) {
return $next($request);
}

return redirect('login');
}
}
6 changes: 6 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class User extends Authenticatable
'name',
'email',
'password',
'isAdmin',
];

/**
Expand All @@ -40,4 +41,9 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];

public function WorkExperiences()
{
return $this->hasMany(WorkExperience::class);
}
}
28 changes: 28 additions & 0 deletions app/Models/WorkExperience.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Models;

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

class WorkExperience extends Model
{
use HasFactory;

protected $fillable = [
'position',
'org_name',
'org_activity',
'description',
'month_start',
'year_start',
'month_end',
'year_end',
'user_id',
];

public function user()
{
return $this->belongsTo(User::class);
}
}
1 change: 1 addition & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function definition()
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'isAdmin' => 'simple_user',
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
Expand Down
36 changes: 36 additions & 0 deletions database/factories/WorkExperienceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Database\Factories;

use App\Models\WorkExperience;
use Illuminate\Database\Eloquent\Factories\Factory;

class WorkExperienceFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = WorkExperience::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'position' => $this->faker->text(25),
'org_name' => $this->faker->text(50),
'org_activity' => $this->faker->text(50),
'description' => $this->faker->paragraph(5),
'month_start' => $this->faker->monthName(),
'year_start' => $this->faker->year(),
'month_end' => $this->faker->monthName(),
'year_end' => $this->faker->year(),
'user_id' => $this->faker->numberBetween(1,10),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up()
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('isAdmin')->default('simple_user');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
Expand Down
Loading

0 comments on commit 0c72d2c

Please sign in to comment.