Skip to content

Commit d85cc6f

Browse files
committed
User_Project linking, and the first use of it by showing members of a project
1 parent 1416e67 commit d85cc6f

File tree

8 files changed

+144
-1
lines changed

8 files changed

+144
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace SoftwareHerd\Http\Controllers;
3+
4+
use SoftwareHerd\user_projects;
5+
use Illuminate\Http\Request;
6+
7+
class User_ProjectsController extends Controller
8+
{
9+
public function project_members($id)
10+
{
11+
$user_projects = user_projects::get()->where('project_id', $id);
12+
$single_project = user_projects::get()->where('project_id', $id)->first();
13+
return view('project_members', array('user_projects' => $user_projects, 'single_project' => $single_project));
14+
}
15+
16+
}

app/User_Projects.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace SoftwareHerd;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class User_Projects extends Model
8+
{
9+
//
10+
protected $table = 'user_projects';
11+
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateUserproject extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('user_projects', function (Blueprint $table) {
17+
$table->integer('user_id');
18+
$table->integer('project_id');
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::dropIfExists('user_projects');
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddUserNameToUserProjects extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('user_projects', function (Blueprint $table) {
17+
//
18+
$table->string('user_name');
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::table('user_projects', function (Blueprint $table) {
30+
//
31+
$table->dropColumn('user_name');
32+
});
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddProjectNameTouserProjects extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('user_projects', function (Blueprint $table) {
17+
//
18+
$table->string('project_name');
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::table('user_projects', function (Blueprint $table) {
30+
//
31+
$table->dropColumn('project_name');
32+
});
33+
}
34+
}

resources/views/project.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
@section('content')
44
<h1>{{ $project->title }}</h1>
55
<h3>{{ $project->description }}</h3>
6+
<a href="/members/{{ $project->id }}">Members</a>
67
@endsection
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@extends('layouts.master')
2+
3+
@section('content')
4+
<h1>Members of {{ $single_project->project_name }}:</h1>
5+
<ul>
6+
@foreach ($user_projects as $member)
7+
<!-- Project Title -->
8+
<a href="/user/{{$member->user_id}}">{{ $member->user_name }}</a><br>
9+
@endforeach
10+
</ul>
11+
12+
13+
@endsection

routes/web.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
Route::get('project/{id}', 'ProjectController@project'); //Route for individual project
2020
Route::get('project_library', 'ProjectController@projects'); //Route for project library
2121

22-
Route::get('user/{id}', 'UserController@user'); //Route for individual project
2322

2423

24+
Route::get('user/{id}', 'UserController@user'); //Route for individual project
25+
Route::get('members/{id}', 'User_ProjectsController@project_members'); //Route for project members
26+
2527
Auth::routes();
2628

2729
Route::get('/new_project', function () { //view for creating new project

0 commit comments

Comments
 (0)