Skip to content

Commit

Permalink
refactored file controller
Browse files Browse the repository at this point in the history
  • Loading branch information
skarampatakis committed Apr 11, 2018
1 parent 0e66cf7 commit d8f6a84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
21 changes: 4 additions & 17 deletions app/Http/Controllers/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Illuminate\Http\Request;

use App\File;
use App\User;
use Auth;

class FileController extends Controller
{
Expand All @@ -21,21 +19,10 @@ public function __construct()
* @return Response
*/
public function mygraphs()
{
$user = Auth::user();
$files = $this->ownGraphs($user)->merge($this->publicGraphs($user));
return view('files.index',["user"=>$user, "files"=>$files]);
}

public function ownGraphs(User $user){
$files = File::where("user_id", $user->id)->withCount("projects")->with("projects")->get();
return $files;
}

public function publicGraphs(User $user){
$files = File::where("public", true)->where("user_id", "!=", $user->id)->withCount("projects")->with("projects")->get();
return $files;
}
{
$user = auth()->user();
return view('files.index',["user"=>$user, "files"=>$user->userGraphs()]);
}

public function store()
{
Expand Down
16 changes: 13 additions & 3 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class User extends Authenticatable
*/
protected $hidden = [
'password', 'remember_token',
];


];

public function links(){
return $this->hasMany("App\Link");
Expand All @@ -50,4 +48,16 @@ public function social(){
return $this->hasMany("App\SocialAccount");
}

public function userGraphs(){
return $this->ownGraphs()->merge($this->publicGraphs());
}

public function ownGraphs(){
return File::where("user_id", $this->id)->withCount("projects")->with("projects")->get();
}

public function publicGraphs(){
return File::where("public", true)->where("user_id", "!=", $this->id)->withCount("projects")->with("projects")->get();
}

}

0 comments on commit d8f6a84

Please sign in to comment.