diff --git a/app/FlashMessage.php b/app/FlashMessage.php new file mode 100644 index 0000000..35eaf99 --- /dev/null +++ b/app/FlashMessage.php @@ -0,0 +1,11 @@ +send(new Welcome($user)); - session()->flash('primary', 'Thanks for registering. Please, do not forget to validate your e-mail address.'); + session()->flash(FlashMessage::PRIMARY, 'Thanks for registering. Please, do not forget to validate your e-mail address.'); return $user; } diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 979c8f0..4867ee0 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -5,13 +5,17 @@ namespace App\Http\Controllers; use \App\Item; use \App\User; use Illuminate\Http\Request; +use App\FlashMessage as flash; class ItemController extends Controller { public function show($id) { $item = Item::find($id); - if (!$item || $item->product->user_id != \Auth::id()) return back(); + if (!$item || $item->product->user_id != \Auth::id()) { + session()->flash(flash::DANGER, "The item doesn't exist."); + return back(); + } $users = $item->users()->get(); $otherItems = Item::where([['product_id', $item->product_id], ['id', '!=', $id]])->get(); @@ -28,7 +32,7 @@ class ItemController extends Controller * Stores the included item into database * As the items are included on the Product view, * it must return to there after inclusion - * + * * @return (view) The product view */ public function store(Request $request) @@ -43,7 +47,7 @@ class ItemController extends Controller $authUser = User::loggedIn(); $authUser->items()->create(['name' => request('item'), 'product_id' => request('product_id')]); - return redirect('product/'.request('product_id')); + return redirect('product/' . request('product_id')); } public function patch(Request $request) @@ -52,7 +56,7 @@ class ItemController extends Controller $item = User::loggedIn()->items()->find(request('item')); $item->name = request('name'); $item->save(); - return redirect('item/'.request('item')); + return redirect('item/' . request('item')); } public function delete(Request $request) @@ -65,4 +69,4 @@ class ItemController extends Controller Item::deleteAndDetach($item); return redirect('product/' . $product); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 81da593..849fa7b 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -6,6 +6,7 @@ use \App\Item; use \App\User; use \App\Product; use Illuminate\Http\Request; +use App\FlashMessage as flash; class ProductController extends Controller { @@ -70,7 +71,7 @@ class ProductController extends Controller $product = Product::fromAuthUser()->find($id); if (!$product) { - session()->flash('danger', "The product doesn't exist or doesn't belongs to you."); + session()->flash(flash::DANGER, "The product doesn't exist or doesn't belongs to you."); return redirect('/product'); } return view('product.show', compact('product'));