From 4f32dcb139dece91b6016d9bcd21e5fa2f4a6378 Mon Sep 17 00:00:00 2001 From: Griehle Date: Tue, 23 Jan 2018 10:28:55 -0700 Subject: [PATCH] message --- app/Http/Controllers/UserController.php | 47 ++++++++++++- app/Http/Controllers/postController.php | 29 +++++++- app/Post.php | 5 ++ public/css/styles.css | 2 +- resources/views/dashboard.blade.php | 80 +++++++++++------------ resources/views/includes/header.blade.php | 4 +- resources/views/layouts/master.blade.php | 11 +++- routes/web.php | 33 +++++++++- 8 files changed, 160 insertions(+), 51 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 85c32cf..d5b9030 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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){ @@ -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'); + + } + + } \ No newline at end of file diff --git a/app/Http/Controllers/postController.php b/app/Http/Controllers/postController.php index e3c26b0..69d5ed4 100644 --- a/app/Http/Controllers/postController.php +++ b/app/Http/Controllers/postController.php @@ -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]); } @@ -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); } } \ No newline at end of file diff --git a/app/Post.php b/app/Post.php index 842d812..12e0801 100644 --- a/app/Post.php +++ b/app/Post.php @@ -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'); } diff --git a/public/css/styles.css b/public/css/styles.css index 1ec3b3c..d733b7e 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -15,4 +15,4 @@ .dheader{ padding: 3% 0; -} \ No newline at end of file +} diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 7733747..409a8ff 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -6,9 +6,9 @@ {{--Left side of screen dashboard view--}}

DashBoard

-
+ {{--
--}} -
+

What do you have to say?

@@ -23,12 +23,12 @@ {{--right side f screen on dashboard view--}} -
+

Whats going on

- +
@foreach($posts as $post) -
+

{{$post->body}}

@@ -36,47 +36,45 @@ Posted by {{ $post->user->display_name }} on {{ $post->created_at->format('m/d/Y')}}
- Like - DisLike - Edit - Delete - + Like | + DisLike | + @if(Auth::user() == $post->user) + | + Edit | + Delete + @endif
@endforeach -
-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -

-
- Posted by Author -
-
- Like - DisLike - Edit - Delete - -
-
-
-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -

-
- Posted by Author -
-
- Like - DisLike - Edit - Delete - -
-
-
{{--
--}}
+ + + @endsection \ No newline at end of file diff --git a/resources/views/includes/header.blade.php b/resources/views/includes/header.blade.php index 390efce..723097f 100644 --- a/resources/views/includes/header.blade.php +++ b/resources/views/includes/header.blade.php @@ -15,8 +15,8 @@ diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php index 1220015..b45fcbc 100644 --- a/resources/views/layouts/master.blade.php +++ b/resources/views/layouts/master.blade.php @@ -3,16 +3,23 @@ @yield('title') - + + @include('includes.header') -
+
@yield('content')
+ + + + + + diff --git a/routes/web.php b/routes/web.php index d2120aa..97a7c64 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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();