Skip to content

Commit

Permalink
message
Browse files Browse the repository at this point in the history
  • Loading branch information
Griehle committed Jan 23, 2018
1 parent 2cb4e7b commit 4f32dcb
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 51 deletions.
47 changes: 46 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
namespace App\Http\Controllers;

use App\User;
use App\Role;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;

class UserController extends Controller{
public function postSignUp(Request $request){
Expand Down Expand Up @@ -44,4 +46,47 @@ public function postSignin(Request $request){
return redirect()->back();
}

public function getAccount(){
return view('account', ['user'=>Auth::user()]);
//return view('welcome');
}

public function saveAccount(Request $request){
$this->validate($request, [
'display_name'=>'required|max:40|unique:users'
]);

$user = Auth::user();
$user->name = $request['name'];
$user->display_name = $request['display_name'];
$user->email = $request['email'];
$user->update();
$file = $request->file('image');
$filename = $request->first_name . '-' . $user->id . '.jpg';
if($file)
{
$file->storeAs('local', $filename);
};
// $file= $request['image'];
// $filename = $request['name'] . '-' . $user->id . '.jpg';
// if ($file){
//
// Storage::disk('local')->put($filename, File::get($file));
// }
return redirect()->route('account');

}

public function getUserImage ($filename){
$file = Storage::disk('local')->get($filename);
return new response($file, 200);
}

public function getLogout(){
Auth::logout();
return redirect()->route('home');

}


}
29 changes: 26 additions & 3 deletions app/Http/Controllers/postController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
namespace App\Http\Controllers;

use App\Post;
//use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Auth;
use http\Env\Response;
use Illuminate\Http\Request;


//use Illuminate\Support\Facades\Session;


class postController extends Controller {


public function getDashboard(){
$posts = Post::all();
$posts = Post::orderBy('created_at', 'desc')->get();
return view('dashboard', ['posts'=>$posts]);
}

Expand All @@ -29,8 +34,26 @@ public function postCreatePost( Request $request ) {
}

public function getPostDelete($post_id){

$post = Post::where('id', $post_id)->first();
if (Auth::user() != $post->user){
return redirect()->back();
}
$post->delete();
return redirect()->route('dashbaord');
return redirect()->route('dashboard')->with(['message'=>'Successfully deleted']);
}

public function postEditPost(Request $request){
$this->validate($request,[
'body'=>'required'
]);
$post = Post::find($request['postId']);
if (Auth::user() != $post->user){
return redirect()->back();
}

$post->body = $request['body'];
$post->update();
return response()->json(['new_body' => $post->body], 200);
}
}
5 changes: 5 additions & 0 deletions app/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


class Post extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
public function user(){
return $this->belongsTo('App\User');
}
Expand Down
2 changes: 1 addition & 1 deletion public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

.dheader{
padding: 3% 0;
}
}
80 changes: 39 additions & 41 deletions resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
{{--Left side of screen dashboard view--}}
<h1 class="text-center">DashBoard</h1>
<section class="row">
<div class="col-md-1"></div>
{{--<div class="col-md-1"></div>--}}

<div class = "col-md-5 text-center">
<div class = "col-md-6 text-center">
<header class="dheader">
<h3>What do you have to say?</h3>
</header>
Expand All @@ -23,60 +23,58 @@

{{--right side f screen on dashboard view--}}

<div class = "col-md-5 text-center">
<div class = "col-md-6 text-center">
<header class="dheader">
<h3>Whats going on</h3>

</header>
@foreach($posts as $post)
<article class="posts">
<article class="posts" data-postId="{{$post->id}}">
<p>
{{$post->body}}
</p>
<div class="info">
Posted by {{ $post->user->display_name }} on {{ $post->created_at->format('m/d/Y')}}
</div>
<div class="interaction">
<a href="#">Like</a>
<a href="#">DisLike</a>
<a href="#">Edit</a>
<a href="#">Delete</a>

<a href="#">Like</a> |
<a href="#">DisLike</a> |
@if(Auth::user() == $post->user)
|
<a href="#" class="edit" data-postId="{{$post->id}}">Edit</a> |
<a href="{{route('post.delete', ['post_id' => $post->id])}}">Delete</a>
@endif
</div>
</article>
@endforeach

<article class="posts">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<div class="info">
Posted by Author
</div>
<div class="interaction">
<a href="#">Like</a>
<a href="#">DisLike</a>
<a href="#">Edit</a>
<a href="#">Delete</a>

</div>
</article>
<article class="posts">
<p class="new-post">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<div class="info">
Posted by Author
</div>
<div class="interaction">
<a href="#">Like</a>
<a href="#">DisLike</a>
<a href="#">Edit</a>
<a href="#">Delete</a>

</div>
</article>
</header>
</div>
{{--<div class="col-md-1"></div>--}}
</section>

<div class="modal fade" tabindex="-1" role="dialog" id="edit-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Edit Post</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="post-body">Edit the Post</label>
<textarea class="form-control" name="post-body" id="post-body" rows="5"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="modal-save">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
var token = '{{Session::token()}}';
var url = '{{route('edit')}}';
</script>
@endsection
4 changes: 2 additions & 2 deletions resources/views/includes/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Account</a></li>
<li><a href="#">Logout</a></li>
<li><a href='{{ route('account') }}'>Account</a></li>
<li><a href="{{ route('logout') }}">Logout</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
Expand Down
11 changes: 9 additions & 2 deletions resources/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@

<head>
<title>@yield('title')</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="{{URL::to('css/styles.css')}}" >


</head>

<body>
@include('includes.header')
<div class="'container">
<div class="container">
@yield('content')
</div>


<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="{{ URL::to('js/myApp.js') }}"></script>

</body>
</html>
33 changes: 32 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,38 @@

Route::get('/createpost', [
'uses' => 'postController@postCreatePost',
'as' => 'post.create'
'as' => 'post.create',
'middeware' => 'auth'
]);

Route::get('/delete-post/{post_id}', [
'uses' => 'postController@getPostDelete',
'as' => 'post.delete',
'middeware' => 'auth'
]);

Route::get('/logout',[
'uses' =>'UserController@getLogout',
'as'=>'get.logout'
]);

Route::get('/account', [
'uses'=>'UserController@getAccount',
'as'=>'account'
]);

Route::post('/updateAccount', [
'uses' => 'UserController@saveAccount',
'as' => 'account.save'
]);
Route::get('/userImage/(filename)', [
'uses'=>'UserController@getUserImage',
'as'=> 'account.image'
]);

Route::post('/edit',[
'uses'=> "PostController@postEditPost",
'as'=>'edit'
]);

Auth::routes();
Expand Down

0 comments on commit 4f32dcb

Please sign in to comment.