Skip to content

Commit

Permalink
Merge pull request #9 from andela-sachungo/develop
Browse files Browse the repository at this point in the history
Added alerts
  • Loading branch information
sachungo committed Jan 12, 2016
2 parents ff28949 + 3767a7c commit 6c78635
Show file tree
Hide file tree
Showing 27 changed files with 3,849 additions and 263 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/SocialAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function handleProviderCallback($provider)
$authUser = $this->findOrCreateUser($user);
Auth::login($authUser, true);

flash('Welcome', 'Thank you for logging in and/or signing up!');

return redirect()->route('dashboard');
}

Expand Down
40 changes: 9 additions & 31 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,7 @@ class CategoryController extends Controller
*/
public function __construct()
{
$this->middleware('auth', [
'except' => [
'getVideosByCategory',
],
]);
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
/*public function index()
{
$categories = Categories::all();
return view('categories.index')->with('categories', $categories);
}*/

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('categories.create');
$this->middleware('auth');
}

/**
Expand All @@ -55,7 +29,7 @@ public function store(CategoriesRequest $request)
'title' => $request->title,
]);

// FLASH MESSAGE
flash()->success('Category Added', 'You have created a new category!');

return redirect()->back();
}
Expand Down Expand Up @@ -87,7 +61,8 @@ public function update(CategoriesRequest $request, $id)
'title' => $request->title,
]);

// FLASH MESSAGE
flash()->success('Update successful!', 'The category has been updated.');

return redirect()->route('own.categories');
}

Expand All @@ -103,11 +78,14 @@ public function destroy($id)
if ($category) {
Categories::destroy($id);

flash()->success('Deleted', 'The category has been deleted!');

return redirect()->back();
}

// REDIRECT WITH MESSAGE CATEGORY NOT FOUND
return redirect()->route('dashboard');
flash()->error('Not Found', 'The category do not exist!');

return redirect()->route('own.categories');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class HomeController extends Controller
public function login()
{
if (auth()->user()) {
return view('dashboard.index');
flash('Logged In', 'You are already logged in');

return redirect()->route('dashboard');
}

return view('auth.login');
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function update(ProfileRequest $request, $id)
'email' => $request->email,
]);

// FLASH MESSAGE
flash()->success('Profile Updated', 'You have updated your profile!');

return redirect()->route('dashboard');
}

Expand Down
13 changes: 8 additions & 5 deletions app/Http/Controllers/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function store(VideoRequest $request)
'description' => $request->description,
]);

// FLASH MESSAGE
flash()->success('Success!', 'You have uploaded a video');

return redirect()->route('dashboard');
return redirect()->route('own.videos');
}

/**
Expand Down Expand Up @@ -120,7 +120,8 @@ public function update(VideoRequest $request, $id)
'description' => $request->description,
]);

// FLASH MESSAGE
flash()->success('Video Updated', 'You have updated a video!');

return redirect()->route('own.videos');
}

Expand All @@ -135,11 +136,13 @@ public function destroy($id)
$video = Videos::find($id);
if ($video) {
Videos::destroy($id);
flash()->success('Deleted', 'The video has been deleted!');

return redirect()->route('dashboard');
return redirect()->route('own.videos');
}

// REDIRECT WITH MESSAGE VIDEO NOT FOUND
flash()->error('Not Found', 'The video do not exist!');

return redirect()->route('dashboard');
}

Expand Down
60 changes: 60 additions & 0 deletions app/Http/Flash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Soma\Http;

class Flash
{
/**
* Create a flash message.
*
* @param string $title
* @param string $message
* @param string $key
* @return void
*/
public function createFlash($title, $message, $type, $key = 'flash_message')
{
// Flash is HTTP specific hence no need to inject the Session::store()
session()->flash($key, [
'title' => $title,
'message' => $message,
'type' => $type,
]);
}

/**
* Create an info flash message.
*
* @param string $title
* @param string $message
* @return void
*/
public function info($title, $message)
{
return $this->createFlash($title, $message, 'info');
}

/**
* Create a success flash message.
*
* @param string $title
* @param string $message
* @return void
*/
public function success($title, $message)
{
return $this->createFlash($title, $message, 'success');
}

/**
* Create an error flash message.
*
* @param string $title
* @param string $message
* @return void
*/
public function error($title, $message)
{
return $this->createFlash($title, $message, 'error');
}
}
2 changes: 1 addition & 1 deletion app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
Route::resource(
'category',
'CategoryController',
['except' => ['show', 'index']]
['except' => ['show', 'index', 'create']]
);

// Profile route
Expand Down
20 changes: 20 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
<?php
/**
* A global helper function for creating flash messages using sweet alert.
*
* The app helper function grabs the Flash instance from the container.
* If the flash() function is called with no arguments, return the other
* methods in the Flash class, e.g., success(), else return the info
* method.
*
* @return void
*/
function flash($title = null, $message = null)
{
$flash = app('Soma\Http\Flash');

if (func_num_args() == 0) {
return $flash;
}

return $flash->info($title, $message);
}
Loading

0 comments on commit 6c78635

Please sign in to comment.